Re: [Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:useradd into cloud-init:master

2019-08-12 Thread Dan Watkins
On Mon, Aug 12, 2019 at 02:31:18PM -, Ryan Harper wrote:
> The method is call add_user and the variables match the method.

If the variable matched the method, I'd expect it to be add_user_cmd.
I'd be fine with that, if that's what you would prefer?

> So now we have
> 
> def add_user()
>useradd_cmd = 
> 
> Isn't this the same confusion?

I don't think so; the name of the command we do actually use is
hardcoded in a string literal later on that line:

useradd_cmd = ['useradd', ...]

> The command to add a user could be something else.

Not without code changes, which I would expect to also change the
variable name.

> In cloudinit/distros/freebsd.py for example, the adduser_cmd , is 'pw
> useradd'.

Right, I didn't touch the variable name there.

-- 
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371203
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:useradd into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


Re: [Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:useradd into cloud-init:master

2019-08-12 Thread Ryan Harper
The method is call add_user and the variables match the method.

So now we have

def add_user()
   useradd_cmd = 

Isn't this the same confusion?

The command to add a user could be something else. In 
cloudinit/distros/freebsd.py for example, the adduser_cmd , is 'pw useradd'.

-- 
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371203
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:useradd into cloud-init:master.

___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp


[Cloud-init-dev] [Merge] ~daniel-thewatkins/cloud-init/+git/cloud-init:useradd into cloud-init:master

2019-08-12 Thread Dan Watkins
Dan Watkins has proposed merging 
~daniel-thewatkins/cloud-init/+git/cloud-init:useradd into cloud-init:master.

Commit message:
distros: fix confusing variable names

Building the subp arguments for a `useradd` call in a variable named
`adduser_cmd` is extremely confusing; let's not do that.

(This also changes the snap variable to something more apropos.)


Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~daniel-thewatkins/cloud-init/+git/cloud-init/+merge/371203
-- 
Your team cloud-init commiters is requested to review the proposed merge of 
~daniel-thewatkins/cloud-init/+git/cloud-init:useradd into cloud-init:master.
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 20c994d..00bdee3 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -396,16 +396,16 @@ class Distro(object):
 else:
 create_groups = True
 
-adduser_cmd = ['useradd', name]
-log_adduser_cmd = ['useradd', name]
+useradd_cmd = ['useradd', name]
+log_useradd_cmd = ['useradd', name]
 if util.system_is_snappy():
-adduser_cmd.append('--extrausers')
-log_adduser_cmd.append('--extrausers')
+useradd_cmd.append('--extrausers')
+log_useradd_cmd.append('--extrausers')
 
 # Since we are creating users, we want to carefully validate the
 # inputs. If something goes wrong, we can end up with a system
 # that nobody can login to.
-adduser_opts = {
+useradd_opts = {
 "gecos": '--comment',
 "homedir": '--home',
 "primary_group": '--gid',
@@ -418,7 +418,7 @@ class Distro(object):
 "selinux_user": '--selinux-user',
 }
 
-adduser_flags = {
+useradd_flags = {
 "no_user_group": '--no-user-group',
 "system": '--system',
 "no_log_init": '--no-log-init',
@@ -453,32 +453,32 @@ class Distro(object):
 # Check the values and create the command
 for key, val in sorted(kwargs.items()):
 
-if key in adduser_opts and val and isinstance(val, str):
-adduser_cmd.extend([adduser_opts[key], val])
+if key in useradd_opts and val and isinstance(val, str):
+useradd_cmd.extend([useradd_opts[key], val])
 
 # Redact certain fields from the logs
 if key in redact_opts:
-log_adduser_cmd.extend([adduser_opts[key], 'REDACTED'])
+log_useradd_cmd.extend([useradd_opts[key], 'REDACTED'])
 else:
-log_adduser_cmd.extend([adduser_opts[key], val])
+log_useradd_cmd.extend([useradd_opts[key], val])
 
-elif key in adduser_flags and val:
-adduser_cmd.append(adduser_flags[key])
-log_adduser_cmd.append(adduser_flags[key])
+elif key in useradd_flags and val:
+useradd_cmd.append(useradd_flags[key])
+log_useradd_cmd.append(useradd_flags[key])
 
 # Don't create the home directory if directed so or if the user is a
 # system user
 if kwargs.get('no_create_home') or kwargs.get('system'):
-adduser_cmd.append('-M')
-log_adduser_cmd.append('-M')
+useradd_cmd.append('-M')
+log_useradd_cmd.append('-M')
 else:
-adduser_cmd.append('-m')
-log_adduser_cmd.append('-m')
+useradd_cmd.append('-m')
+log_useradd_cmd.append('-m')
 
 # Run the command
 LOG.debug("Adding user %s", name)
 try:
-util.subp(adduser_cmd, logstring=log_adduser_cmd)
+util.subp(useradd_cmd, logstring=log_useradd_cmd)
 except Exception as e:
 util.logexc(LOG, "Failed to create user %s", name)
 raise e
@@ -490,15 +490,15 @@ class Distro(object):
 
 snapuser = kwargs.get('snapuser')
 known = kwargs.get('known', False)
-adduser_cmd = ["snap", "create-user", "--sudoer", "--json"]
+create_user_cmd = ["snap", "create-user", "--sudoer", "--json"]
 if known:
-adduser_cmd.append("--known")
-adduser_cmd.append(snapuser)
+create_user_cmd.append("--known")
+create_user_cmd.append(snapuser)
 
 # Run the command
 LOG.debug("Adding snap user %s", name)
 try:
-(out, err) = util.subp(adduser_cmd, logstring=adduser_cmd,
+(out, err) = util.subp(create_user_cmd, logstring=create_user_cmd,
capture=True)
 LOG.debug("snap create-user returned: %s:%s", out, err)
 jobj = util.load_json(out)
___
Mailing list: https://launchpad.net/~cloud-init-dev
Post to :