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
|
summary: Verify kernel modules components work as expected
details: |
Install a kernel-modules component and verify that the shipped
kernel module is installed.
systems: [-ubuntu-1*, -ubuntu-20*, -ubuntu-22*]
environment:
# Test both encrypted and unencrypted cases
NESTED_ENABLE_TPM/encrypted: true
NESTED_ENABLE_SECURE_BOOT/encrypted: true
# unencrypted case
NESTED_ENABLE_TPM/plain: false
NESTED_ENABLE_SECURE_BOOT/plain: false
NESTED_BUILD_SNAPD_FROM_CURRENT: true
NESTED_ENABLE_OVMF: true
KMOD_COMP: efi-pstore
prepare: |
# Modify kernel and create a component
"$TESTSTOOLS"/build_kernel_with_comps.sh efi_pstore "$KMOD_COMP"
cp pc-kernel.snap "$(tests.nested get extra-snaps-path)"
cp pc-kernel+"$KMOD_COMP".comp "$(tests.nested get extra-snaps-path)"
tests.nested build-image core
tests.nested create-vm core
execute: |
check_efi_pstore() {
# Compare times to check that drivers tree was created on
# installation, not on seeding
# shellcheck disable=SC2016
tree_birth=$(remote.exec 'date -d"$(stat --printf="%w\n" /var/lib/snapd/kernel/pc-kernel)" +%s')
reboot_time=$(remote.exec 'last reboot --time-format full | sed -n "s/wtmp begins //p"')
reboot_time=$(date -d"$reboot_time" +%s)
test "$reboot_time" -gt "$tree_birth"
# check that the component is in place
kern_ver=$(remote.exec uname -r)
comp_install_dir=/var/lib/snapd/kernel/pc-kernel/x1/lib/modules/"$kern_ver"/updates/"$KMOD_COMP"
comp_dir=/snap/pc-kernel/components/mnt/"$KMOD_COMP"/x1/modules/"$kern_ver"
test "$(remote.exec readlink -f "$comp_install_dir")" = "$comp_dir"
# module comes from a component
remote.exec modinfo -F filename efi_pstore | MATCH updates/"$KMOD_COMP"/kmod/efi-pstore.ko
# module should have been loaded (pulled by systemd-pstore.service)
remote.exec lsmod | MATCH efi_pstore
# Make sure it was loaded early
remote.exec systemctl show -p ExecMainStatus modprobe@efi_pstore.service | MATCH ExecMainStatus=0
}
# check component from store has been early-installed
check_efi_pstore
# Additionally, check that modules loaded by systemd right after switch root could be loaded
lsmod | MATCH ip_tables
# No mounts for unset versions are found
mount | not MATCH efi-pstore_unset
mount | not MATCH pc-kernel_unset
# reboot and check again
boot_id=$(tests.nested boot-id)
remote.exec sudo reboot || true
tests.nested wait-for reboot "$boot_id"
check_efi_pstore
lsmod | MATCH ip_tables
# remove kernel component
remote.exec sudo snap remove pc-kernel+"$KMOD_COMP"
# do a factory reset
printf "Request factory reset\n"
boot_id=$(tests.nested boot-id)
remote.exec "sudo snap reboot --factory-reset" || true
tests.nested wait-for reboot "$boot_id"
# check that we are back in run mode
remote.exec cat /proc/cmdline | MATCH 'snapd_recovery_mode=run'
# wait for the system to get setup and finish seeding
remote.wait-for snap-command
retry -n 10 --wait 2 remote.exec "sudo snap wait system seed.loaded"
# component was restored
check_efi_pstore
|