support creating groups with non-unique GIDs for testing purposes

This commit is contained in:
nicholasmhughes 2022-07-25 16:18:48 -04:00 committed by Megan Wilhite
parent ac2408477d
commit b452ed5663
3 changed files with 14 additions and 2 deletions

1
changelog/62377.fixed Normal file
View file

@ -0,0 +1 @@
Fix groups with duplicate GIDs are not returned by get_group_list

View file

@ -40,8 +40,10 @@ def __virtual__():
) )
def add(name, gid=None, system=False, root=None): def add(name, gid=None, system=False, root=None, non_unique=False):
""" """
.. versionchanged:: 3006.0
Add the specified group Add the specified group
name name
@ -56,6 +58,11 @@ def add(name, gid=None, system=False, root=None):
root root
Directory to chroot into Directory to chroot into
non_unique
Allow creating groups with duplicate (non-unique) GIDs
.. versionchanged:: 3006.0
CLI Example: CLI Example:
.. code-block:: bash .. code-block:: bash
@ -67,6 +74,8 @@ def add(name, gid=None, system=False, root=None):
cmd.append("-g {}".format(gid)) cmd.append("-g {}".format(gid))
if system and __grains__["kernel"] != "OpenBSD": if system and __grains__["kernel"] != "OpenBSD":
cmd.append("-r") cmd.append("-r")
if non_unique:
cmd.append("-o")
if root is not None: if root is not None:
cmd.extend(("-R", root)) cmd.extend(("-R", root))

View file

@ -214,7 +214,9 @@ class TestGroup:
def __enter__(self): def __enter__(self):
group = self.sminion.functions.group.info(self.name) group = self.sminion.functions.group.info(self.name)
if not group: if not group:
ret = self.sminion.functions.group.add(self.name, gid=self.gid) ret = self.sminion.functions.group.add(
self.name, gid=self.gid, non_unique=True
)
assert ret assert ret
self._delete_group = True self._delete_group = True
log.debug("Created system group: %s", self) log.debug("Created system group: %s", self)