← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~slystopad/cloud-init:merge/chpasswd-data-as-list into cloud-init:master

 

Some minor cleanups suggested.  Largely looks good.

In order for me to accept this, you will have to sign the contributors agreement.  See HACKING.rst for more information, and please feel free to ping me in irc or email if I can help out at all.

I'll put this into 'Work in progress' state.  Just move it to Resubmit when you've done that.

Thanks.
Scott

Diff comments:

> diff --git a/cloudinit/config/cc_set_passwords.py b/cloudinit/config/cc_set_passwords.py
> index cf1f59e..60fe7d1 100755
> --- a/cloudinit/config/cc_set_passwords.py
> +++ b/cloudinit/config/cc_set_passwords.py
> @@ -79,7 +90,14 @@ def handle(_name, cfg, cloud, log, args):
>  
>      if 'chpasswd' in cfg:
>          chfg = cfg['chpasswd']
> -        plist = util.get_cfg_option_str(chfg, 'list', plist)
> +        if type(chfg['list']) == type([]):

I think that is equivlent to 
   if isinstance(cfg['list'], list):

and we use the isinstance elsewhere.

> +            cfg_type='list'
> +        else:
> +            cfg_type='string'
> +        if cfg_type == 'list':
> +            plist = util.get_cfg_option_list(chfg, 'list', plist)
> +        else:
> +            plist = util.get_cfg_option_str(chfg, 'list', plist)
>          expire = util.get_cfg_option_bool(chfg, 'expire', expire)
>  
>      if not plist and password:
> @@ -95,13 +113,26 @@ def handle(_name, cfg, cloud, log, args):
>          plist_in = []
>          randlist = []
>          users = []
> -        for line in plist.splitlines():
> +        def _prepare_credentials(line, **kwargs):
>              u, p = line.split(':', 1)
>              if p == "R" or p == "RANDOM":
>                  p = rand_user_password()
> -                randlist.append("%s:%s" % (u, p))
> -            plist_in.append("%s:%s" % (u, p))
> -            users.append(u)
> +                kwargs['randlist'].append("%s:%s" % (u, p))
> +            kwargs['plist_in'].append("%s:%s" % (u, p))
> +            kwargs['users'].append(u)
> +
> +        if cfg_type == 'list':
> +            log.warn("Handling input for chpasswd as list.")

Lets not warn on this, as it is perfectly valid.
Just drop the warn.  Debug if you would like.

> +            for line in plist:
> +                _prepare_credentials(line, randlist=randlist,
> +                                           plist_in=plist_in,
> +                                           users=users)
> +        else:
> +            log.warn("Handling input for chpasswd as multiline string.")
> +            for line in plist.splitlines():
> +                _prepare_credentials(line, randlist=randlist,
> +                                           plist_in=plist_in,
> +                                           users=users)
>  
>          ch_in = '\n'.join(plist_in) + '\n'
>          try:


-- 
https://code.launchpad.net/~slystopad/cloud-init/+git/cloud-init/+merge/317774
Your team cloud init development team is requested to review the proposed merge of ~slystopad/cloud-init:merge/chpasswd-data-as-list into cloud-init:master.


References