Merge lp:~smoser/cloud-init/trunk.1562918 into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 1200
Proposed branch: lp:~smoser/cloud-init/trunk.1562918
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 24 lines (+5/-2)
1 file modified
cloudinit/distros/__init__.py (+5/-2)
To merge this branch: bzr merge lp:~smoser/cloud-init/trunk.1562918
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+290542@code.launchpad.net

Commit message

fix adding of users without a group

revision 1179 regressed adding a user that did not have a 'groups'
entry present. This should handle that correctly, making 'add_user'
able to take:
  a.) groups="group1,group2"
  b.) groups=["group1", "group2"]
  c.) groups=None
  d.) no groups parameter

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/distros/__init__.py'
2--- cloudinit/distros/__init__.py 2016-03-22 07:53:33 +0000
3+++ cloudinit/distros/__init__.py 2016-03-31 00:22:03 +0000
4@@ -362,15 +362,18 @@
5
6 redact_opts = ['passwd']
7
8+ # support kwargs having groups=[list] or groups="g1,g2"
9 groups = kwargs.get('groups')
10 if groups:
11 if isinstance(groups, (list, tuple)):
12+ # kwargs.items loop below wants a comma delimeted string
13+ # that can go right through to the command.
14 kwargs['groups'] = ",".join(groups)
15 else:
16 groups = groups.split(",")
17
18- if create_groups:
19- for group in kwargs.get('groups').split(","):
20+ if create_groups and groups:
21+ for group in groups:
22 if not util.is_group(group):
23 self.create_group(group)
24 LOG.debug("created group %s for user %s", name, group)