Merge ~d-info-e/cloud-init:fix-user-group-doc into cloud-init:master

Proposed by do3meli
Status: Merged
Approved by: Chad Smith
Approved revision: 4b892c2d1fa97bb35935f351d65c872bde513ebf
Merge reported by: Chad Smith
Merged at revision: b27f713ae5b4c5b38eda63758dbaeab92be13b9d
Proposed branch: ~d-info-e/cloud-init:fix-user-group-doc
Merge into: cloud-init:master
Diff against target: 242 lines (+44/-44)
7 files modified
cloudinit/config/cc_users_groups.py (+14/-14)
doc/examples/cloud-config-user-groups.txt (+12/-12)
tests/cloud_tests/testcases/examples/including_user_groups.yaml (+1/-1)
tests/cloud_tests/testcases/modules/user_groups.yaml (+1/-1)
tests/data/merge_sources/expected7.yaml (+8/-8)
tests/data/merge_sources/source7-1.yaml (+5/-5)
tests/data/merge_sources/source7-2.yaml (+3/-3)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Chad Smith Approve
Review via email: mp+342251@code.launchpad.net

Commit message

correct documentation to match correct attribute name usage.

LP: #1420018

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

this one is harder than it should be.

_normalize_users ends up fixing the '-' to '_' in all those before
'distro.create_user' gets called. So either actually works.
Documentation and implementation in cloud-init have unfortunately been
inconsistent with '-' versus '_'.

We should absolutely strive to be consistent both in implementation
and in documentation.

So...
* I'm 98% certain that 'ssh-import-id' in the diff context and
  'ssh-authorized-keys' support either - or _. Lets just change everything to
  document '_' for consistency.
  Please fix those also.
* lets also update the in-module documentation in
  cloudinit/config/cc_users_groups.py to match (that is what ends up
  being documented at
  http://cloudinit.readthedocs.io/en/latest/topics/modules.html#users-and-groups

Revision history for this message
do3meli (d-info-e) wrote :

i haven't tested it but just looking at the code i assume you think that line 133 is the one that converts '-' into '_', right?

see https://git.launchpad.net/cloud-init/tree/cloudinit/distros/ug_util.py#n133

it definitely makes sense to be consistent in the docs as well as the actual implementation. so i will make sure that cloudinit/config/cc_users_groups.py is correct too.

on the other hand i am unsure if ssh-import-id and ssh-authorized-keys are identical. i will dig into that further later on.

c6493bb... by do3meli

adjust also inline code docs for cc_user_groups

Revision history for this message
do3meli (d-info-e) wrote :

hi scott,
i have addressed your point 2), but not yet 1) as i am still unsure if it will break something or not. looking at it a bit more closer i believe any '-' in the cc_user_group module should be replaced if it really works both ways. that also would include others like primary-group, selinux-user, ect. see cloud-config-user-groups.txt for more. what do you think about that?

Revision history for this message
Scott Moser (smoser) wrote :

I'm pretty sure it does work both ways.
so yeah, i suggest we change everything there to have _.

Revision history for this message
Chad Smith (chad.smith) wrote :

+1 on changing any hyphenat-delimited keys to underscore-delimited "_". If there are any inconsistencies there in the code honoring underscore-delmited keys we will fix the code. Consistency across all applicable user-provided fields pays dividends.

Dominic, I'll await your final pass on this and we'll land it right away. Thx again.

Revision history for this message
Chad Smith (chad.smith) :
review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

When you update docs, it's probably good to replace

primary-group: foobar with
with
primary_group: foobar
in our integration test @ tests/cloud_tests/testcases/modules/user_groups.yaml

Revision history for this message
do3meli (d-info-e) wrote :

i will grep through the whole repo when changing a key so i won't miss any place. will keep you updated on this once having time to fix them all.

Revision history for this message
do3meli (d-info-e) wrote :

just found this old bug report here: https://bugs.launchpad.net/cloud-init/+bug/1293254
matches perfectly but is even more general i guess.

4b892c2... by do3meli

change all - to _ in tests,modules,doc for user-group module

Revision history for this message
do3meli (d-info-e) wrote :

chad,

i have adjusted all other occurrence i found. the ssh-import-id was a bit tricky as we have a module called the same. you may have a closer look at this one specifically.

