=== modified file 'debian/changelog' --- debian/changelog 2013-01-18 15:28:08 +0000 +++ debian/changelog 2013-01-31 13:40:57 +0000 @@ -2,6 +2,9 @@ * debian/patches/lp-1100545-allow-config-drive-from-cdrom.patch: in config-drive data to be provided from a CD-ROM (LP: #1100545) + * debian/patches/lp-1100920-fix-default-user.patch: + if 'user' is specified, that should change the default configured + user. -- Scott Moser Fri, 18 Jan 2013 10:24:43 -0500 === added file 'debian/patches/lp-1100920-fix-default-user.patch' --- debian/patches/lp-1100920-fix-default-user.patch 1970-01-01 00:00:00 +0000 +++ debian/patches/lp-1100920-fix-default-user.patch 2013-01-31 13:39:43 +0000 @@ -0,0 +1,153 @@ +Author: Scott Moser +Bug: https://launchpad.net/bugs/1100920 +Applied-Upstream: revno 764 +Description: Merge the old user style with the distro provided config. + . + When the old user: style entry is found, don't forget that + we need to use the distro settings that are provided but + override the name with the new name, this is now accomplished + by merging them together in the correct order (using the standard + cloud-init merging algo). +--- a/cloudinit/distros/__init__.py ++++ b/cloudinit/distros/__init__.py +@@ -553,41 +553,68 @@ def _normalize_users(u_cfg, def_user_cfg + 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 ++ # Handle the previous style of doing this where the first user ++ # overrides the concept of the default user if provided in the user: XYZ ++ # format. ++ old_user = {} + 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: +- default_user_config = distro.get_default_user() +- except NotImplementedError: +- LOG.warn(("Distro has not implemented default user " +- "access. No default user will be normalized.")) +- base_users = cfg['users'] +- if old_user: +- if isinstance(base_users, (list)): +- if len(base_users): +- # The old user replaces user[0] +- base_users[0] = {'name': old_user} +- else: +- # Just add it on at the end... +- base_users.append({'name': old_user}) +- elif isinstance(base_users, (dict)): +- if old_user not in base_users: +- base_users[old_user] = True +- elif isinstance(base_users, (str, basestring)): +- # Just append it on to be re-parsed later +- base_users += ",%s" % (old_user) +- users = _normalize_users(base_users, default_user_config) ++ old_user = cfg['user'] ++ # Translate it into the format that is more useful ++ # going forward ++ if isinstance(old_user, (basestring, str)): ++ old_user = { ++ 'name': old_user, ++ } ++ if not isinstance(old_user, (dict)): ++ LOG.warn(("Format for 'user' key must be a string or " ++ "dictionary and not %s"), util.obj_name(old_user)) ++ old_user = {} ++ ++ # If no old user format, then assume the distro ++ # provides what the 'default' user maps to, but notice ++ # that if this is provided, we won't automatically inject ++ # a 'default' user into the users list, while if a old user ++ # format is provided we will. ++ distro_user_config = {} ++ try: ++ distro_user_config = distro.get_default_user() ++ except NotImplementedError: ++ LOG.warn(("Distro has not implemented default user " ++ "access. No distribution provided default user" ++ " will be normalized.")) ++ ++ # Merge the old user (which may just be an empty dict when not ++ # present with the distro provided default user configuration so ++ # that the old user style picks up all the distribution specific ++ # attributes (if any) ++ default_user_config = util.mergemanydict([old_user, distro_user_config]) ++ ++ base_users = cfg.get('users', []) ++ if not isinstance(base_users, (list, dict, str, basestring)): ++ LOG.warn(("Format for 'users' key must be a comma separated string" ++ " or a dictionary or a list and not %s"), ++ util.obj_name(base_users)) ++ base_users = [] ++ ++ if old_user: ++ # Ensure that when user: is provided that this user ++ # always gets added (as the default user) ++ if isinstance(base_users, (list)): ++ # Just add it on at the end... ++ base_users.append({'name': 'default'}) ++ elif isinstance(base_users, (dict)): ++ base_users['default'] = base_users.get('default', True) ++ elif isinstance(base_users, (str, basestring)): ++ # Just append it on to be re-parsed later ++ base_users += ",default" ++ ++ users = _normalize_users(base_users, default_user_config) + return (users, groups) + + +--- a/tests/unittests/test_distros/test_user_data_normalize.py ++++ b/tests/unittests/test_distros/test_user_data_normalize.py +@@ -143,26 +143,29 @@ class TestUGNormalize(MockerTestCase): + 'users': 'default' + } + (users, _groups) = self._norm(ug_cfg, distro) +- self.assertIn('bob', users) ++ self.assertNotIn('bob', users) # Bob is not the default now, zetta is + self.assertIn('zetta', users) ++ self.assertTrue(users['zetta']['default']) + self.assertNotIn('default', users) + ug_cfg = { + 'user': 'zetta', + 'users': 'default, joe' + } + (users, _groups) = self._norm(ug_cfg, distro) +- self.assertIn('bob', users) ++ self.assertNotIn('bob', users) # Bob is not the default now, zetta is + self.assertIn('joe', users) + self.assertIn('zetta', users) ++ self.assertTrue(users['zetta']['default']) + self.assertNotIn('default', users) + ug_cfg = { + 'user': 'zetta', + 'users': ['bob', 'joe'] + } + (users, _groups) = self._norm(ug_cfg, distro) +- self.assertNotIn('bob', users) ++ self.assertIn('bob', users) + self.assertIn('joe', users) + self.assertIn('zetta', users) ++ self.assertTrue(users['zetta']['default']) + ug_cfg = { + 'user': 'zetta', + 'users': { +@@ -174,6 +177,7 @@ class TestUGNormalize(MockerTestCase): + self.assertIn('bob', users) + self.assertIn('joe', users) + self.assertIn('zetta', users) ++ self.assertTrue(users['zetta']['default']) + ug_cfg = { + 'user': 'zetta', + } === modified file 'debian/patches/series' --- debian/patches/series 2013-01-18 15:28:08 +0000 +++ debian/patches/series 2013-01-31 13:36:35 +0000 @@ -8,3 +8,4 @@ lp-1077020-fix-ca-certificates-blanklines.patch lp-1090482-fix-cloud-config-mirrors.patch lp-1100545-allow-config-drive-from-cdrom.patch +lp-1100920-fix-default-user.patch