Skip to content

Commit d81a2c2

Browse files
committed
Update upgrade test
1 parent a04ad3f commit d81a2c2

File tree

7 files changed

+97
-37
lines changed

7 files changed

+97
-37
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: 85 additions & 10 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,32 @@
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()
3978

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

45-
with srv.FileServer(("::", SRVPORT), BUNDLEDIR):
46-
84+
netns = infamy.IsolatedMacVlan(hport).start()
85+
netns.runsh("""
86+
set -ex
87+
ip link set dev iface up
88+
""", check=True)
89+
with srv.FileServer(netns, ("[::]", SRVPORT), BUNDLEDIR):
4790
with test.step("Start installation of selected package"):
4891
print(f"Installing {os.path.basename(env.args.package)}")
4992
target.call_dict("infix-system", {
@@ -53,17 +96,49 @@
5396
})
5497

5598
with test.step("Wait for upgrade to finish"):
56-
for _ in range(600):
99+
for left in range(600):
57100
oper = target.get_dict("/system-state/software")
58101
installer = oper["system-state"]["software"]["installer"]
59102
if installer["operation"] == "idle":
60103
if "last-error" in installer:
61104
print("Install failed:", installer["last-error"])
62105
test.fail()
63106

64-
test.succeed()
65-
107+
break
108+
time.sleep(1)
109+
if left >= 600:
110+
print("Timeout, last state:", oper)
111+
test.fail()
66112
time.sleep(1)
67113

68-
print("Timeout, last state:", oper)
69-
test.fail()
114+
with test.step("Verify boot order has changed and reboot"):
115+
assert(old_bootorder != bootloader.get_boot_order())
116+
target.reboot()
117+
118+
if not wait_boot(target, env):
119+
test.fail()
120+
target = env.attach("target", "mgmt", "netconf")
121+
122+
123+
with test.step("Verify that the partition is the booted"):
124+
should_boot=bootloader.get_boot_order().split()[0]
125+
oper = target.get_dict("/system-state/software")
126+
booted = oper["system-state"]["software"]["booted"]
127+
print(f"Should boot: {should_boot}, booted: {booted}")
128+
assert(booted == should_boot)
129+
130+
with test.step("Restore boot order to original configured"):
131+
print(f"Restore boot order to {old_bootorder}")
132+
if bootloader.set_boot_order(old_bootorder) != 0:
133+
test.fail()
134+
target = env.attach("target", "mgmt", "netconf")
135+
target.reboot()
136+
if not wait_boot(target, env):
137+
test.fail()
138+
target = env.attach("target", "mgmt", "netconf")
139+
140+
with test.step("Verify the boot order is the orignal configured"):
141+
# Wait for sshd to start.
142+
until(lambda: old_bootorder == bootloader.get_boot_order(), attempts=200)
143+
144+
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)