Skip to content

Commit 5d02429

Browse files
author
Dan Lavu
committed
adding hostname() method and updating nsupdate
1 parent 27bdf1e commit 5d02429

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

sssd_test_framework/utils/network.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ def ip(self, name: str | None = None) -> IPUtils:
4040

4141
return inst
4242

43+
def hostname(self, name: str | None = None) -> str | None:
44+
"""
45+
Run hostname command.
46+
47+
:param name: Hostname.
48+
:type name: str | None = None
49+
"""
50+
if isinstance(name, str):
51+
self.__rollback.append(f"hostname {self.host.conn.run('hostname').stdout.strip()}")
52+
self.host.conn.run(f"hostname {name}")
53+
return None
54+
else:
55+
return self.host.conn.run("hostname").stdout.strip()
56+
4357
def tcpdump(self, pcap_path: str, args: list[Any] | None = None) -> SSHKillableProcess:
4458
"""
4559
Run tcpdump. The packets are captured in ``pcap_path``.
@@ -136,17 +150,22 @@ def dig(self, address: str, server: str = "", reverse: bool = False) -> dict[str
136150

137151
return None if not records else records[0]
138152

139-
def nslookup(self, args: list[str]) -> ProcessResult:
153+
def nslookup(self, args: list[str], max_retries: int = 1, delay: int = 0) -> ProcessResult:
140154
"""
141155
Execute nslookup command with given arguments.
142156
143157
:param args: Arguments to ``nslookup``, defaults to None
144158
:type args: list[str]
145-
:return: SSH Process result
159+
:param max_retries: Retry attempts, optional
160+
:type max_retries: int = 1
161+
:param delay: Delay between attempts, optional
162+
:type delay: int = 0
163+
:return: Process result object.
146164
:rtype: ProcessResult
147165
"""
148-
149-
return self.host.conn.exec(["nslookup", *args], raise_on_error=False)
166+
return self.host.conn.exec(
167+
["nslookup", f"-retry={str(max_retries)}", f"-timeout={str(delay)}", *args], raise_on_error=False
168+
)
150169

151170
def teardown(self):
152171
"""

0 commit comments

Comments
 (0)