Fix traceback in service.py when OS not identified

If the OS was not properly identified, salt/modules/service.py is used
as a fallback provider for the service module/state. However, the way it
looks up the location of the initscripts directory results in a
traceback if the OS grain isn't in the lookup dict.

This commit simplifies the lookup dict and has the module use
/etc/init.d as the location for initscripts if the 'os' grain is not in
the lookup dict, fixing this traceback.
This commit is contained in:
Erik Johnson 2013-09-24 12:38:14 -05:00
parent a3339d9b81
commit 5495a5fdca

View File

@ -11,21 +11,9 @@ __func_alias__ = {
'reload_': 'reload'
}
GRAINMAP = {
_GRAINMAP = {
'Arch': '/etc/rc.d',
'Arch ARM': '/etc/rc.d',
'Debian': '/etc/init.d',
'Fedora': '/etc/init.d',
'RedHat': '/etc/init.d',
'Ubuntu': '/etc/init.d',
'Gentoo': '/etc/init.d',
'CentOS': '/etc/init.d',
'CloudLinux': '/etc/init.d',
'Amazon': '/etc/init.d',
'SunOS': '/etc/init.d',
'SUSE Enterprise Server': '/etc/init.d',
'openSUSE': '/etc/init.d',
'OEL': '/etc/init.d',
'Arch ARM': '/etc/rc.d'
}
@ -77,8 +65,10 @@ def start(name):
salt '*' service.start <service name>
'''
cmd = os.path.join(GRAINMAP[__grains__['os']],
name + ' start')
cmd = os.path.join(
_GRAINMAP.get(__grains__.get('os'), '/etc/init.d'),
name + ' start'
)
return not __salt__['cmd.retcode'](cmd)
@ -92,8 +82,10 @@ def stop(name):
salt '*' service.stop <service name>
'''
cmd = os.path.join(GRAINMAP[__grains__['os']],
name + ' stop')
cmd = os.path.join(
_GRAINMAP.get(__grains__.get('os'), '/etc/init.d'),
name + ' stop'
)
return not __salt__['cmd.retcode'](cmd)
@ -107,8 +99,10 @@ def restart(name):
salt '*' service.restart <service name>
'''
cmd = os.path.join(GRAINMAP[__grains__['os']],
name + ' restart')
cmd = os.path.join(
_GRAINMAP.get(__grains__.get('os'), '/etc/init.d'),
name + ' restart'
)
return not __salt__['cmd.retcode'](cmd)
@ -137,8 +131,10 @@ def reload_(name):
salt '*' service.reload <service name>
'''
cmd = os.path.join(GRAINMAP[__grains__['os']],
name + ' reload')
cmd = os.path.join(
_GRAINMAP.get(__grains__.get('os'), '/etc/init.d'),
name + ' reload'
)
return not __salt__['cmd.retcode'](cmd)
@ -152,9 +148,9 @@ def get_all():
salt '*' service.get_all
'''
if not os.path.isdir(GRAINMAP[__grains__['os']]):
if not os.path.isdir(_GRAINMAP.get(__grains__.get('os'), '/etc/init.d')):
return []
return sorted(os.listdir(GRAINMAP[__grains__['os']]))
return sorted(os.listdir(_GRAINMAP.get(__grains__.get('os'), '/etc/init.d')))
def available(name):