Skip to content

Commit

Permalink
Merge pull request #24802 from basepi/merge-forward-2015.5
Browse files Browse the repository at this point in the history
[2015.5] Merge forward from 2014.7 to 2015.5
  • Loading branch information
basepi committed Jun 18, 2015
2 parents daa76c3 + 5b7a65d commit ae05e70
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions salt/modules/win_servermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def _srvmgr(func):
def _parse_powershell_list(lst):
'''
Parse command output when piped to format-list
Need to look at splitting with ':' so you can get the full value
Need to check for error codes and return false if it's trying to parse
'''
ret = {}
for line in lst.splitlines():
Expand All @@ -47,6 +49,7 @@ def _parse_powershell_list(lst):
# baz}
if len(splt) > 2:
ret[splt[0]] = splt[2]
ret['message'] = lst
return ret


Expand Down
14 changes: 11 additions & 3 deletions salt/states/win_servermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ def installed(name, recurse=False, force=False):

# Install the features
ret['changes'] = {'feature': __salt__['win_servermanager.install'](name, recurse)}
ret['result'] = ret['changes']['feature']['Success'] == 'True'
if not ret['result']:
ret['comment'] = 'failed to install the feature: {0}'.format(ret['changes']['feature']['ExitCode'])

if 'Success' in ret['changes']['feature']:
ret['result'] = ret['changes']['feature']['Success'] == 'True'
if not ret['result']:
ret['comment'] = 'Failed to install {0}: {1}'.format(name, ret['changes']['feature']['ExitCode'])
else:
ret['comment'] = 'Installed {0}'.format(name)
else:
ret['result'] = False
ret['comment'] = 'Failed to install {0}.\nError Message:\n{1}'.format(name, ret['changes']['feature']['message'])
ret['changes'] = {}

return ret

Expand Down
8 changes: 6 additions & 2 deletions tests/unit/modules/win_servermanager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def test_install(self):
Test if it install a feature.
'''
with patch.dict(win_servermanager.__salt__, {'cmd.run': self._m_run()}):
self.assertDictEqual(win_servermanager.install('Telnet-Client'), {})
self.assertDictEqual(win_servermanager.install('Telnet-Client'), {
'message': ''
})

# 'remove' function tests: 1

Expand All @@ -72,7 +74,9 @@ def test_remove(self):
Test if it remove an installed feature.
'''
with patch.dict(win_servermanager.__salt__, {'cmd.run': self._m_run()}):
self.assertDictEqual(win_servermanager.remove('Telnet-Client'), {})
self.assertDictEqual(win_servermanager.remove('Telnet-Client'), {
'message': ''
})


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/states/win_servermanager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_installed(self):

with patch.dict(win_servermanager.__opts__, {"test": False}):
ret.update({'changes': {'feature': {'Success': 'True'}},
'result': True})
'result': True, 'comment': 'Installed salt'})
self.assertDictEqual(win_servermanager.installed('salt'),
ret)

Expand Down

0 comments on commit ae05e70

Please sign in to comment.