Skip to content

Commit

Permalink
Merge pull request #1338 from dbungert/cloud-config-schema-jammy
Browse files Browse the repository at this point in the history
cloud-config: schema drop deprecated dict user.groups value type (jammy branch)
  • Loading branch information
dbungert authored Jun 28, 2022
2 parents df11755 + 10d01b9 commit 762a7d9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
6 changes: 3 additions & 3 deletions subiquity/common/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import logging
import os
from typing import List

log = logging.getLogger('subiquity.common.resources')

Expand All @@ -26,7 +27,7 @@ def resource_path(relative_path):
return os.path.join(os.environ.get("SUBIQUITY_ROOT", "."), relative_path)


def get_users_and_groups(chroot_prefix=[]):
def get_users_and_groups(chroot_prefix=[]) -> List:
# prevent import when calling just resource_path
from subiquitycore.utils import run_command

Expand All @@ -43,5 +44,4 @@ def get_users_and_groups(chroot_prefix=[]):
for line in cp.stdout.splitlines():
target_groups.add(line.split(':')[0])

groups = target_groups.intersection(groups)
return groups
return list(target_groups.intersection(groups))
2 changes: 1 addition & 1 deletion subiquity/models/subiquity.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _cloud_init_config(self):
'gecos': user.realname,
'passwd': user.password,
'shell': '/bin/bash',
'groups': groups,
'groups': ','.join(sorted(groups)),
'lock_passwd': False,
}
if self.ssh.authorized_keys:
Expand Down
29 changes: 28 additions & 1 deletion subiquity/models/tests/test_subiquity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import fnmatch
import unittest
from unittest import mock
import yaml

from subiquitycore.pubsub import MessageHub
Expand All @@ -28,6 +29,24 @@
)
from subiquity.server.types import InstallerChannels

getent_group_output = '''
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog
tty:x:5:syslog
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
sudo:x:27:
ssh:x:118:
lxd:x:132:
'''


class TestModelNames(unittest.TestCase):

Expand Down Expand Up @@ -182,7 +201,8 @@ def test_mirror(self):
config = model.render()
self.assertNotIn('apt', config)

def test_cloud_init_user_list_merge(self):
@mock.patch('subiquitycore.utils.run_command')
def test_cloud_init_user_list_merge(self, run_cmd):
main_user = IdentityData(
username='mainuser',
crypted_password='dummy_value',
Expand All @@ -193,10 +213,17 @@ def test_cloud_init_user_list_merge(self):
model = self.make_model()
model.identity.add_user(main_user)
model.userdata = {'users': [secondary_user]}

run_cmd.return_value.stdout = getent_group_output
cloud_init_config = model._cloud_init_config()
self.assertEqual(len(cloud_init_config['users']), 2)
self.assertEqual(cloud_init_config['users'][0]['name'], 'mainuser')
self.assertEqual(
cloud_init_config['users'][0]['groups'],
'adm,lxd,sudo'
)
self.assertEqual(cloud_init_config['users'][1]['name'], 'user2')
run_cmd.assert_called_with(['getent', 'group'], check=True)

with self.subTest('Secondary user only'):
model = self.make_model()
Expand Down

0 comments on commit 762a7d9

Please sign in to comment.