~harlowja/cloud-init/group-dict-fix

« back to all changes in this revision

Viewing changes to cloudinit/distros/__init__.py

  • Committer: Joshua Harlow
  • Date: 2012-11-09 23:28:35 UTC
  • Revision ID: harlowja@yahoo-inc.com-20121109232835-u7s63t41qonunmca
Fix the merging of group configuration
when that group configuration is a dict => members.

Show diffs side-by-side

added added

removed removed

Lines of Context:
425
425
# is the standard form used in the rest
426
426
# of cloud-init
427
427
def _normalize_groups(grp_cfg):
428
 
    if isinstance(grp_cfg, (str, basestring, list)):
 
428
    if isinstance(grp_cfg, (str, basestring)):
 
429
        grp_cfg = grp_cfg.strip().split(",")
 
430
    if isinstance(grp_cfg, (list)):
429
431
        c_grp_cfg = {}
430
 
        for i in util.uniq_merge(grp_cfg):
431
 
            c_grp_cfg[i] = []
 
432
        for i in grp_cfg:
 
433
            if isinstance(i, (dict)):
 
434
                for k, v in i.items():
 
435
                    if k not in c_grp_cfg:
 
436
                        if isinstance(v, (list)):
 
437
                            c_grp_cfg[k] = list(v)
 
438
                        elif isinstance(v, (basestring, str)):
 
439
                            c_grp_cfg[k] = [v]
 
440
                        else:
 
441
                            raise TypeError("Bad group member type %s" %
 
442
                                            util.obj_name(v))
 
443
                    else:
 
444
                        if isinstance(v, (list)):
 
445
                            c_grp_cfg[k].extend(v)
 
446
                        elif isinstance(v, (basestring, str)):
 
447
                            c_grp_cfg[k].append(v)
 
448
                        else:
 
449
                            raise TypeError("Bad group member type %s" %
 
450
                                            util.obj_name(v))
 
451
            elif isinstance(i, (str, basestring)):
 
452
                if i not in c_grp_cfg:
 
453
                    c_grp_cfg[i] = []
 
454
            else:
 
455
                raise TypeError("Unknown group name type %s" %
 
456
                                util.obj_name(i))
432
457
        grp_cfg = c_grp_cfg
433
 
 
434
458
    groups = {}
435
459
    if isinstance(grp_cfg, (dict)):
436
460
        for (grp_name, grp_members) in grp_cfg.items():