Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cloudinit/distros/ug_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ def _normalize_users(u_cfg, def_user_cfg=None):
# Now merge the extracted groups with the default config provided
users_groups = util.uniq_merge_sorted(parsed_groups, def_groups)
parsed_config["groups"] = ",".join(users_groups)
# The real config for the default user is the combination of the
# default user config provided by the distro, the default user
# config provided by the above merging for the user 'default' and
# then the parsed config from the user's 'real name' which does not
# have to be 'default' (but could be)
# The real config for the default user is the combination of:
# - the parsed config from the user's 'real name' which does
# not have to be 'default' (but could be)
# - then the default user config provided by the above merging
# for the user 'default'
# - then the default user config provided by the distro not
users[def_user] = util.mergemanydict(
[def_user_cfg, def_config, parsed_config]
[parsed_config, def_config, def_user_cfg]
)

# Ensure that only the default user that we found (if any) is actually
Expand Down
24 changes: 24 additions & 0 deletions tests/unittests/distros/test_user_data_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,30 @@ def test_users_dict_default_additional(self):
assert users["bob"]["blah"] is True
assert users["bob"]["default"] is True

def test_users_dict_override_default_attribute(self):
distro = self._make_distro("ubuntu", bcfg)
ug_cfg = {
"users": ["default", {"name": "bob", "lock_passwd": False}],
}
users, _ = self._norm(ug_cfg, distro)

assert "bob" in users
assert "name" not in users["bob"]

for key, val in bcfg.items():
if key == "lock_passwd":
# Assert that the default user config is True
assert val is True
# Assert that the resolved value
# matches the passed config: False
assert users["bob"][key] is False
elif key == "groups":
assert users["bob"][key] == ",".join(val)
elif key != "name":
assert users["bob"][key] == val

assert users["bob"]["default"] is True

def test_users_dict_extract(self):
distro = self._make_distro("ubuntu", bcfg)
ug_cfg = {
Expand Down
Loading