rh_service module: fix logic in _chkconfig_is_enabled

Fixes #23971.
This commit is contained in:
Justin Findlay 2015-11-13 23:29:15 -07:00
parent af297bb0ae
commit 5a93b7e53c

View file

@ -153,23 +153,22 @@ def _sysv_is_enabled(name, runlevel=None):
def _chkconfig_is_enabled(name, runlevel=None):
'''
Return True if the service is enabled according to chkconfig; otherwise
return False. If `runlevel` is None, then use the current runlevel.
Return ``True`` if the service is enabled according to chkconfig; otherwise
return ``False``. If ``runlevel`` is ``None``, then use the current
runlevel.
'''
cmdline = '/sbin/chkconfig --list {0}'.format(name)
result = __salt__['cmd.run_all'](cmdline, python_shell=False)
if runlevel is None:
runlevel = _runlevel()
if result['retcode'] == 0:
cols = result['stdout'].splitlines()[0].split()
try:
if cols[0].strip(':') == name:
if runlevel is None:
runlevel = _runlevel()
if len(cols) > 3 and '{0}:on'.format(runlevel) in cols:
for row in result['stdout'].splitlines():
if '{0}:on'.format(runlevel) in row:
if row.split()[0] == name:
return True
elif len(cols) < 3 and cols[1] and cols[1] == 'on':
return True
except IndexError:
pass
elif row.split() == [name + ':', 'on']:
return True
return False