Skip to content

Commit 3f35931

Browse files
author
Dan Lavu
committed
adding subid management to the ipa role
1 parent 06abf1b commit 3f35931

File tree

1 file changed

+59
-0
lines changed
  • sssd_test_framework/roles

1 file changed

+59
-0
lines changed

sssd_test_framework/roles/ipa.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ..misc import (
2020
attrs_include_value,
2121
attrs_parse,
22+
delimiter_parse,
2223
get_attr,
2324
ip_version,
2425
to_list,
@@ -1192,6 +1193,20 @@ def test_example(client: Client, ipa: IPA):
11921193
"""
11931194
return IDUserOverride(self)
11941195

1196+
def subid(self) -> IPASubID:
1197+
"""
1198+
IPA subid management.
1199+
1200+
.. code-block:: python
1201+
:caption: Example usage
1202+
1203+
@pytest.mark.topology(KnownTopology.IPA)
1204+
def test_ipa__subids_configured(ipa: IPA):
1205+
user = ipa.user("user1").add()
1206+
user.subid().generate()
1207+
"""
1208+
return IPASubID(self)
1209+
11951210

11961211
class IDUserOverride(IPAUser):
11971212
"""
@@ -1400,6 +1415,50 @@ def show_override(self, idview_name: str) -> dict[str, list[str]]:
14001415
return attrs_parse(lines)
14011416

14021417

1418+
class IPASubID(IPAUser):
1419+
"""
1420+
IPA sub id management.
1421+
"""
1422+
1423+
def __init__(self, user: IPAUser) -> None:
1424+
"""
1425+
:param user: IPA user object.
1426+
:type user: IPAUser
1427+
"""
1428+
super().__init__(user.role, user.name)
1429+
1430+
self.name = user.name
1431+
""" Owner name."""
1432+
1433+
self.uid_start: int | None = None
1434+
""" SubUID range start"""
1435+
1436+
self.uid_size: int | None = None
1437+
""" SubUID range size."""
1438+
1439+
self.gid_start: int | None = None
1440+
""" SubGID range start."""
1441+
1442+
self.gid_size: int | None = None
1443+
""" SubGID range size."""
1444+
1445+
def generate(self) -> IPASubID:
1446+
"""
1447+
Generate subordinate id.
1448+
"""
1449+
self.host.conn.run(f"ipa subid-generate --owner {self.name}")
1450+
result = self.host.conn.run(f"ipa subid-find --owner {self.name}").stdout_lines
1451+
result = [item for item in result if ":" in item]
1452+
subids = {k: v for k, v in delimiter_parse(result).items()}
1453+
1454+
self.uid_start = int(subids["SubUID range start"]) if subids.get("SubUID range start") else None
1455+
self.uid_size = int(subids["SubUID range size"]) if subids.get("SubUID range size") else None
1456+
self.gid_start = int(subids["SubGID range start"]) if subids.get("SubGID range start") else None
1457+
self.gid_size = int(subids["SubGID range size"]) if subids.get("SubGID range size") else None
1458+
1459+
return self
1460+
1461+
14031462
class IPAGroup(IPAObject):
14041463
"""
14051464
IPA group management.

0 commit comments

Comments
 (0)