Merge pull request #32165 from terminalmage/issue31731

Make __virtual__ for rhservice.py more robust
This commit is contained in:
Nicole Thomas 2016-03-27 12:21:16 -06:00
commit ae472617af

View file

@ -67,18 +67,22 @@ def __virtual__():
else:
return (False, 'Cannot load rh_service module on SUSE > 11')
try:
osrelease = float(__grains__.get('osrelease', 0))
except ValueError:
return (False, 'Cannot load rh_service module: '
'osrelease grain, {0}, not a float,'.format(osrelease))
osrelease_major = __grains__.get('osrelease_info', [0])[0]
if __grains__['os'] == 'Fedora':
if osrelease > 15:
return (False, 'Cannot load rh_service module on Fedora >= 15')
if osrelease_major >= 15:
return (
False,
'Fedora >= 15 uses systemd, will not load rh_service.py '
'as virtual \'service\''
)
if __grains__['os'] in ('RedHat', 'CentOS', 'ScientificLinux', 'OEL'):
if osrelease >= 7:
return (False, 'Cannot load rh_service module on RedHat >= 7')
if osrelease_major >= 7:
return (
False,
'RedHat-based distros >= version 7 use systemd, will not '
'load rh_service.py as virtual \'service\''
)
return __virtualname__
return (False, 'Cannot load rh_service module: OS not in {0}'.format(enable))