Merge pull request #2652 from s0undt3ch/issues/2631

Fix #2631
This commit is contained in:
Thomas S Hatch 2012-11-21 10:43:29 -08:00
commit c6f575ebed
2 changed files with 25 additions and 8 deletions

View File

@ -83,6 +83,16 @@ def gid_to_group(gid):
salt '*' file.gid_to_group 0
'''
try:
gid = int(gid)
except ValueError:
# This is not an integer, maybe it's already the group name?
gid = group_to_gid(gid)
if not gid:
# Don't even bother to feed it to grp
return ''
try:
return grp.getgrgid(gid).gr_name
except KeyError:

View File

@ -23,10 +23,12 @@ as either absent or present
user.absent
'''
# Import python libs
import logging
log = logging.getLogger(__name__)
def _changes(
name,
uid=None,
@ -129,7 +131,7 @@ def present(
gid
The default group id
gid_from_name
If True, the default group id will be set to the id of the group with
the same name as the user.
@ -205,25 +207,29 @@ def present(
for missing_optgroup in [x for x in optional_groups
if x not in present_optgroups]:
log.debug('Optional group "{0}" for user "{1}" is not '
'present'.format(missing_optgroup,name))
'present'.format(missing_optgroup, name))
else:
present_optgroups = None
# Log a warning for all groups specified in both "groups" and
# "optional_groups" lists.
if groups and optional_groups:
for x in set(groups).intersection(optional_groups):
log.warning('Group "{0}" specified in both groups and '
'optional_groups for user {1}'.format(x,name))
'optional_groups for user {1}'.format(x, name))
if fullname is None: fullname = ''
if roomnumber is None: roomnumber = ''
if workphone is None: workphone = ''
if homephone is None: homephone = ''
if fullname is None:
fullname = ''
if roomnumber is None:
roomnumber = ''
if workphone is None:
workphone = ''
if homephone is None:
homephone = ''
if gid_from_name:
gid = __salt__['file.group_to_gid'](name)
changes = _changes(
name,
uid,
@ -239,6 +245,7 @@ def present(
roomnumber,
workphone,
homephone)
if changes:
if __opts__['test']:
ret['result'] = None