Add test mode conditionals to the alternatives state

This commit is contained in:
Colton Myers 2014-06-13 16:18:47 -06:00
parent b26679c3aa
commit 948de0a2f6

View File

@ -65,6 +65,12 @@ def install(name, link, path, priority):
isinstalled = __salt__['alternatives.check_installed'](name, path)
if not isinstalled:
if __opts__['test']:
ret['comment'] = (
'Alternative will be set for {0} to {1} with priority {2}'
).format(name, path, priority)
ret['result'] = None
return ret
__salt__['alternatives.install'](name, link, path, priority)
ret['comment'] = (
'Setting alternative for {0} to {1} with priority {2}'
@ -100,6 +106,11 @@ def remove(name, path):
isinstalled = __salt__['alternatives.check_installed'](name, path)
if isinstalled:
if __opts__['test']:
ret['comment'] = ('Alternative for {0} will be removed'
.format(name))
ret['result'] = None
return ret
__salt__['alternatives.remove'](name, path)
current = __salt__['alternatives.show_current'](name)
if current:
@ -154,6 +165,10 @@ def auto(name):
ret['comment'] = '{0} already in auto mode'.format(name)
return ret
if __opts__['test']:
ret['comment'] = '{0} will be put in auto mode'.format(name)
ret['result'] = None
return ret
ret['changes']['result'] = __salt__['alternatives.auto'](name)
return ret
@ -192,6 +207,12 @@ def set_(name, path):
break
if isinstalled:
if __opts__['test']:
ret['comment'] = (
'Alternative for {0} will be set to path {1}'
).format(name, current)
ret['result'] = None
return ret
__salt__['alternatives.set'](name, path)
current = __salt__['alternatives.show_current'](name)
if current == path: