1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
summary: Verify that we are able to use validation sets with the model assertion through prepare-image
details: |
The `snap prepare-image` command performs some of the steps necessary for
creating device images.
This test verifies that in classic and Ubuntu Core systems, the prepare-image
command prepares properly an ubuntu-core 20 image using a model with
validation sets in enforce mode.
It is checked that the generated seed.manifest is created in working directory
and the expected revisions for the fundamental snaps are retrieved. Also it
is verified that snaps in the validation set are retrieved and the revisions
are correct.
# autopkgtest run only a subset of tests that deals with the integration
# with the distro
backends: [-autopkgtest]
# disable the following distributions
# ubuntu-14, lack of systemd-run
# ubuntu-20.04-arm*, because we use pc kernel and gadget.
systems:
- -ubuntu-14.04-*
# The test downloads pc from track 20, which is not available for arm
# TODO run the test also for a UC22 model
- -ubuntu-*-arm-*
environment:
ROOT: /home/test/tmp/
IMAGE: $ROOT/system-seed
GADGET: $ROOT/gadget
STORE_DIR: $(pwd)/fake-store-blobdir
STORE_ADDR: localhost:11028
prepare: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
mkdir -p "$ROOT"
chown test:test "$ROOT"
restore: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
"$TESTSTOOLS"/store-state teardown-fake-store "$STORE_DIR"
rm -rf "$ROOT"
execute: |
if [ "$TRUST_TEST_KEYS" = "false" ]; then
echo "This test needs test keys to be trusted"
exit
fi
install_snap_to_fakestore() {
local SNAP_NAME="$1"
local SNAP_REVISION="$2"
local SNAP_PATH
cat > snap-"$SNAP_NAME"-decl.json <<EOF
{
"plugs": {
"snapd-control": {
"allow-installation": "true",
"allow-auto-connection": "true"
}
}
}
EOF
cat > snap-"$SNAP_NAME"-rev.json <<EOF
{
"type": "snap-revision",
"snap-id": "$SNAP_NAME-id",
"snap-revision": "$SNAP_REVISION"
}
EOF
SNAP_PATH=$("$TESTSTOOLS"/snaps-state pack-local "$SNAP_NAME")
"$TESTSTOOLS"/store-state make-snap-installable --extra-decl-json snap-"$SNAP_NAME"-decl.json "$STORE_DIR" "$SNAP_PATH"
fakestore new-snap-revision --dir "${STORE_DIR}" "$SNAP_PATH" --snap-rev-json snap-"$SNAP_NAME"-rev.json
}
echo Download snaps needed for the the model
snap download core
snap download pc --channel=20/stable
snap download pc-kernel --channel=20/stable
snap download core20
snap download snapd
"$TESTSTOOLS"/store-state setup-fake-store "$STORE_DIR"
# Sign the needed assertions for validation sets and model
gendeveloper1 sign-model < ./asserts/vs1.json > foo.assert
gendeveloper1 sign-model < ./asserts/vs2.json > bar.assert
gendeveloper1 sign-model < ./asserts/core-20.json > model.assert
echo Expose the needed assertions through the fakestore
cp "$TESTSLIB"/assertions/testrootorg-store.account-key "$STORE_DIR/asserts"
cp "$TESTSLIB"/assertions/developer1.account "$STORE_DIR/asserts"
cp "$TESTSLIB"/assertions/developer1.account-key "$STORE_DIR/asserts"
cp foo.assert "$STORE_DIR/asserts"
cp bar.assert "$STORE_DIR/asserts"
# It is not enough to copy the assertions, we must also ack them otherwise we
# will get an error about not being able to resolve the account key
snap ack "$STORE_DIR/asserts/testrootorg-store.account-key"
snap ack "$STORE_DIR/asserts/developer1.account"
snap ack "$STORE_DIR/asserts/developer1.account-key"
# We now add all the required snaps to the fake store. It hardly matter which revision
# we give to them, as the fake store does not handle requests of specific revisions. Currently
# the fake-store will just return whatever revision there is.
echo "Adding snaps to the fake store"
"$TESTSTOOLS"/store-state make-snap-installable "$STORE_DIR" "$(ls core_*.snap)" 99T7MUlRhtI3U0QFgl5mXXESAiSwt776
"$TESTSTOOLS"/store-state make-snap-installable "$STORE_DIR" "$(ls pc_*.snap)" UqFziVZDHLSyO3TqSWgNBoAdHbLI4dAH
"$TESTSTOOLS"/store-state make-snap-installable "$STORE_DIR" "$(ls pc-kernel_*.snap)" pYVQrBcKmBa0mZ4CCN7ExT6jH8rY1hza
"$TESTSTOOLS"/store-state make-snap-installable "$STORE_DIR" "$(ls core20_*.snap)" DLqre5XGLbDqg9jPtiAhRRjDuPVa5X1q
"$TESTSTOOLS"/store-state make-snap-installable "$STORE_DIR" "$(ls snapd_*.snap)" PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4
install_snap_to_fakestore test-snapd-sh 13
# Use the fake-store to verify behavior, so we can use our own assertions
export SNAPPY_FORCE_API_URL=http://"$STORE_ADDR"
echo Running prepare-image
snap prepare-image --channel edge --write-revisions --snap core --snap test-snapd-sh ./model.assert "$ROOT"
# The generated seed.manifest will be in working directory.
echo Verifying the generated manifest has correct contents
MATCH "developer1/bar\s1+$" < seed.manifest
MATCH "developer1/foo\s1+$" < seed.manifest
MATCH "core\s1+$" < seed.manifest
MATCH "core20\s1+$" < seed.manifest
MATCH "snapd\s1+$" < seed.manifest
echo Verifying the expected revisions were retrieved
test -e "$IMAGE/snaps/core20_1.snap"
test -e "$IMAGE/snaps/pc_1.snap"
test -e "$IMAGE/snaps/pc-kernel_1.snap"
test -e "$IMAGE/snaps/snapd_1.snap"
CURDATE=$(date +"%Y%m%d")
test -e "$IMAGE/systems/$CURDATE/snaps/core_1.snap"
test -e "$IMAGE/systems/$CURDATE/snaps/test-snapd-sh_13.snap"
echo Verifying that the store acknowledged we requested the expected revisions set by validation sets
# vs1.json
# pc: 1
# pc-kernel: 1
"$TESTSTOOLS"/journal-state get-log -u fakestore | MATCH 'requested snap "pc" revision 1'
"$TESTSTOOLS"/journal-state get-log -u fakestore | MATCH 'requested snap "pc-kernel" revision 1'
# vs2.json
# test-snapd-sh: 13
"$TESTSTOOLS"/journal-state get-log -u fakestore | MATCH 'requested snap "test-snapd-sh" revision 13'
# rest should not have a revision provided
"$TESTSTOOLS"/journal-state get-log -u fakestore | MATCH 'requested snap "core20" revision 0'
"$TESTSTOOLS"/journal-state get-log -u fakestore | MATCH 'requested snap "snapd" revision 0'
"$TESTSTOOLS"/journal-state get-log -u fakestore | MATCH 'requested snap "core" revision 0'
|