Handle the case where 'user' is defined but 'users' isn't.
This commit is contained in:
@@ -507,13 +507,20 @@ def _normalize_users(u_cfg, def_user_cfg=None):
|
|||||||
|
|
||||||
|
|
||||||
def normalize_users_groups(cfg, distro):
|
def normalize_users_groups(cfg, distro):
|
||||||
|
if not cfg:
|
||||||
|
cfg = {}
|
||||||
users = {}
|
users = {}
|
||||||
groups = {}
|
groups = {}
|
||||||
if 'groups' in cfg:
|
if 'groups' in cfg:
|
||||||
groups = _normalize_groups(cfg['groups'])
|
groups = _normalize_groups(cfg['groups'])
|
||||||
|
|
||||||
|
# Handle the previous style of doing this...
|
||||||
old_user = None
|
old_user = None
|
||||||
if 'user' in cfg:
|
if 'user' in cfg and cfg['user']:
|
||||||
old_user = str(cfg['user'])
|
old_user = str(cfg['user'])
|
||||||
|
if not 'users' in cfg:
|
||||||
|
cfg['users'] = old_user
|
||||||
|
old_user = None
|
||||||
if 'users' in cfg:
|
if 'users' in cfg:
|
||||||
default_user_config = None
|
default_user_config = None
|
||||||
try:
|
try:
|
||||||
@@ -527,7 +534,7 @@ def normalize_users_groups(cfg, distro):
|
|||||||
# The old user replaces user[0]
|
# The old user replaces user[0]
|
||||||
base_users[0] = {'name': old_user}
|
base_users[0] = {'name': old_user}
|
||||||
elif not base_users and 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)):
|
elif isinstance(base_users, (dict)):
|
||||||
# Sorry order not possible
|
# Sorry order not possible
|
||||||
if old_user and old_user not in base_users:
|
if old_user and old_user not in base_users:
|
||||||
|
|||||||
@@ -174,6 +174,16 @@ class TestUGNormalize(MockerTestCase):
|
|||||||
self.assertIn('bob', users)
|
self.assertIn('bob', users)
|
||||||
self.assertIn('joe', users)
|
self.assertIn('joe', users)
|
||||||
self.assertIn('zetta', 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):
|
def test_users_dict_default_additional(self):
|
||||||
distro = self._make_distro('ubuntu', 'bob')
|
distro = self._make_distro('ubuntu', 'bob')
|
||||||
|
|||||||
Reference in New Issue
Block a user