Skip to content

Commit

Permalink
test: Refactor upgrade test
Browse files Browse the repository at this point in the history
* Use new cleanup in infamy to ensure the boot order gets restored
* Use new boot order in operational and use RPC to set boot order
  to remove all SSH commands.
  • Loading branch information
mattiaswal committed Dec 19, 2024
1 parent ffa8a0a commit 092c82d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 63 deletions.
2 changes: 0 additions & 2 deletions test/case/ietf_system/upgrade/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ endif::topdoc[]
. Wait for upgrade to finish
. Verify boot order has changed and reboot
. Verify that the partition is the booted
. Restore boot order to original configured
. Verify the boot order is the orignal configured


<<<
Expand Down
74 changes: 28 additions & 46 deletions test/case/ietf_system/upgrade/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,31 @@
BUNDLEDIR,
"package"
)
def get_boot_order(target):
oper = target.get_dict("/system-state/software")
return " ".join(oper["system-state"]["software"]["boot-order"])

def set_boot_order(target, order):
target.call_dict("infix-system", {
"set-boot-order": {
"boot-order": order.split(" ")
}
})

class Uboot:
def __init__(self, ssh):
self.ssh=ssh

def get_boot_order(self):
order=self.ssh.runsh("sudo fw_printenv BOOT_ORDER").stdout.split("=")
return order[1].strip()

def set_boot_order(self, order):
return self.ssh.run(f"sudo fw_setenv BOOT_ORDER '{order}'".split()).returncode

class Grub:
def __init__(self, ssh):
self.ssh = ssh

def get_boot_order(self):
lines=self.ssh.runsh("grub-editenv /mnt/aux/grub/grubenv list").stdout.split("\n")
for line in lines:
if "ORDER" in line:
return line.split("=")[1].strip()
def cleanup(env, target, port, old_bootorder):
target = env.attach(target, port)
print(f"Restore boot order to {old_bootorder}")
target = env.attach("target", "mgmt", "netconf")
set_boot_order(target, old_bootorder)
target.reboot()
if not wait_boot(target, env):
test.fail()
target = env.attach("target", "mgmt", "netconf")

def set_boot_order(self, order):
return self.ssh.run(f"sudo grub-editenv /mnt/aux/grub/grubenv set ORDER='{order}'".split()).returncode
print("Verify the boot order is the orignal configured")
order = get_boot_order(target)
assert order == old_bootorder, f"Unexpected bootorder: {repr(order)}"

with infamy.Test() as test:
with test.step("Set up topology and attach to target DUT"):
Expand All @@ -65,20 +66,13 @@ def set_boot_order(self, order):
os.symlink(os.path.abspath(env.args.package), PKGPATH)

target = env.attach("target", "mgmt", "netconf")
target_ssh = env.attach("target", "mgmt", "ssh")
if target_ssh.run("test -e /sys/firmware/devicetree/base/chosen/u-boot,version".split()).returncode == 0:
bootloader=Uboot(target_ssh)
elif target_ssh.run("test -e /mnt/aux/grub/grubenv".split()).returncode == 0:
bootloader=Grub(target_ssh)
else:
print("No supported bootloader found")
test.skip()

old_bootorder=bootloader.get_boot_order()
old_bootorder=get_boot_order(target)
print(f"Initial bootorder: {repr(old_bootorder)}")

_, hport = env.ltop.xlate("host", "data")
_, tport = env.ltop.xlate("target", "data")
test.set_test_cleanup(lambda: cleanup(env, "target", "mgmt", old_bootorder))

netns = infamy.IsolatedMacVlan(hport).start()
netns.addip("192.168.0.1")
Expand Down Expand Up @@ -130,7 +124,9 @@ def set_boot_order(self, order):
test.fail()

with test.step("Verify boot order has changed and reboot"):
assert(old_bootorder != bootloader.get_boot_order())
print(get_boot_order(target))
print(old_bootorder)
assert(old_bootorder != get_boot_order(target))
target.reboot()

if not wait_boot(target, env):
Expand All @@ -139,24 +135,10 @@ def set_boot_order(self, order):


with test.step("Verify that the partition is the booted"):
should_boot=bootloader.get_boot_order().split()[0]
should_boot=get_boot_order(target).split()[0]
oper = target.get_dict("/system-state/software")
booted = oper["system-state"]["software"]["booted"]
print(f"Should boot: {should_boot}, booted: {booted}")
assert(booted == should_boot)

with test.step("Restore boot order to original configured"):
print(f"Restore boot order to {old_bootorder}")
if bootloader.set_boot_order(old_bootorder) != 0:
test.fail()
target = env.attach("target", "mgmt", "netconf")
target.reboot()
if not wait_boot(target, env):
test.fail()
target = env.attach("target", "mgmt", "netconf")

with test.step("Verify the boot order is the orignal configured"):
order = bootloader.get_boot_order()
assert order == old_bootorder, f"Unexpected bootorder: {repr(order)}"

test.succeed()
39 changes: 24 additions & 15 deletions test/case/ietf_system/upgrade/topology.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/infamy/restconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def put_config_dict(self, modname, edit):

return self.put_datastore("running", data)

def call_dict(self, model, call):
pass # Need implementation

def call_rpc(self, rpc):
"""Actually send a POST to RESTCONF server"""
url = f"{self.rpc_url}/{rpc}"
Expand Down
4 changes: 4 additions & 0 deletions test/infamy/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def get_current_time_with_offset(self):
"""Needed since libyang is too nice and removes the original offset"""
pass

@abstractmethod
def call_dict(self, module, call):
pass

@abstractmethod
def call_action(self, xpath):
pass
Expand Down

0 comments on commit 092c82d

Please sign in to comment.