Update set_hwclock to only accept UTC on NILinuxRT

NILinuxRT systems do not support non-UTC timezones for hwclock, so
enforce that in set_hwclock.
This commit is contained in:
Jeffrey Pautler 2017-05-17 16:44:44 -05:00
parent 3b9924f165
commit 6254b8f326
2 changed files with 15 additions and 12 deletions

View File

@ -480,12 +480,14 @@ def set_hwclock(clock):
salt '*' timezone.set_hwclock UTC
'''
if 'AIX' in __grains__['os_family']:
if clock.lower() != 'utc':
raise SaltInvocationError(
'UTC is the only permitted value'
)
return True
os_family = __grains__['os_family']
for family in ('AIX', 'NILinuxRT'):
if family in os_family:
if clock.lower() != 'utc':
raise SaltInvocationError(
'UTC is the only permitted value'
)
return True
timezone = get_zone()

View File

@ -316,15 +316,16 @@ class TimezoneModuleTestCase(TestCase, LoaderModuleMockMixin):
@patch('os.path.exists', MagicMock(return_value=True))
@patch('os.unlink', MagicMock())
@patch('os.symlink', MagicMock())
def test_set_hwclock_aix(self):
def test_set_hwclock_aix_nilinuxrt(self):
'''
Test set hwclock on AIX
Test set hwclock on AIX and NILinuxRT
:return:
'''
with patch.dict(timezone.__grains__, {'os_family': ['AIX']}):
with self.assertRaises(SaltInvocationError):
assert timezone.set_hwclock('forty two')
assert timezone.set_hwclock('UTC')
for osfamily in ['AIX', 'NILinuxRT']:
with patch.dict(timezone.__grains__, {'os_family': osfamily}):
with self.assertRaises(SaltInvocationError):
assert timezone.set_hwclock('forty two')
assert timezone.set_hwclock('UTC')
@patch('salt.utils.which', MagicMock(return_value=False))
@patch('os.path.exists', MagicMock(return_value=True))