-
Notifications
You must be signed in to change notification settings - Fork 594
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
o/snapstate, o/devicestate: remodel with components from the store #14933
Merged
alfonsosanchezbeato
merged 2 commits into
canonical:master
from
andrewphelpsj:remodel-components-from-store
Feb 4, 2025
Merged
Changes from all commits
Commits
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
39 changes: 39 additions & 0 deletions
39
tests/lib/assertions/test-snapd-component-remodel-initial-pc-24.json
This file contains 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,39 @@ | ||
{ | ||
"type": "model", | ||
"authority-id": "developer1", | ||
"series": "16", | ||
"brand-id": "developer1", | ||
"model": "my-model", | ||
"revision": "1", | ||
"architecture": "amd64", | ||
"timestamp": "2024-04-24T00:00:00+00:00", | ||
"grade": "dangerous", | ||
"base": "core24", | ||
"serial-authority": ["generic"], | ||
"snaps": [ | ||
{ | ||
"default-channel": "24/edge", | ||
"id": "UqFziVZDHLSyO3TqSWgNBoAdHbLI4dAH", | ||
"name": "pc", | ||
"type": "gadget" | ||
}, | ||
{ | ||
"default-channel": "24/edge", | ||
"id": "pYVQrBcKmBa0mZ4CCN7ExT6jH8rY1hza", | ||
"name": "pc-kernel", | ||
"type": "kernel" | ||
}, | ||
{ | ||
"default-channel": "latest/edge", | ||
"id": "dwTAh7MZZ01zyriOZErqd1JynQLiOGvM", | ||
"name": "core24", | ||
"type": "base" | ||
}, | ||
{ | ||
"default-channel": "latest/edge", | ||
"id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4", | ||
"name": "snapd", | ||
"type": "snapd" | ||
} | ||
] | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/lib/assertions/test-snapd-component-remodel-new-pc-24.json
This file contains 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,42 @@ | ||
{ | ||
"type": "model", | ||
"authority-id": "developer1", | ||
"series": "16", | ||
"brand-id": "developer1", | ||
"model": "my-model", | ||
"revision": "2", | ||
"architecture": "amd64", | ||
"timestamp": "2024-04-24T00:00:00+00:00", | ||
"grade": "dangerous", | ||
"base": "core24", | ||
"serial-authority": ["generic"], | ||
"snaps": [ | ||
{ | ||
"default-channel": "24/edge", | ||
"id": "UqFziVZDHLSyO3TqSWgNBoAdHbLI4dAH", | ||
"name": "pc", | ||
"type": "gadget" | ||
}, | ||
{ | ||
"default-channel": "24/edge", | ||
"id": "pYVQrBcKmBa0mZ4CCN7ExT6jH8rY1hza", | ||
"name": "pc-kernel", | ||
"type": "kernel", | ||
"components": { | ||
"wifi-comp": "required" | ||
} | ||
}, | ||
{ | ||
"default-channel": "latest/edge", | ||
"id": "dwTAh7MZZ01zyriOZErqd1JynQLiOGvM", | ||
"name": "core24", | ||
"type": "base" | ||
}, | ||
{ | ||
"default-channel": "latest/edge", | ||
"id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4", | ||
"name": "snapd", | ||
"type": "snapd" | ||
} | ||
] | ||
} |
This file contains 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,131 @@ | ||
summary: remodel to a model that contains components | ||
|
||
details: | | ||
This test remodels to a model that contains components. Specifically, this | ||
tests updating the kernel snap to a version that supports the newly required | ||
component and installing that component. | ||
|
||
validates that the newly created system can be rebooted into. | ||
|
||
systems: [-ubuntu-1*, -ubuntu-20*, -ubuntu-22*] | ||
|
||
environment: | ||
INITIAL_MODEL_JSON: $TESTSLIB/assertions/test-snapd-component-remodel-initial-pc-24.json | ||
NEW_MODEL_JSON: $TESTSLIB/assertions/test-snapd-component-remodel-new-pc-24.json | ||
NESTED_ENABLE_TPM: true | ||
NESTED_ENABLE_SECURE_BOOT: true | ||
NESTED_BUILD_SNAPD_FROM_CURRENT: true | ||
NESTED_REPACK_GADGET_SNAP: true | ||
NESTED_REPACK_KERNEL_SNAP: true | ||
NESTED_REPACK_BASE_SNAP: true | ||
NESTED_REPACK_FOR_FAKESTORE: true | ||
NESTED_FAKESTORE_BLOB_DIR: $(pwd)/fake-store-blobdir | ||
NESTED_SIGN_SNAPS_FAKESTORE: true | ||
NESTED_UBUNTU_IMAGE_SNAPPY_FORCE_SAS_URL: http://localhost:11028 | ||
|
||
prepare: | | ||
if [ "${TRUST_TEST_KEYS}" = "false" ]; then | ||
echo "This test needs test keys to be trusted" | ||
exit | ||
fi | ||
|
||
# although nested_start_core_vm_unit usually installs this, the fake store | ||
# will already have been set up, so we need to install it here | ||
snap install test-snapd-swtpm --edge | ||
|
||
"${TESTSTOOLS}/store-state" setup-fake-store "${NESTED_FAKESTORE_BLOB_DIR}" | ||
|
||
gendeveloper1 sign-model < "${INITIAL_MODEL_JSON}" > initial-model.assert | ||
|
||
cp "${TESTSLIB}/assertions/testrootorg-store.account-key" "${NESTED_FAKESTORE_BLOB_DIR}/asserts" | ||
cp "${TESTSLIB}/assertions/developer1.account" "${NESTED_FAKESTORE_BLOB_DIR}/asserts" | ||
cp "${TESTSLIB}/assertions/developer1.account-key" "${NESTED_FAKESTORE_BLOB_DIR}/asserts" | ||
cp initial-model.assert "${NESTED_FAKESTORE_BLOB_DIR}/asserts" | ||
|
||
tests.nested prepare-essential-snaps | ||
|
||
export SNAPPY_FORCE_API_URL="${NESTED_UBUNTU_IMAGE_SNAPPY_FORCE_SAS_URL}" | ||
ubuntu-image snap --image-size 10G ./initial-model.assert | ||
|
||
image_dir=$(tests.nested get images-path) | ||
image_name=$(tests.nested get image-name core) | ||
cp ./pc.img "${image_dir}/${image_name}" | ||
tests.nested configure-default-user | ||
|
||
# run the fake device service too, so that the device can be initialised | ||
systemd-run --collect --unit fakedevicesvc fakedevicesvc localhost:11029 | ||
|
||
tests.nested build-image core | ||
tests.nested create-vm core | ||
|
||
#shellcheck source=tests/lib/core-config.sh | ||
. "$TESTSLIB"/core-config.sh | ||
wait_for_first_boot_change | ||
|
||
remote.exec 'sudo systemctl stop snapd snapd.socket' | ||
|
||
remote.exec 'sudo cat /var/lib/snapd/state.json' | gojq '.data.auth.device."session-macaroon"="fake-session"' > state.json | ||
remote.push state.json | ||
remote.exec 'sudo mv state.json /var/lib/snapd/state.json' | ||
remote.exec 'sudo systemctl start snapd snapd.socket' | ||
|
||
restore: | | ||
systemctl stop fakedevicesvc | ||
"${TESTSTOOLS}/store-state" teardown-fake-store "${NESTED_FAKESTORE_BLOB_DIR}" | ||
|
||
execute: | | ||
function post_json_data() { | ||
route=$1 | ||
template=$2 | ||
shift 2 | ||
|
||
# shellcheck disable=SC2059 | ||
response=$(printf "${template}" "$@" | remote.exec "sudo snap debug api -X POST -H 'Content-Type: application/json' ${route}") | ||
if ! gojq -e .change <<< "${response}"; then | ||
echo "could not get change id from response: ${response}" | ||
false | ||
fi | ||
} | ||
|
||
unsquashfs "${NESTED_FAKESTORE_BLOB_DIR}/pc-kernel.snap" | ||
sed -i -e '/^version/ s/$/-with-comps/' squashfs-root/meta/snap.yaml | ||
snap pack --filename=pc-kernel-with-comps.snap ./squashfs-root | ||
"${TESTSTOOLS}"/build_kernel_with_comps.sh mac80211_hwsim wifi-comp pc-kernel-with-comps.snap | ||
|
||
kernel_id='pYVQrBcKmBa0mZ4CCN7ExT6jH8rY1hza' | ||
|
||
# bump the available kernel version in the fake store | ||
"${TESTSTOOLS}"/store-state make-snap-installable --noack \ | ||
--revision 2 \ | ||
"${NESTED_FAKESTORE_BLOB_DIR}" \ | ||
./pc-kernel-with-comps.snap \ | ||
"${kernel_id}" | ||
|
||
"${TESTSTOOLS}"/store-state make-component-installable --noack \ | ||
--snap-revision 2 \ | ||
--component-revision 1 \ | ||
--snap-id "${kernel_id}" \ | ||
"${NESTED_FAKESTORE_BLOB_DIR}" \ | ||
./pc-kernel+wifi-comp.comp | ||
|
||
gendeveloper1 sign-model < "${NEW_MODEL_JSON}" > new-model.assert | ||
remote.push new-model.assert | ||
|
||
boot_id="$(tests.nested boot-id)" | ||
change_id="$(remote.exec 'sudo snap remodel --no-wait new-model.assert')" | ||
remote.wait-for reboot "${boot_id}" | ||
|
||
# this remodel expects two reboots, once for testing the recovery system | ||
# and once for rebooting into the new kernel | ||
boot_id="$(tests.nested boot-id)" | ||
remote.wait-for reboot "${boot_id}" | ||
|
||
remote.exec "snap watch ${change_id}" | ||
remote.exec 'snap list pc-kernel' | awk '$NR != 1 { print $3 }' | MATCH '2' | ||
remote.exec 'snap components pc-kernel' | sed 1d | MATCH 'pc-kernel\+wifi-comp\s+installed' | ||
|
||
# make sure that the kernel module got installed and is loaded from our | ||
# component | ||
remote.exec sudo modprobe mac80211_hwsim | ||
remote.exec ip link show wlan0 | ||
remote.exec modinfo --filename mac80211_hwsim | MATCH '/lib/modules/.*/updates/wifi-comp' |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this installed by
nested_start_core_vm_unit()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, but it won't work there since we've already set up the fake store at that point. I'll add a comment.