check timedatectl errno and return stdout on failure

Fixes #28528.
This commit is contained in:
Justin Findlay 2015-11-03 17:28:19 -07:00
parent 7e22e7cf24
commit 5c0e5dacc0

View file

@ -27,6 +27,19 @@ def __virtual__():
return True
def _timedatectl():
'''
get the output of timedatectl
'''
ret = __salt__['cmd.run_all'](['timedatectl'], python_shell=False)
if ret['retcode'] != 0:
msg = 'timedatectl failed: {0}'.format(ret['stderr'])
raise CommandExecutionError(msg)
return ret
def _get_zone_solaris():
tzfile = '/etc/TIMEZONE'
with salt.utils.fopen(tzfile, 'r') as fp_:
@ -100,20 +113,18 @@ def get_zone():
'''
cmd = ''
if salt.utils.which('timedatectl'):
ret = __salt__['cmd.run_all'](['timedatectl'], python_shell=False)
if ret['retcode'] > 0:
msg = 'timedatectl failed: {0}'.format(ret['stderr'])
raise CommandExecutionError(msg)
ret = _timedatectl()
for line in (x.strip() for x in ret['stdout'].splitlines()):
try:
return re.match(r'Time ?zone:\s+(\S+)', line).group(1)
except AttributeError:
pass
raise CommandExecutionError(
'Failed to parse timedatectl output, this is likely a bug'
)
msg = ('Failed to parse timedatectl output: {0}\n'
'Please file an issue with SaltStack').format(ret['stdout'])
raise CommandExecutionError(msg)
else:
if __grains__['os'].lower() == 'centos':
return _get_zone_etc_localtime()
@ -264,8 +275,8 @@ def get_hwclock():
'''
cmd = ''
if salt.utils.which('timedatectl'):
out = __salt__['cmd.run'](['timedatectl'], python_shell=False)
for line in (x.strip() for x in out.splitlines()):
ret = _timedatectl()
for line in (x.strip() for x in ret['stdout'].splitlines()):
if 'rtc in local tz' in line.lower():
try:
if line.split(':')[-1].strip().lower() == 'yes':
@ -274,9 +285,11 @@ def get_hwclock():
return 'UTC'
except IndexError:
pass
raise CommandExecutionError(
'Failed to parse timedatectl output, this is likely a bug'
)
msg = ('Failed to parse timedatectl output: {0}\n'
'Please file an issue with SaltStack').format(ret['stdout'])
raise CommandExecutionError(msg)
else:
os_family = __grains__['os_family']
for family in ('RedHat', 'Suse'):