please run CI. thanks

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:4b892c2d1fa97bb35935f351d65c872bde513ebf
https://jenkins.ubuntu.com/server/job/cloud-init-ci/962/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/962/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=b27f713a

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/config/cc_users_groups.py b/cloudinit/config/cc_users_groups.py
2index f363000..b215e95 100644
3--- a/cloudinit/config/cc_users_groups.py
4+++ b/cloudinit/config/cc_users_groups.py
5@@ -34,16 +34,16 @@ config keys for an entry in ``users`` are as follows:
6 - ``homedir``: Optional. Home dir for user. Default is ``/home/<username>``
7 - ``inactive``: Optional. Mark user inactive. Default: false
8 - ``lock_passwd``: Optional. Disable password login. Default: true
9- - ``no-create-home``: Optional. Do not create home directory. Default:
10+ - ``no_create_home``: Optional. Do not create home directory. Default:
11 false
12- - ``no-log-init``: Optional. Do not initialize lastlog and faillog for
13+ - ``no_log_init``: Optional. Do not initialize lastlog and faillog for
14 user. Default: false
15- - ``no-user-group``: Optional. Do not create group named after user.
16+ - ``no_user_group``: Optional. Do not create group named after user.
17 Default: false
18 - ``passwd``: Hash of user password
19- - ``primary-group``: Optional. Primary group for user. Default to new group
20+ - ``primary_group``: Optional. Primary group for user. Default to new group
21 named after user.
22- - ``selinux-user``: Optional. SELinux user for user's login. Default to
23+ - ``selinux_user``: Optional. SELinux user for user's login. Default to
24 default SELinux user.
25 - ``shell``: Optional. The user's login shell. The default is to set no
26 shell, which results in a system-specific default being used.
27@@ -51,9 +51,9 @@ config keys for an entry in ``users`` are as follows:
28 a Snappy user through ``snap create-user``. If an Ubuntu SSO account is
29 associated with the address, username and SSH keys will be requested from
30 there. Default: none
31- - ``ssh-authorized-keys``: Optional. List of ssh keys to add to user's
32+ - ``ssh_authorized_keys``: Optional. List of ssh keys to add to user's
33 authkeys file. Default: none
34- - ``ssh-import-id``: Optional. SSH id to import for user. Default: none
35+ - ``ssh_import_id``: Optional. SSH id to import for user. Default: none
36 - ``sudo``: Optional. Sudo rule to use, or list of sudo rules to use.
37 Default: none.
38 - ``system``: Optional. Create user as system user with no home directory.
39@@ -89,18 +89,18 @@ config keys for an entry in ``users`` are as follows:
40 homedir: <home directory>
41 inactive: <true/false>
42 lock_passwd: <true/false>
43- no-create-home: <true/false>
44- no-log-init: <true/false>
45- no-user-group: <true/false>
46+ no_create_home: <true/false>
47+ no_log_init: <true/false>
48+ no_user_group: <true/false>
49 passwd: <password>
50- primary-group: <primary group>
51- selinux-user: <selinux username>
52+ primary_group: <primary group>
53+ selinux_user: <selinux username>
54 shell: <shell path>
55 snapuser: <email>
56- ssh-authorized-keys:
57+ ssh_authorized_keys:
58 - <key>
59 - <key>
60- ssh-import-id: <id>
61+ ssh_import_id: <id>
62 sudo: <sudo config>
63 system: <true/false>
64 uid: <user id>
65diff --git a/doc/examples/cloud-config-user-groups.txt b/doc/examples/cloud-config-user-groups.txt
66index 0554d1f..7bca24a 100644
67--- a/doc/examples/cloud-config-user-groups.txt
68+++ b/doc/examples/cloud-config-user-groups.txt
69@@ -10,20 +10,20 @@ users:
70 - default
71 - name: foobar
72 gecos: Foo B. Bar
73- primary-group: foobar
74+ primary_group: foobar
75 groups: users
76- selinux-user: staff_u
77+ selinux_user: staff_u
78 expiredate: 2012-09-01
79- ssh-import-id: foobar
80+ ssh_import_id: foobar
81 lock_passwd: false
82 passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
83 - name: barfoo
84 gecos: Bar B. Foo
85 sudo: ALL=(ALL) NOPASSWD:ALL
86 groups: users, admin
87- ssh-import-id: None
88+ ssh_import_id: None
89 lock_passwd: true
90- ssh-authorized-keys:
91+ ssh_authorized_keys:
92 - <ssh pub key 1>
93 - <ssh pub key 2>
94 - name: cloudy
95@@ -37,10 +37,10 @@ users:
96 # gecos: The user name's real name, i.e. "Bob B. Smith"
97 # homedir: Optional. Set to the local path you want to use. Defaults to
98 # /home/<username>
99-# primary-group: define the primary group. Defaults to a new group created
100+# primary_group: define the primary group. Defaults to a new group created
101 # named after the user.
102 # groups: Optional. Additional groups to add the user to. Defaults to none
103-# selinux-user: Optional. The SELinux user for the user's login, such as
104+# selinux_user: Optional. The SELinux user for the user's login, such as
105 # "staff_u". When this is omitted the system will select the default
106 # SELinux user.
107 # lock_passwd: Defaults to true. Lock the password to disable password login
108@@ -66,11 +66,11 @@ users:
109 # should use SSH authentication only.
110 #
111 # You have thus been warned.
112-# no-create-home: When set to true, do not create home directory.
113-# no-user-group: When set to true, do not create a group named after the user.
114-# no-log-init: When set to true, do not initialize lastlog and faillog database.
115-# ssh-import-id: Optional. Import SSH ids
116-# ssh-authorized-keys: Optional. [list] Add keys to user's authorized keys file
117+# no_create_home: When set to true, do not create home directory.
118+# no_user_group: When set to true, do not create a group named after the user.
119+# no_log_init: When set to true, do not initialize lastlog and faillog database.
120+# ssh_import_id: Optional. Import SSH ids
121+# ssh_authorized_keys: Optional. [list] Add keys to user's authorized keys file
122 # sudo: Defaults to none. Set to the sudo string you want to use, i.e.
123 # ALL=(ALL) NOPASSWD:ALL. To add multiple rules, use the following
124 # format.
125diff --git a/tests/cloud_tests/testcases/examples/including_user_groups.yaml b/tests/cloud_tests/testcases/examples/including_user_groups.yaml
126index 469d03c..77528d9 100644
127--- a/tests/cloud_tests/testcases/examples/including_user_groups.yaml
128+++ b/tests/cloud_tests/testcases/examples/including_user_groups.yaml
129@@ -16,7 +16,7 @@ cloud_config: |
130 - default
131 - name: foobar
132 gecos: Foo B. Bar
133- primary-group: foobar
134+ primary_group: foobar
135 groups: users
136 expiredate: 2038-01-19
137 lock_passwd: false
138diff --git a/tests/cloud_tests/testcases/modules/user_groups.yaml b/tests/cloud_tests/testcases/modules/user_groups.yaml
139index 22b5d70..675dfb8 100644
140--- a/tests/cloud_tests/testcases/modules/user_groups.yaml
141+++ b/tests/cloud_tests/testcases/modules/user_groups.yaml
142@@ -15,7 +15,7 @@ cloud_config: |
143 - default
144 - name: foobar
145 gecos: Foo B. Bar
146- primary-group: foobar
147+ primary_group: foobar
148 groups: users
149 expiredate: 2038-01-19
150 lock_passwd: false
151diff --git a/tests/data/merge_sources/expected7.yaml b/tests/data/merge_sources/expected7.yaml
152index 25284f0..d32988e 100644
153--- a/tests/data/merge_sources/expected7.yaml
154+++ b/tests/data/merge_sources/expected7.yaml
155@@ -4,20 +4,20 @@ users:
156 - default
157 - name: foobar
158 gecos: Foo B. Bar
159- primary-group: foobar
160+ primary_group: foobar
161 groups: users
162- selinux-user: staff_u
163+ selinux_user: staff_u
164 expiredate: 2012-09-01
165- ssh-import-id: foobar
166+ ssh_import_id: foobar
167 lock-passwd: false
168 passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
169 - name: barfoo
170 gecos: Bar B. Foo
171 sudo: ALL=(ALL) NOPASSWD:ALL
172 groups: users, admin
173- ssh-import-id: None
174+ ssh_import_id: None
175 lock-passwd: true
176- ssh-authorized-keys:
177+ ssh_authorized_keys:
178 - <ssh pub key 1>
179 - <ssh pub key 2>
180 - name: cloudy
181@@ -29,10 +29,10 @@ users:
182 - sue
183 - name: foobar_jr
184 gecos: Foo B. Bar Jr
185- primary-group: foobar
186+ primary_group: foobar
187 groups: users
188- selinux-user: staff_u
189+ selinux_user: staff_u
190 expiredate: 2012-09-01
191- ssh-import-id: foobar
192+ ssh_import_id: foobar
193 lock-passwd: false
194 passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
195diff --git a/tests/data/merge_sources/source7-1.yaml b/tests/data/merge_sources/source7-1.yaml
196index 8fb9b32..6405fc9 100644
197--- a/tests/data/merge_sources/source7-1.yaml
198+++ b/tests/data/merge_sources/source7-1.yaml
199@@ -4,20 +4,20 @@ users:
200 - default
201 - name: foobar
202 gecos: Foo B. Bar
203- primary-group: foobar
204+ primary_group: foobar
205 groups: users
206- selinux-user: staff_u
207+ selinux_user: staff_u
208 expiredate: 2012-09-01
209- ssh-import-id: foobar
210+ ssh_import_id: foobar
211 lock-passwd: false
212 passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
213 - name: barfoo
214 gecos: Bar B. Foo
215 sudo: ALL=(ALL) NOPASSWD:ALL
216 groups: users, admin
217- ssh-import-id: None
218+ ssh_import_id: None
219 lock-passwd: true
220- ssh-authorized-keys:
221+ ssh_authorized_keys:
222 - <ssh pub key 1>
223 - <ssh pub key 2>
224 - name: cloudy
225diff --git a/tests/data/merge_sources/source7-2.yaml b/tests/data/merge_sources/source7-2.yaml
226index 1e26201..0cd2897 100644
227--- a/tests/data/merge_sources/source7-2.yaml
228+++ b/tests/data/merge_sources/source7-2.yaml
229@@ -6,11 +6,11 @@ users:
230 - sue
231 - name: foobar_jr
232 gecos: Foo B. Bar Jr
233- primary-group: foobar
234+ primary_group: foobar
235 groups: users
236- selinux-user: staff_u
237+ selinux_user: staff_u
238 expiredate: 2012-09-01
239- ssh-import-id: foobar
240+ ssh_import_id: foobar
241 lock-passwd: false
242 passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
243

Subscribers

People subscribed via source and target branches