|
4 | 4 |
|
5 | 5 | Verify it is possible to upgrade.
|
6 | 6 | """
|
| 7 | +# NOTE: THIS TEST IS HARDCODED TO NETCONF |
| 8 | +# There is a bug somewhere in the restconf-code (infamy or rousette) |
7 | 9 | import os
|
8 | 10 | import time
|
9 | 11 | import netifaces
|
10 | 12 | import infamy
|
11 | 13 | import infamy.file_server as srv
|
| 14 | +from infamy.util import wait_boot, until |
12 | 15 |
|
13 | 16 | SRVPORT = 8008
|
14 | 17 |
|
|
17 | 20 | "bundles"
|
18 | 21 | )
|
19 | 22 |
|
| 23 | +bootloader=None |
20 | 24 | PKGPATH = os.path.join(
|
21 | 25 | BUNDLEDIR,
|
22 | 26 | "package"
|
23 | 27 | )
|
24 | 28 |
|
| 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 | + |
25 | 53 | with infamy.Test() as test:
|
26 | 54 | with test.step("Set up topology and attach to target DUT"):
|
27 | 55 | env = infamy.Env()
|
|
33 | 61 | os.unlink(PKGPATH)
|
34 | 62 | except FileNotFoundError:
|
35 | 63 | pass
|
| 64 | + #os.unlink(PKGPATH) |
36 | 65 | os.symlink(os.path.abspath(env.args.package), PKGPATH)
|
37 | 66 |
|
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() |
39 | 78 |
|
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") |
42 | 81 | hip = netifaces.ifaddresses(hport)[netifaces.AF_INET6][0]["addr"]
|
43 | 82 | hip = hip.replace(f"%{hport}", f"%{tport}")
|
44 | 83 |
|
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): |
47 | 90 | with test.step("Start installation of selected package"):
|
48 | 91 | print(f"Installing {os.path.basename(env.args.package)}")
|
49 | 92 | target.call_dict("infix-system", {
|
|
53 | 96 | })
|
54 | 97 |
|
55 | 98 | with test.step("Wait for upgrade to finish"):
|
56 |
| - for _ in range(600): |
| 99 | + for left in range(600): |
57 | 100 | oper = target.get_dict("/system-state/software")
|
58 | 101 | installer = oper["system-state"]["software"]["installer"]
|
59 | 102 | if installer["operation"] == "idle":
|
60 | 103 | if "last-error" in installer:
|
61 | 104 | print("Install failed:", installer["last-error"])
|
62 | 105 | test.fail()
|
63 | 106 |
|
64 |
| - test.succeed() |
65 |
| - |
| 107 | + break |
| 108 | + time.sleep(1) |
| 109 | + if left >= 600: |
| 110 | + print("Timeout, last state:", oper) |
| 111 | + test.fail() |
66 | 112 | time.sleep(1)
|
67 | 113 |
|
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() |
0 commit comments