-
Notifications
You must be signed in to change notification settings - Fork 63
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
Open
Meulengracht
wants to merge
7
commits into
canonical:main
Choose a base branch
from
Meulengracht:tests/uc-remodel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb719c0
checkbox/providers/base: add test for remodeling
Meulengracht b5256db
checkbox/providers/base/bin: apply blake formatting to remodel_test.py
Meulengracht ef333cc
checkbox/providers/base: use templates for remodel, add a test plan f…
Meulengracht b9bfba2
providers/base: improve the remodel script based on feedback, update …
Meulengracht bf47451
providers/base: fix linting in remodel_test.py
Meulengracht fe98047
providers/base/units/ubuntucore: improve how we wait for reboot, remo…
Meulengracht 5192e9d
providers: fix a linting issue, update reboot jobs
Meulengracht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2025 Canonical Ltd. | ||
# All rights reserved. | ||
# | ||
# Written by: | ||
# Authors: Philip Meulengracht <[email protected]> | ||
|
||
import argparse | ||
import os | ||
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 SystemExit(f"platform not supported for remodeling test: {plt}") | ||
|
||
|
||
# Currently images used in certifications are sourced from cdimage, | ||
# those images builds using the models supplied in canonical/models. | ||
# Make sure we use the same models that come from the same authority, | ||
# otherwise remodeling will fail. | ||
def download_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"downloading model for remodeling: {base_uri + branch + model}") | ||
path, _ = urlretrieve(base_uri + branch + model) | ||
return path | ||
|
||
|
||
# downloads a snap to the tmp folder | ||
def download_snap(name, out, channel): | ||
dir = os.getcwd() | ||
os.chdir("/tmp") | ||
subprocess.run( | ||
[ | ||
"snap", | ||
"download", | ||
name, | ||
f"--channel=latest/{channel}", | ||
f"--basename={out}", | ||
] | ||
) | ||
os.chdir(dir) | ||
|
||
|
||
def download_snaps(uc_ver): | ||
# use stable for remodel, we are not testing the snaps we are | ||
# remodeling to, but rather the process works. | ||
channel = "stable" | ||
download_snap(f"core{uc_ver}", "base", channel) | ||
if "pi" in get_platform(): | ||
download_snap("pi", "gadget", f"--channel={uc_ver}/{channel}") | ||
download_snap("pi-kernel", "kernel", f"--channel={uc_ver}/{channel}") | ||
else: | ||
download_snap("pc", "gadget", f"--channel={uc_ver}/{channel}") | ||
download_snap("pc-kernel", "kernel", f"--channel={uc_ver}/{channel}") | ||
|
||
|
||
def main(): | ||
"""Run remodel of an Ubuntu Core host.""" | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"target", | ||
help="which verison of ubuntu-core that should be remodeled to", | ||
choices=["22", "24"], | ||
) | ||
|
||
# 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 | ||
parser.add_argument( | ||
"--offline", | ||
help="whether the remodel should be offline", | ||
action="store_true", | ||
) | ||
args = parser.parse_args() | ||
|
||
# resolve the model for the current platform | ||
model_path = download_model(args.target) | ||
|
||
if args.offline: | ||
download_snaps(args.target) | ||
|
||
# instantiate the offline remodel | ||
print("initiating offline device remodel") | ||
subprocess.run( | ||
[ | ||
"sudo", | ||
"snap", | ||
"remodel", | ||
"--offline", | ||
"--snap", | ||
"/tmp/base.snap", | ||
"--assertion", | ||
"/tmp/base.assert", | ||
"--snap", | ||
"/tmp/gadget.snap", | ||
"--assertion", | ||
"/tmp/gadget.assert", | ||
"--snap", | ||
"/tmp/kernel.snap", | ||
"--assertion", | ||
"/tmp/kernel.assert", | ||
model_path, | ||
] | ||
) | ||
else: | ||
# instantiate the remodel | ||
print("initiating device remodel") | ||
subprocess.run(["sudo", "snap", "remodel", model_path]) | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meulengracht marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.