Fix win_useradd.chgroups return when cmd.run_all retcode != 0

Fixes #34841

When calling user.chgroups on a windows system, we were not checking
for the retcode of the `cmd.run_all` call when the localgroup call
failed.

This adds a check to make sure the retcode is 0. If it isn't 0, then
we should be returning False, not True.
This commit is contained in:
rallytime 2016-11-01 11:19:23 -06:00
parent 1a4833b3a1
commit c70492a1fe

View file

@ -666,7 +666,10 @@ def chgroups(name, groups, append=True):
continue
group = _cmd_quote(group).lstrip('\'').rstrip('\'')
cmd = 'net localgroup "{0}" {1} /add'.format(group, name)
__salt__['cmd.run_all'](cmd, python_shell=True)
out = __salt__['cmd.run_all'](cmd, python_shell=True)
if out['retcode'] != 0:
log.error(out['stdout'])
return False
agrps = set(list_groups(name))
return len(ugrps - agrps) == 0