test: verify hostname format %h-%m in running and operational

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-06-25 17:22:36 +02:00
parent 32ef120928
commit 0d0d97ad3f
+30 -3
View File
@@ -1,13 +1,16 @@
#!/usr/bin/env python3
import random, string
import random
import string
import re
import infamy
with infamy.Test() as test:
with test.step("Initialize"):
env = infamy.Env(infamy.std_topology("1x1"))
target = env.attach("target", "mgmt")
tgtssh = env.attach("target", "mgmt", "ssh")
fmt = "%h-%m"
with test.step("Set new hostname"):
new = "".join((random.choices(string.ascii_lowercase, k=16)))
@@ -20,6 +23,30 @@ with infamy.Test() as test:
with test.step(f"Verify new hostname ({new})"):
running = target.get_config_dict("/ietf-system:system")
assert(running["system"]["hostname"] == new)
assert running["system"]["hostname"] == new
with test.step(f"Set hostname format: {fmt}"):
target.put_config_dict("ietf-system", {
"system": {
"hostname": fmt,
}
})
with test.step(f"Verify hostname format in running: {fmt}"):
running = target.get_config_dict("/ietf-system:system")
if running["system"]["hostname"] != fmt:
test.fail()
cmd = tgtssh.runsh("sed -n s/^DEFAULT_HOSTNAME=//p /etc/os-release")
default = cmd.stdout.rstrip()
with test.step(f"Verify hostname format in operational: {default}-c0-ff-ee"):
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()