Skip to content

Commit c8a7b97

Browse files
author
Dan Lavu
committed
adding subid management to the ipa role
1 parent 64036f8 commit c8a7b97

File tree

1 file changed

+106
-0
lines changed
  • sssd_test_framework/roles

1 file changed

+106
-0
lines changed

sssd_test_framework/roles/ipa.py

Lines changed: 106 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,
@@ -359,6 +360,27 @@ def test_example_group(client: Client, ipa: IPA):
359360
"""
360361
return IPAGroup(self, name)
361362

363+
def subid(self, name: str = "admin") -> IPASubID:
364+
"""
365+
IPA subid management.
366+
367+
.. code-block:: python
368+
:caption: Example usage
369+
370+
@pytest.mark.topology(KnownTopology.IPA)
371+
def test_ipa__subids_configured(ipa: IPA):
372+
ipa.user("user1").add()
373+
user = ipa.subid("user1")
374+
user.generate()
375+
376+
assert user.uid_start is not None
377+
assert user.uid_range is not None
378+
assert user.gid_start is not None
379+
assert user.gid_range is not None
380+
assert user.uid is not None
381+
"""
382+
return IPASubID(self, name)
383+
362384
def netgroup(self, name: str) -> IPANetgroup:
363385
"""
364386
Get netgroup object.
@@ -1332,6 +1354,90 @@ def show_override(self, idview_name: str) -> dict[str, list[str]]:
13321354
return attrs_parse(lines)
13331355

13341356

1357+
class IPASubID(IPAObject):
1358+
"""
1359+
IPA sub id management.
1360+
"""
1361+
1362+
def __init__(self, role: IPA, owner: str = "admin"):
1363+
"""
1364+
:param role: IPA role object.
1365+
:type role: IPA
1366+
:param owner: Owner or username.
1367+
:type owner: str
1368+
"""
1369+
super().__init__(role, owner, command_group="subid")
1370+
1371+
self.owner = owner
1372+
""" SubID owner."""
1373+
1374+
self.uid: str | None = None
1375+
""" SubUID, set during generate. """
1376+
1377+
self.uid_start: int | None = None
1378+
""" SubUID range start, set when found."""
1379+
1380+
self.uid_range: int | None = None
1381+
""" SubUID range size, set when found."""
1382+
1383+
self.gid_start: int | None = None
1384+
""" SubGID range start, set when found."""
1385+
1386+
self.gid_range: int | None = None
1387+
""" SubGID range size, set when found."""
1388+
1389+
def generate(self) -> IPASubID:
1390+
"""
1391+
Generate subordinate id.
1392+
"""
1393+
result = self.host.conn.run(f"ipa subid-generate --owner {self.owner}").stdout_lines
1394+
result = [item for item in result if ":" in item]
1395+
subids = delimiter_parse(result)
1396+
1397+
self.uid = subids.get("Unique ID")
1398+
self.uid_start = int(s) if (s := subids.get("SubUID range start")) else None
1399+
self.uid_range = int(s) if (s := subids.get("SubUID range size")) else None
1400+
self.gid_start = int(s) if (s := subids.get("SubGID range start")) else None
1401+
self.gid_range = int(s) if (s := subids.get("SubGID range size")) else None
1402+
1403+
return self
1404+
1405+
def show(self, subid: str) -> dict[str, str]:
1406+
"""
1407+
Show subid info.
1408+
1409+
:param subid: Subordinate id.
1410+
:type subid: str
1411+
:return: Subordinate id information.
1412+
:rtype: dict[str, str]
1413+
"""
1414+
result = self.host.conn.run(f"ipa subid-show {subid}").stdout_lines
1415+
result = [item for item in result if ":" in item]
1416+
out = delimiter_parse(result)
1417+
1418+
return out
1419+
1420+
def find(self, subid: str | None = None) -> dict[str, str]:
1421+
"""
1422+
Find subid.
1423+
1424+
:param subid: Subordinate id, optional
1425+
:type subid: str | None = None
1426+
:return: Subordinate id information.
1427+
:rtype: dict[str, str]
1428+
"""
1429+
if subid is not None:
1430+
args = subid
1431+
else:
1432+
args = f"--owner {self.owner}"
1433+
1434+
result = self.host.conn.run(f"ipa subid-find {args}", raise_on_error=False).stdout_lines
1435+
result = [item for item in result if ":" in item]
1436+
out = delimiter_parse(result)
1437+
1438+
return out
1439+
1440+
13351441
class IPAGroup(IPAObject):
13361442
"""
13371443
IPA group management.

0 commit comments

Comments
 (0)