Skip creating groups with the same name as a user

Otherwise the user creation fails when anaconda sees there is already a
group with that name. Log a warning and continue on.
This commit is contained in:
Brian C. Lane 2018-05-09 11:20:24 -07:00
parent cb7e4e55ba
commit 5443c1cfea
3 changed files with 29 additions and 3 deletions

View File

@ -182,15 +182,20 @@ def add_customizations(f, recipe):
continue continue
f.write('sshkey --user %s "%s"\n' % (sshkey["user"], sshkey["key"])) f.write('sshkey --user %s "%s"\n' % (sshkey["user"], sshkey["key"]))
# Creating a user also creates a group. Make a list of the names for later
user_groups = []
if "user" in customizations: if "user" in customizations:
# only name is required, everything else is optional # only name is required, everything else is optional
for user in customizations["user"]: for user in customizations["user"]:
write_ks_user(f, user) write_ks_user(f, user)
user_groups.append(user["name"])
if "group" in customizations: if "group" in customizations:
for group in customizations["group"]: for group in customizations["group"]:
write_ks_group(f, group) if group["name"] not in user_groups:
write_ks_group(f, group)
else:
log.warning("Skipping group %s, already created by user", group["name"])
def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_mode=0): def start_build(cfg, dnflock, gitlock, branch, recipe_name, compose_type, test_mode=0):
""" Start the build """ Start the build

View File

@ -26,7 +26,7 @@ description = "Widget admin account"
password = "$6$CHO2$3rN8eviE2t50lmVyBYihTgVRHcaecmeCk31LeOUleVK/R/aeWVHVZDi26zAH.o0ywBKH9Tc0/wm7sW/q39uyd1" password = "$6$CHO2$3rN8eviE2t50lmVyBYihTgVRHcaecmeCk31LeOUleVK/R/aeWVHVZDi26zAH.o0ywBKH9Tc0/wm7sW/q39uyd1"
home = "/srv/widget/" home = "/srv/widget/"
shell = "/usr/bin/bash" shell = "/usr/bin/bash"
groups = ["widget", "users"] groups = ["widget", "users", "students"]
uid = 1200 uid = 1200
[[customizations.user]] [[customizations.user]]
@ -36,6 +36,10 @@ password = "simple plain password"
[[customizations.user]] [[customizations.user]]
name = "bart" name = "bart"
key = "SSH KEY FOR BART" key = "SSH KEY FOR BART"
groups = ["students"]
[[customizations.group]] [[customizations.group]]
name = "widget" name = "widget"
[[customizations.group]]
name = "students"

View File

@ -85,6 +85,10 @@ GROUP_GID = GROUP + """
gid = 1011 gid = 1011
""" """
USER_GROUP = USER + """[[customizations.group]]
name = "tester"
"""
KS_USER_ALL = '''sshkey --user tester "A SSH KEY FOR TESTER" KS_USER_ALL = '''sshkey --user tester "A SSH KEY FOR TESTER"
user --name tester --homedir /opt/users/tester/ --iscrypted --password "$6$CHO2$3rN8eviE2t50lmVyBYihTgVRHcaecmeCk31LeOUleVK/R/aeWVHVZDi26zAH.o0ywBKH9Tc0/wm7sW/q39uyd1" --shell /usr/bin/zsh --uid 1013 --gid 4242 --gecos "a test user account" user --name tester --homedir /opt/users/tester/ --iscrypted --password "$6$CHO2$3rN8eviE2t50lmVyBYihTgVRHcaecmeCk31LeOUleVK/R/aeWVHVZDi26zAH.o0ywBKH9Tc0/wm7sW/q39uyd1" --shell /usr/bin/zsh --uid 1013 --gid 4242 --gecos "a test user account"
''' '''
@ -96,6 +100,12 @@ class CustomizationsTestCase(unittest.TestCase):
add_customizations(f, r) add_customizations(f, r)
self.assertTrue(result in f.getvalue(), f.getvalue()) self.assertTrue(result in f.getvalue(), f.getvalue())
def assertNotCustomization(self, test, result):
r = recipe_from_toml(test)
f = StringIO()
add_customizations(f, r)
self.assertTrue(result not in f.getvalue(), f.getvalue())
def test_set_hostname(self): def test_set_hostname(self):
"""Test setting the hostname""" """Test setting the hostname"""
self.assertCustomization(HOSTNAME, "network --hostname=testhostname") self.assertCustomization(HOSTNAME, "network --hostname=testhostname")
@ -144,6 +154,13 @@ class CustomizationsTestCase(unittest.TestCase):
"""Test creating user with group membership""" """Test creating user with group membership"""
self.assertCustomization(USER + USER_GROUPS, "--groups wheel,users") self.assertCustomization(USER + USER_GROUPS, "--groups wheel,users")
def test_user_same_group(self):
"""Test creating a group with the same name as a user"""
# Creating a group with the same name should skip the group creation
self.assertCustomization(USER_GROUP, "user --name tester")
self.assertNotCustomization(USER_GROUP, "group --name tester")
def test_create_user_all(self): def test_create_user_all(self):
"""Test creating user with all settings""" """Test creating user with all settings"""
r = recipe_from_toml(USER_ALL) r = recipe_from_toml(USER_ALL)