diff options
-rw-r--r-- | cloudinit/distros/__init__.py | 11 | ||||
-rw-r--r-- | tests/unittests/test_distros/test_user_data_normalize.py | 10 |
2 files changed, 19 insertions, 2 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 13e4fd44..4cf8f745 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -507,13 +507,20 @@ def _normalize_users(u_cfg, def_user_cfg=None): def normalize_users_groups(cfg, distro): + if not cfg: + cfg = {} users = {} groups = {} if 'groups' in cfg: groups = _normalize_groups(cfg['groups']) + + # Handle the previous style of doing this... old_user = None - if 'user' in cfg: + if 'user' in cfg and cfg['user']: old_user = str(cfg['user']) + if not 'users' in cfg: + cfg['users'] = old_user + old_user = None if 'users' in cfg: default_user_config = None try: @@ -527,7 +534,7 @@ def normalize_users_groups(cfg, distro): # The old user replaces user[0] base_users[0] = {'name': old_user} elif not base_users and old_user: - base.append({'name': old_user}) + base_users.append({'name': old_user}) elif isinstance(base_users, (dict)): # Sorry order not possible if old_user and old_user not in base_users: diff --git a/tests/unittests/test_distros/test_user_data_normalize.py b/tests/unittests/test_distros/test_user_data_normalize.py index 4a4e1a29..890d8f05 100644 --- a/tests/unittests/test_distros/test_user_data_normalize.py +++ b/tests/unittests/test_distros/test_user_data_normalize.py @@ -174,6 +174,16 @@ class TestUGNormalize(MockerTestCase): self.assertIn('bob', users) self.assertIn('joe', users) self.assertIn('zetta', users) + ug_cfg = { + 'user': 'zetta', + } + (users, _groups) = self._norm(ug_cfg, distro) + self.assertIn('zetta', users) + ug_cfg = { + } + (users, groups) = self._norm(ug_cfg, distro) + self.assertEquals({}, users) + self.assertEquals({}, groups) def test_users_dict_default_additional(self): distro = self._make_distro('ubuntu', 'bob') |