|
| 1 | +summary: Verify install-device hostname is copied to run mode |
| 2 | + |
| 3 | +details: | |
| 4 | + Check that a hostname set by the gadget install-device hook during install |
| 5 | + mode is copied to the target run-mode system before the device reboots. |
| 6 | + On UC26 this also verifies that the presence of the install-device hook |
| 7 | + prevents the single-boot initramfs install path and that the hook runs. |
| 8 | +
|
| 9 | +backends: [-garden] |
| 10 | +systems: [ubuntu-24.04-64, ubuntu-26.04-64] |
| 11 | + |
| 12 | +environment: |
| 13 | + NESTED_BUILD_SNAPD_FROM_CURRENT: true |
| 14 | + |
| 15 | + NESTED_ENABLE_TPM: false |
| 16 | + NESTED_ENABLE_SECURE_BOOT: false |
| 17 | + NESTED_SIGN_SNAPS_FAKESTORE: true |
| 18 | + NESTED_CUSTOM_MODEL: $TESTSLIB/assertions/developer1-{VERSION}-dangerous.model |
| 19 | + NESTED_FAKESTORE_BLOB_DIR: $(pwd)/fake-store-blobdir |
| 20 | + NESTED_UBUNTU_IMAGE_SNAPPY_FORCE_SAS_URL: http://localhost:11028 |
| 21 | + NESTED_USE_CLOUD_INIT: false |
| 22 | + |
| 23 | +prepare: | |
| 24 | + # shellcheck source=tests/lib/nested.sh |
| 25 | + . "$TESTSLIB/nested.sh" |
| 26 | +
|
| 27 | + "$TESTSTOOLS"/store-state setup-fake-store "$NESTED_FAKESTORE_BLOB_DIR" |
| 28 | + "$TESTSTOOLS"/store-state teardown-staging-store |
| 29 | +
|
| 30 | + echo "Expose the needed assertions through the fakestore" |
| 31 | + cp "$TESTSLIB"/assertions/testrootorg-store.account-key "$NESTED_FAKESTORE_BLOB_DIR/asserts" |
| 32 | + cp "$TESTSLIB"/assertions/developer1.account "$NESTED_FAKESTORE_BLOB_DIR/asserts" |
| 33 | + cp "$TESTSLIB"/assertions/developer1.account-key "$NESTED_FAKESTORE_BLOB_DIR/asserts" |
| 34 | +
|
| 35 | + VERSION="$(tests.nested show version)" |
| 36 | +
|
| 37 | + echo "Generate a system-user assertion for the dangerous model" |
| 38 | + gojq --arg model "testkeys-snapd-dangerous-core-${VERSION}-amd64" \ |
| 39 | + ".models += [\$model] | .models |= unique" \ |
| 40 | + "$TESTSLIB/assertions/developer1-${VERSION}-auto-import.json" > auto-import.json |
| 41 | + "$TESTSLIB/gendeveloper1assert/main.sh" auto-import.json auto-import.assert |
| 42 | + export NESTED_CUSTOM_AUTO_IMPORT_ASSERTION="$PWD/auto-import.assert" |
| 43 | +
|
| 44 | + echo "Grab and prepare the gadget snap" |
| 45 | + snap download --basename=pc --channel="$VERSION/edge" pc |
| 46 | + unsquashfs -d pc-gadget pc.snap |
| 47 | +
|
| 48 | + echo "Add the install-device hook" |
| 49 | + mkdir -p pc-gadget/meta/hooks |
| 50 | + cp install-device pc-gadget/meta/hooks/install-device |
| 51 | + chmod +x pc-gadget/meta/hooks/install-device |
| 52 | +
|
| 53 | + echo "Disable serial registration for this test" |
| 54 | + test -f pc-gadget/meta/hooks/prepare-device |
| 55 | + sed -i '0,/^set -eu$/s//set -eu\n\nsnapctl set device-service.access=offline/' pc-gadget/meta/hooks/prepare-device |
| 56 | + grep -q '^snapctl set device-service.access=offline$' pc-gadget/meta/hooks/prepare-device |
| 57 | + chmod +x pc-gadget/meta/hooks/prepare-device |
| 58 | +
|
| 59 | + echo "Add the install-device hook plug to snap.yaml" |
| 60 | + gojq -s --yaml-input --yaml-output '.[0] * .[1]' snap-yaml-extras.yaml pc-gadget/meta/snap.yaml > snap.yaml.tmp |
| 61 | + cp -v snap.yaml.tmp pc-gadget/meta/snap.yaml |
| 62 | +
|
| 63 | + echo "Hold refreshes and make the journal persistent" |
| 64 | + sed defaults.yaml -e "s/@HOLD-TIME@/$(date --date='next week' +%Y-%m-%dT%H:%M:%S%:z)/" >> pc-gadget/meta/gadget.yaml |
| 65 | +
|
| 66 | + snap pack pc-gadget/ "$(tests.nested get extra-snaps-path)" |
| 67 | + rm -rf pc-gadget/ |
| 68 | +
|
| 69 | + NESTED_FAKESTORE_SNAP_DECL_PC_GADGET="pc-snap-decl-extras.json" |
| 70 | + export NESTED_FAKESTORE_SNAP_DECL_PC_GADGET |
| 71 | +
|
| 72 | + tests.nested build-image core |
| 73 | + unset NESTED_FAKESTORE_SNAP_DECL_PC_GADGET |
| 74 | +
|
| 75 | + tests.nested create-vm core |
| 76 | +
|
| 77 | +restore: | |
| 78 | + "$TESTSTOOLS"/store-state teardown-fake-store "$NESTED_FAKESTORE_BLOB_DIR" |
| 79 | + tests.cleanup restore |
| 80 | +
|
| 81 | +debug: | |
| 82 | + # shellcheck source=tests/lib/nested.sh |
| 83 | + . "$TESTSLIB/nested.sh" |
| 84 | +
|
| 85 | + cat "$NESTED_LOGS_DIR/ubuntu-image.log" || true |
| 86 | + journalctl -u nested-vm --no-pager || true |
| 87 | + nested_print_serial_log || true |
| 88 | + remote.exec "sudo snap changes" || true |
| 89 | + remote.exec "sudo snap changes | awk '/Initialize device/ { print \$1 }' | xargs -r -n1 sudo snap change" || true |
| 90 | + remote.exec "cat /proc/cmdline" || true |
| 91 | + remote.exec "cat /var/lib/snapd/modeenv" || true |
| 92 | + remote.exec "cat /etc/hostname" || true |
| 93 | + remote.exec "hostnamectl status --static" || true |
| 94 | + remote.exec "snap get pc device-service.access" || true |
| 95 | + remote.exec "snap connections pc" || true |
| 96 | + remote.exec "sudo journalctl -b --no-pager" || true |
| 97 | + remote.exec "zcat /var/log/install-mode.log.gz" || true |
| 98 | +
|
| 99 | +execute: | |
| 100 | + # shellcheck source=tests/lib/nested.sh |
| 101 | + . "$TESTSLIB/nested.sh" |
| 102 | +
|
| 103 | + echo "Wait for device initialisation to be done" |
| 104 | + INITIALIZE_DEVICE_CHANGE="$(remote.exec snap changes | awk '/Initialize device/ { print $1; exit }')" |
| 105 | + test -n "$INITIALIZE_DEVICE_CHANGE" |
| 106 | + retry -n 200 --wait 1 --env "INITIALIZE_DEVICE_CHANGE=$INITIALIZE_DEVICE_CHANGE" sh -c \ |
| 107 | + "remote.exec snap changes | MATCH \"^${INITIALIZE_DEVICE_CHANGE}\\s+(Done|Error).*Initialize device\"" |
| 108 | + remote.exec "sudo snap change $INITIALIZE_DEVICE_CHANGE" || true |
| 109 | + remote.exec snap changes | MATCH "^${INITIALIZE_DEVICE_CHANGE}\\s+Done.*Initialize device" |
| 110 | +
|
| 111 | + echo "Check the system booted into run mode" |
| 112 | + remote.exec "cat /proc/cmdline" | MATCH "snapd_recovery_mode=run" |
| 113 | + remote.exec "cat /var/lib/snapd/modeenv" | MATCH "mode=run" |
| 114 | +
|
| 115 | + echo "Check that install-device ran" |
| 116 | + remote.exec "zcat /var/log/install-mode.log.gz" | MATCH "Run install-device hook" |
| 117 | +
|
| 118 | + echo "Check the gadget hook has hostname-control connected" |
| 119 | + remote.exec "snap connections pc" | MATCH 'hostname-control\s+pc:hostname-control\s+:hostname-control' |
| 120 | +
|
| 121 | + echo "Check that serial registration was disabled for the test" |
| 122 | + remote.exec "snap get pc device-service.access" | MATCH "^offline$" |
| 123 | +
|
| 124 | + echo "Check that the install-device hostname reached run mode" |
| 125 | + remote.exec "cat /etc/hostname" | MATCH "^install-device-hostname$" |
| 126 | + remote.exec "hostnamectl status --static" | MATCH "^install-device-hostname$" |
0 commit comments