Skip to content

Commit 85a3d5d

Browse files
committed
Update upgrade test
1 parent a04ad3f commit 85a3d5d

File tree

7 files changed

+93
-35
lines changed

7 files changed

+93
-35
lines changed

test/case/ietf_system/bundles/package

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/case/ietf_system/ietf_system.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616

1717
- name: ssh_key_authentication
1818
case: ssh_key_authentication/test.py
19+
20+
- name: upgrade
21+
case: upgrade/test.py

test/case/ietf_system/upgrade/Readme.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ endif::topdoc[]
1818
. Set up topology and attach to target DUT
1919
. Start installation of selected package
2020
. Wait for upgrade to finish
21+
. Verify boot order has changed and reboot
22+
. Verify that the partition is the booted
23+
. Restore boot order to original configured
24+
. Verify the boot order is the orignal configured
2125

2226

2327
<<<

test/case/ietf_system/upgrade/test.py

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
55
Verify it is possible to upgrade.
66
"""
7+
# NOTE: THIS TEST IS HARDCODED TO NETCONF
8+
# There is a bug somewhere in the restconf-code (infamy or rousette)
79
import os
810
import time
911
import netifaces
1012
import infamy
1113
import infamy.file_server as srv
14+
from infamy.util import wait_boot, until
1215

1316
SRVPORT = 8008
1417

@@ -17,11 +20,36 @@
1720
"bundles"
1821
)
1922

23+
bootloader=None
2024
PKGPATH = os.path.join(
2125
BUNDLEDIR,
2226
"package"
2327
)
2428

29+
class Uboot:
30+
def __init__(self, ssh):
31+
self.ssh=ssh
32+
33+
def get_boot_order(self):
34+
order=self.ssh.runsh("sudo fw_printenv BOOT_ORDER").stdout.split("=")
35+
return order[1]
36+
37+
def set_boot_order(self, order):
38+
return self.ssh.run(f"sudo fw_setenv BOOT_ORDER '{order}'".split()).returncode
39+
40+
class Grub:
41+
def __init__(self, ssh):
42+
self.ssh = ssh
43+
44+
def get_boot_order(self):
45+
lines=self.ssh.runsh("grub-editenv /mnt/aux/grub/grubenv list").stdout.split("\n")
46+
for line in lines:
47+
if "ORDER" in line:
48+
return line.split("=")[1]
49+
50+
def set_boot_order(self, order):
51+
return self.ssh.run(f"sudo grub-editenv /mnt/aux/grub/grubenv set ORDER='{order}'".split()).returncode
52+
2553
with infamy.Test() as test:
2654
with test.step("Set up topology and attach to target DUT"):
2755
env = infamy.Env()
@@ -33,17 +61,31 @@
3361
os.unlink(PKGPATH)
3462
except FileNotFoundError:
3563
pass
64+
#os.unlink(PKGPATH)
3665
os.symlink(os.path.abspath(env.args.package), PKGPATH)
3766

38-
target = env.attach("target", "mgmt")
67+
target = env.attach("target", "mgmt", "netconf")
68+
target_ssh = env.attach("target", "mgmt", "ssh")
69+
if target_ssh.run("test -e /sys/firmware/devicetree/base/chosen/u-boot,version".split()).returncode == 0:
70+
bootloader=Uboot(target_ssh)
71+
elif target_ssh.run("test -e /mnt/aux/grub/grubenv".split()).returncode == 0:
72+
bootloader=Grub(target_ssh)
73+
else:
74+
print("No supported bootloader found")
75+
test.skip()
76+
77+
old_bootorder=bootloader.get_boot_order()
78+
print(f"Initial bootorder: {repr(old_bootorder)}")
3979

40-
_, hport = env.ltop.xlate("host", "mgmt")
41-
_, tport = env.ltop.xlate("target", "mgmt")
80+
_, hport = env.ltop.xlate("host", "data")
81+
_, tport = env.ltop.xlate("target", "data")
4282
hip = netifaces.ifaddresses(hport)[netifaces.AF_INET6][0]["addr"]
4383
hip = hip.replace(f"%{hport}", f"%{tport}")
4484

45-
with srv.FileServer(("::", SRVPORT), BUNDLEDIR):
85+
netns = infamy.IsolatedMacVlan(hport).start()
86+
netns.run("ip link set dev iface up".split(), check=True)
4687

88+
with srv.FileServer(netns, ("[::]", SRVPORT), BUNDLEDIR):
4789
with test.step("Start installation of selected package"):
4890
print(f"Installing {os.path.basename(env.args.package)}")
4991
target.call_dict("infix-system", {
@@ -61,9 +103,40 @@
61103
print("Install failed:", installer["last-error"])
62104
test.fail()
63105

64-
test.succeed()
65-
106+
break
66107
time.sleep(1)
108+
else:
109+
print("Timeout, last state:", oper)
110+
test.fail()
111+
112+
with test.step("Verify boot order has changed and reboot"):
113+
assert(old_bootorder != bootloader.get_boot_order())
114+
target.reboot()
115+
116+
if not wait_boot(target, env):
117+
test.fail()
118+
target = env.attach("target", "mgmt", "netconf")
119+
120+
121+
with test.step("Verify that the partition is the booted"):
122+
should_boot=bootloader.get_boot_order().split()[0]
123+
oper = target.get_dict("/system-state/software")
124+
booted = oper["system-state"]["software"]["booted"]
125+
print(f"Should boot: {should_boot}, booted: {booted}")
126+
assert(booted == should_boot)
127+
128+
with test.step("Restore boot order to original configured"):
129+
print(f"Restore boot order to {old_bootorder}")
130+
if bootloader.set_boot_order(old_bootorder) != 0:
131+
test.fail()
132+
target = env.attach("target", "mgmt", "netconf")
133+
target.reboot()
134+
if not wait_boot(target, env):
135+
test.fail()
136+
target = env.attach("target", "mgmt", "netconf")
137+
138+
with test.step("Verify the boot order is the orignal configured"):
139+
order = bootloader.get_boot_order()
140+
assert order == old_bootorder, f"Unexpected bootorder: {repr(order)}"
67141

68-
print("Timeout, last state:", oper)
69-
test.fail()
142+
test.succeed()

test/case/ietf_system/upgrade/topology.dot

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../infamy/topologies/1x2.dot

test/test.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ mode-run := -t $(BINARIES_DIR)/qemu.dot
2222
mode := $(mode-$(TEST_MODE))
2323

2424
INFIX_IMAGE_ID := $(call qstrip,$(INFIX_IMAGE_ID))
25-
binaries-$(ARCH) := $(addprefix $(INFIX_IMAGE_ID),.img -disk.img .pkg)
25+
binaries-$(ARCH) := $(addprefix $(INFIX_IMAGE_ID),.img -disk.img)
26+
pkg-$(ARCH) := -p $(O)/images/$(addprefix $(INFIX_IMAGE_ID),.pkg)
2627
binaries-x86_64 += OVMF.fd
2728
binaries := $(foreach bin,$(binaries-$(ARCH)),-f $(BINARIES_DIR)/$(bin))
2829

@@ -32,10 +33,10 @@ export INFAMY_ARGS := --transport=netconf
3233
endif
3334

3435
test:
35-
$(test-dir)/env -r $(base) $(mode) $(binaries) $(ninepm) $(TESTS)
36+
$(test-dir)/env -r $(base) $(mode) $(binaries) $(pkg-$(ARCH)) $(ninepm) $(TESTS)
3637

3738
test-sh:
38-
$(test-dir)/env $(base) $(mode) $(binaries) -i /bin/sh
39+
$(test-dir)/env $(base) $(mode) $(binaries) $(pkg-$(ARCH)) -i /bin/sh
3940

4041
test-spec:
4142
@esc_infix_name="$(echo $(INFIX_NAME) | sed 's/\//\\\//g')"; \

0 commit comments

Comments
 (0)