From dce9a9c53de899a00793d4c129c6059656650f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Tue, 2 Sep 2025 17:13:11 +0200 Subject: [PATCH] test: Add new sanity check tests One to verify it is the correct version on the duts and one that check that it is the correct bootorder. --- test/case/all.yaml | 14 ++++++++++++++ test/case/meta/bootorder.py | 24 ++++++++++++++++++++++++ test/case/meta/check-version.py | 24 ++++++++++++++++++++++++ test/case/meta/reproducible.py | 23 ----------------------- test/env | 2 ++ test/infamy/topology.py | 8 +++++++- test/test.mk | 3 +-- test/virt/dual/topology.dot.in | 2 ++ test/virt/quad/topology.dot.in | 4 ++++ 9 files changed, 78 insertions(+), 26 deletions(-) create mode 100755 test/case/meta/bootorder.py create mode 100755 test/case/meta/check-version.py diff --git a/test/case/all.yaml b/test/case/all.yaml index 22cbecec..74174a30 100644 --- a/test/case/all.yaml +++ b/test/case/all.yaml @@ -6,12 +6,26 @@ infamy: specification: False +- case: meta/bootorder.py + infamy: + specification: False + +- case: meta/check-version.py + infamy: + specification: False + + - name: Misc tests suite: misc/misc.yaml - name: ietf-system suite: ietf_system/ietf_system.yaml +# Upgrade may leave wrong boot order +- case: meta/bootorder.py + infamy: + specification: False + - name: ietf-syslog suite: ietf_syslog/ietf_syslog.yaml diff --git a/test/case/meta/bootorder.py b/test/case/meta/bootorder.py new file mode 100755 index 00000000..a82d4c7b --- /dev/null +++ b/test/case/meta/bootorder.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import infamy + +with infamy.Test() as test: + with test.step("Discover topology and attach to available DUTs"): + env = infamy.Env(False) + ctrl = env.ptop.get_ctrl() + duts = {} + duts_state = {} + for ix in env.ptop.get_infixen(): + cport, ixport = env.ptop.get_mgmt_link(ctrl, ix) + print(f"Attaching to {ix}:{ixport} via {ctrl}:{cport}") + duts[ix] = env.attach(ix, ixport) + + with test.step("Verify bootorder"): + for name, tgt in duts.items(): + expected = env.ptop.get_expected_boot(name) + running = tgt.get_data("/ietf-system:system-state") + running = running['system-state']['software']['booted'] + print(f"{name}: booted: {running} expected: {expected}") + + if running != expected: + test.fail() + test.succeed() diff --git a/test/case/meta/check-version.py b/test/case/meta/check-version.py new file mode 100755 index 00000000..1ec8570a --- /dev/null +++ b/test/case/meta/check-version.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import infamy +import os + +with infamy.Test() as test: + with test.step("Discover topology and attach to available DUTs"): + env = infamy.Env(False) + ctrl = env.ptop.get_ctrl() + duts = {} + duts_state = {} + for ix in env.ptop.get_infixen(): + cport, ixport = env.ptop.get_mgmt_link(ctrl, ix) + print(f"Attaching to {ix}:{ixport} via {ctrl}:{cport}") + duts[ix] = env.attach(ix, ixport) + + with test.step("Verify software version"): + expected=os.environ.get("VERSION") + for name, tgt in duts.items(): + running = tgt.get_data("/ietf-system:system-state") + running = running['system-state']['platform']['os-version'] + print(f"{name}: booted: {running} expected {expected}") + if running != expected: + test.fail() + test.succeed() diff --git a/test/case/meta/reproducible.py b/test/case/meta/reproducible.py index e6f68515..6e2ad565 100755 --- a/test/case/meta/reproducible.py +++ b/test/case/meta/reproducible.py @@ -13,27 +13,4 @@ with infamy.Test() as test: else: print(f"Specify PYTHONHASHSEED={seed} to reproduce this test environment") - with test.step("Discover topology and attach to available DUTs"): - env = infamy.Env(False) - ctrl = env.ptop.get_ctrl() - - duts = {} - for ix in env.ptop.get_infixen(): - cport, ixport = env.ptop.get_mgmt_link(ctrl, ix) - print(f"Attaching to {ix}:{ixport} via {ctrl}:{cport}") - duts[ix] = env.attach(ix, ixport) - - with test.step("Log running software versions"): - for name, tgt in duts.items(): - sys = tgt.get_data("/ietf-system:system-state") - sw = sys["system-state"]["software"] - plt = sys["system-state"]["platform"] - - print(f"{name}:") - for k,v in plt.items(): - print(f" {k:<16s} {v}") - - for k in ("compatible", "booted"): - print(f" {k:<16s} {sw[k]}") - test.succeed() diff --git a/test/env b/test/env index 10eed98f..b5e651a5 100755 --- a/test/env +++ b/test/env @@ -184,6 +184,7 @@ while getopts "b:cCDf:hiKp:q:rt:" opt; do kvm= ;; p) + version=$(unsquashfs -cat $OPTARG manifest.raucm | awk -F'=' '/^version=/ {print $2}') INFAMY_ARGS="$INFAMY_ARGS -p $OPTARG" ;; q) @@ -234,6 +235,7 @@ if [ "$containerize" ]; then --env NINEPM_PROJ_CONFIG="$NINEPM_PROJ_CONFIG" \ --env QENETH_PATH="$testdir/templates:$testdir" \ --env PS1="$(build_ps1)" \ + --env VERSION="$version" \ $extra_env \ --expose 9001-9010 --publish-all \ -v "$HOME/.infix/.ash_history":/root/.ash_history \ diff --git a/test/infamy/topology.py b/test/infamy/topology.py index 00f3efcf..2332945e 100644 --- a/test/infamy/topology.py +++ b/test/infamy/topology.py @@ -131,6 +131,13 @@ class Topology: return qstrip(password) if password is not None else "admin" + def get_expected_boot(self, node): + n = self.dotg.get_node(node) + b = n[0] if n else {} + boot = b.get("expected_boot") + + return _qstrip(boot) + def get_link(self, src, dst, flt=lambda _: True): es = self.g.get_edge_data(src, dst) for e in es.values(): @@ -150,7 +157,6 @@ class Topology: def get_infixen(self): return self.get_nodes(lambda _, attrs: compatible(attrs, {"requires": {"infix"}})) - def get_attr(self, name, default=None): return _qstrip(self.dotg.get_attributes().get(name, default)) diff --git a/test/test.mk b/test/test.mk index 53c3391d..0d75fb18 100644 --- a/test/test.mk +++ b/test/test.mk @@ -14,8 +14,7 @@ mode-qeneth := -q $(test-dir)/virt/quad mode-host := -t $(or $(TOPOLOGY),/etc/infamy.dot) mode-run := -t $(BINARIES_DIR)/qemu.dot mode := $(mode-$(TEST_MODE)) - -INFIX_IMAGE_ID := $(call qstrip,$(INFIX_IMAGE_ID)) +INFIX_IMAGE_ID := $(call qstrip,$(INFIX_IMAGE_ID)) binaries-$(ARCH) := $(addprefix $(INFIX_IMAGE_ID),.img -disk.qcow2) pkg-$(ARCH) := -p $(O)/images/$(addprefix $(INFIX_IMAGE_ID),.pkg) binaries-x86_64 += OVMF.fd diff --git a/test/virt/dual/topology.dot.in b/test/virt/dual/topology.dot.in index 3ce0fab1..736f818c 100644 --- a/test/virt/dual/topology.dot.in +++ b/test/virt/dual/topology.dot.in @@ -25,6 +25,7 @@ graph "dual" { label="{ e1 | e2 | e3 } | dut1 | { e4 | e5 | e6 }", pos="10,18!", provides="infix", + expected_boot="primary", qn_console=9001, qn_mem="384M", qn_usb="dut1.usb" @@ -33,6 +34,7 @@ graph "dual" { label="{ e1 | e2 | e3 } | dut2 | { e4 | e5 | e6 }", pos="10,12!", provides="infix", + expected_boot="primary", qn_console=9002, qn_mem="384M", qn_usb="dut2.usb" diff --git a/test/virt/quad/topology.dot.in b/test/virt/quad/topology.dot.in index a2b3fb10..549456d4 100644 --- a/test/virt/quad/topology.dot.in +++ b/test/virt/quad/topology.dot.in @@ -24,6 +24,7 @@ graph "quad" { label="{ e1 | e2 | e3 | e4 } | dut1 | { e5 | e6 | e7 | e8}", pos="10,30!", provides="infix", + expected_boot="primary", qn_console=9001, qn_mem="384M", qn_usb="dut1.usb" @@ -32,6 +33,7 @@ graph "quad" { label="{ e1 | e2 | e3 | e4 } | dut2 | { e5 | e6 | e7 | e8}", pos="0,20!", provides="infix", + expected_boot="primary", qn_console=9002, qn_mem="384M", qn_usb="dut2.usb" @@ -40,6 +42,7 @@ graph "quad" { label="{ e1 | e2 | e3 | e4 } | dut3 | { e5 | e6 | e7 | e8}", pos="0,10!", provides="infix", + expected_boot="primary", qn_console=9003, qn_mem="384M", qn_usb="dut3.usb" @@ -49,6 +52,7 @@ graph "quad" { label="{ e1 | e2 | e3 | e4 } | dut4 | { e5 | e6 | e7 | e8}", pos="10,0!", provides="infix", + expected_boot="primary", qn_console=9004, qn_mem="384M", qn_usb="dut4.usb"