Files
infix/test/case/ietf_system/hostname/test.py
T
Joachim Wiberg 44d37808f1 test/case: use 9pm 'name:' for all test names
To reduce the duplication of effort between 9pm and the Infamy framework
this change consolidates the move from local 'infamy: title:' extension
to 9pm 'name:'.

For the parameterized tunnel tests we leverage the 9pm dynamic test-spec
variable, which looks for a correspodning <case>.adoc instead of static
Readme.adoc, when generating the test report.

Each test documentation should cover all aspects of the test, much like
the usage text of a UNIX program.  To this end, the tunnel test docs are
now more spelled out, including all invariants.

Some refactoring of these tests were also necessary, e.g., replacing any
reserved Python keywords like 'type', and other PEP-8 fixes.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-09-15 14:26:06 +02:00

56 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""Set hostname
Verify that it is possible to set hostname using both regular text and
format specificers, like '%h-%m'. These format specifiers expand to
'<default hostname>-<MAC>', where MAC is the last three bytes of the
base MAC address. E.g., ix-01-01-01.
"""
import re
import infamy
with infamy.Test() as test:
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
target = env.attach("target", "mgmt")
tgtssh = env.attach("target", "mgmt", "ssh")
FMT = "%h-%m"
NEW = "h0stn4m3"
with test.step("Set hostname to 'h0stn4m3'"):
target.put_config_dict("ietf-system", {
"system": {
"hostname": NEW,
}
})
with test.step("Verify new hostname 'h0stn4m3'"):
running = target.get_config_dict("/ietf-system:system")
assert running["system"]["hostname"] == NEW
with test.step("Set hostname to '%h-%m'"):
target.put_config_dict("ietf-system", {
"system": {
"hostname": FMT,
}
})
with test.step("Verify hostname is %h-%m in running configuration"):
running = target.get_config_dict("/ietf-system:system")
if running["system"]["hostname"] != FMT:
test.fail()
with test.step("Verify hostname format in operational"):
cmd = tgtssh.runsh("sed -n s/^DEFAULT_HOSTNAME=//p /etc/os-release")
default = cmd.stdout.rstrip()
oper = target.get_data("/ietf-system:system")
name = oper["system"]["hostname"]
pattern = rf'^{default}-([0-9a-fA-F]{{2}}-){{2}}[0-9a-fA-F]{{2}}$'
regex = re.compile(pattern)
if not regex.match(name):
test.fail()
test.succeed()