|
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() |
| 78 | + print(f"Initial bootorder: {repr(old_bootorder)}") |
39 | 79 |
|
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") |
42 | 82 | hip = netifaces.ifaddresses(hport)[netifaces.AF_INET6][0]["addr"]
|
43 | 83 | hip = hip.replace(f"%{hport}", f"%{tport}")
|
44 | 84 |
|
45 |
| - with srv.FileServer(("::", SRVPORT), BUNDLEDIR): |
| 85 | + netns = infamy.IsolatedMacVlan(hport).start() |
| 86 | + netns.run("ip link set dev iface up".split(), check=True) |
46 | 87 |
|
| 88 | + with srv.FileServer(netns, ("[::]", SRVPORT), BUNDLEDIR): |
47 | 89 | with test.step("Start installation of selected package"):
|
48 | 90 | print(f"Installing {os.path.basename(env.args.package)}")
|
49 | 91 | target.call_dict("infix-system", {
|
|
61 | 103 | print("Install failed:", installer["last-error"])
|
62 | 104 | test.fail()
|
63 | 105 |
|
64 |
| - test.succeed() |
65 |
| - |
| 106 | + break |
66 | 107 | 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)}" |
67 | 141 |
|
68 |
| - print("Timeout, last state:", oper) |
69 |
| - test.fail() |
| 142 | + test.succeed() |
0 commit comments