Skip to content

Add remodel tests for Ubuntu Core 20 => 22 and 22 => 24 (New) #1858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions providers/base/bin/remodel_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env python3
# Copyright 2025 Canonical Ltd.
# All rights reserved.
#
# Written by:
# Authors: Philip Meulengracht <[email protected]>

import os
import sys
import platform
import subprocess
from urllib.request import urlretrieve


def get_platform():
plt = platform.platform()
if "raspi-aarch64" in plt:
return "pi-arm64"
elif "raspi" in plt:
return "pi-armhf"
elif "x86_64" in plt:
return "amd64"
raise Exception(f"unrecognized platform {plt}")


def resolve_target_remodel():
runtime = os.getenv("CHECKBOX_RUNTIME", "/snap/checkbox/current")
if "checkbox20" in runtime:
return "uc22"
elif "checkbox22" in runtime:
return "uc24"
raise Exception(f"unsupported version for remodel: {runtime}")


def resolve_model(uc_ver):
base_uri = "https://raw.githubusercontent.com/canonical/models/"
branch = "refs/heads/master/"
model = f"ubuntu-core-{uc_ver}-{get_platform()}-dangerous.model"
print(f"resolving model for remodeling: {base_uri + branch + model}")
path, _ = urlretrieve(base_uri + branch + model, f"uc-{uc_ver}.model")
return path


def resolve_snaps(uc_ver):
subprocess.run(
["snap", "download", f"core{uc_ver}", f"--basename=core{uc_ver}"]
)
# for the kernel snap use beta
if "pi" in get_platform():
subprocess.run(
[
"snap",
"download",
"pi",
f"--channel={uc_ver}/edge",
"--basename=gadget",
]
)
subprocess.run(
[
"snap",
"download",
"pi-kernel",
f"--channel={uc_ver}/beta",
"--basename=kernel",
]
)
else:
subprocess.run(
[
"snap",
"download",
"pc",
f"--channel={uc_ver}/edge",
"--basename=gadget",
]
)
subprocess.run(
[
"snap",
"download",
"pc-kernel",
f"--channel={uc_ver}/beta",
"--basename=kernel",
]
)


def main():
"""Run remodel of an Ubuntu Core host."""

uc_ver = ""
if len(sys.argv) > 1:
uc_ver = sys.argv[1]
else:
uc_ver = resolve_target_remodel()

# resolve the model for the current platform
model_path = resolve_model(uc_ver)

# resolve the snaps for the remodel if offline has been requested
# (currently offline was used for testing in certain scenarios during
# test development) - for normal testing offline should not be needed
offline = False
if len(sys.argv) > 2 and sys.argv[2] == "offline":
offline = True

if offline:
resolve_snaps(uc_ver)

# instantiate the offline remodel
print("initiating offline device remodel")
subprocess.run(
[
"sudo",
"snap",
"remodel",
"--offline",
"--snap",
f"core{uc_ver}.snap",
"--assertion",
f"core{uc_ver}.assert",
"--snap",
"gadget.snap",
"--assertion",
"gadget.assert",
"--snap",
"kernel.snap",
"--assertion",
"kernel.assert",
model_path,
]
)
else:
# instantiate the remodel
print("initiating device remodel")
subprocess.run(["sudo", "snap", "remodel", model_path])


if __name__ == "__main__":
exit(main())
36 changes: 36 additions & 0 deletions providers/base/units/ubuntucore/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,42 @@ _verification:
plugin: manual
category_id: ubuntucore

id: ubuntucore/remodel-20-to-22
category_id: ubuntucore
_summary: Remodel Ubuntu Core 20 to 22
_purpose:
Verify the system can remodel from ubuntu core 22 to 24 under normal
circumstances. The requirement is that the official models from canonical
are used for the running Ubuntu Core host. Multiple reboots will happen
as a part of this test.
unit: job
plugin: shell
user: root
flags: noreturn
estimated_duration: 180.0
command:
snap model | grep "ubuntu-core-20"
remodel_test.py 22
reboot

id: ubuntucore/remodel-22-to-24
category_id: ubuntucore
_summary: Remodel Ubuntu Core 22 to 24
_purpose:
Verify the system can remodel from ubuntu core 22 to 24 under normal
circumstances. The requirement is that the official models from canonical
are used for the running Ubuntu Core host. Multiple reboots will happen
as a part of this test.
unit: job
plugin: shell
user: root
flags: noreturn
estimated_duration: 180.0
command:
snap model | grep "ubuntu-core-22"
remodel_test.py 24
reboot

unit: template
template-resource: lsb
template-filter: lsb.distributor_id == 'Ubuntu Core'
Expand Down
Loading