summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-24 20:33:13 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-09-24 20:33:13 -0700
commita2c6279d303a3b85625404653c7ab8081281ee18 (patch)
tree5093c33ffff091cc3e08d1b522d3de3a58cc6c60
parent90b6cfd005f5af90991fe93e5a08c8a8849e2a6d (diff)
downloadvyos-cloud-init-a2c6279d303a3b85625404653c7ab8081281ee18.tar.gz
vyos-cloud-init-a2c6279d303a3b85625404653c7ab8081281ee18.zip
Handle the case where 'user' is defined but 'users' isn't.
-rw-r--r--cloudinit/distros/__init__.py11
-rw-r--r--tests/unittests/test_distros/test_user_data_normalize.py10
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')