mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
* tests: document nightly/sbuild Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/classic/hotplug Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: fix typo: verifying Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: fix typo: established Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: fix typo: finished Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: fix typo: missing space Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/classic/snapshots-with-core-refresh-revert Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/core/core-revert Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/core/image-build Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/manual/cloud-init-*-vuln The two tests are related, one checks what happens on a system that boots up for the first time with the fix, while the other the fix is applied on update. Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/manual/cmdline-remove-append Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/manual/core-early-config Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/manual/core20-new-snapd-does-not-break-old-initrd Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/manual/core20-validation-sets Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: fix typo: bionic Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * tests: document nested/manual/gadget-connections Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> * Update tests/nested/classic/hotplug/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/classic/hotplug/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/classic/hotplug/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/core/core-revert/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/core/core-revert/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/core/core-revert/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/core/core-revert/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/core/core20-kernel-failover/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/core/core20-kernel-failover/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/cmdline-remove-append/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/core-early-config/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/core-early-config/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/core20-new-snapd-does-not-break-old-initrd/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/core20-new-snapd-does-not-break-old-initrd/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/devmode-snaps-can-run-other-snaps/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/gadget-connections/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nightly/sbuild/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update tests/nested/manual/devmode-snaps-can-run-other-snaps/task.yaml Co-authored-by: Graham Morrison <graham.morrison@canonical.com> * Update task.yaml --------- Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com> Co-authored-by: Sergio Cazzolato <sergiocazzolato@gmail.com> Co-authored-by: Graham Morrison <graham.morrison@canonical.com> Co-authored-by: Sergio Cazzolato <sergio.cazzolato@canonical.com>
194 lines
7.9 KiB
YAML
194 lines
7.9 KiB
YAML
summary: Create ubuntu classic image, install snapd and test hotplug feature
|
|
|
|
details: |
|
|
Snapd contains a little-used subsystem for reacting to dynamic device
|
|
reconfiguration events, and in response, maintains a set of system-provided
|
|
slots for certain snapd interfaces.
|
|
|
|
One of the first interfaces to support this feature was the serial-port
|
|
interface. Using this, snapd was able to detect serial ports that were not declared
|
|
statically in the gadget snap, but instead were enumerated on startup or
|
|
discovered dynamically when attached to the system over the USB bus.
|
|
|
|
Simulating and testing this sort of interaction requires a nested virtual machine, where
|
|
qemu can be scripted to dynamically attach devices to the running virtual
|
|
machine.
|
|
|
|
prepare: |
|
|
echo "Install snapd.deb in the nested vm"
|
|
remote.push "${GOHOME}"/snapd_*.deb
|
|
remote.exec "sudo apt update"
|
|
remote.exec "sudo apt install -y ./snapd_*.deb"
|
|
|
|
echo "Install linux-modules-extra package as it provides ftdi_sio and usbserial kernel modules"
|
|
#shellcheck disable=SC2016
|
|
remote.exec 'DEBIAN_FRONTEND=noninteractive sudo -E apt install -y "linux-modules-extra-$(uname -r)"'
|
|
|
|
snap pack "$TESTSLIB"/snaps/serial-port-hotplug
|
|
remote.push serial-port-hotplug_1.0_all.snap
|
|
echo "Add test user to dialout group required for ttyUSB* devices"
|
|
remote.exec "sudo usermod -a -G dialout user1"
|
|
|
|
remote.exec "sudo snap install --devmode jq"
|
|
|
|
restore: |
|
|
rm -f /tmp/serialport{0,1}
|
|
|
|
debug: |
|
|
remote.exec "snap connections --all" || true
|
|
remote.exec "snap list" || true
|
|
remote.exec "dmesg" || true
|
|
remote.exec 'sudo jq -r ".data[\"hotplug-slots\"]" /var/lib/snapd/state.json' || true
|
|
remote.exec 'lsmod' || true
|
|
|
|
execute: |
|
|
#shellcheck source=tests/lib/hotplug.sh
|
|
. "$TESTSLIB/hotplug.sh"
|
|
#shellcheck source=tests/lib/nested.sh
|
|
. "$TESTSLIB/nested.sh"
|
|
|
|
if remote.exec "udevadm info -e" | MATCH "ID_MODEL=QEMU_USB_SERIAL"; then
|
|
echo "USB serial already registered, exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
remote.exec "sudo snap install hello-world"
|
|
|
|
echo "Enabling hotplug"
|
|
remote.exec "sudo snap set core experimental.hotplug=true"
|
|
|
|
echo "Plugging the device"
|
|
hotplug_add_dev1
|
|
|
|
# precondition checks to make sure qemu setup is correct
|
|
remote.exec "retry --wait 1 -n 5 sh -c 'udevadm info -e | MATCH ID_MODEL=QEMU_USB_SERIAL'"
|
|
|
|
remote.exec "ls /dev/tty*" | MATCH "ttyUSB0"
|
|
|
|
echo "Checking that qemuusbserial hotplug slot is present"
|
|
check_slot_present qemuusbserial
|
|
check_slot_not_gone qemuusbserial
|
|
check_slot_device_path qemuusbserial "/dev/ttyUSB0"
|
|
|
|
echo "Unplugging the device with no connections on the slot"
|
|
hotplug_del_dev1
|
|
|
|
# precondition check to make sure qemu event was triggered correctly
|
|
remote.exec "retry --wait 1 -n 5 sh -c 'udevadm info -e | NOMATCH ID_MODEL=QEMU_USB_SERIAL'"
|
|
if remote.exec "udevadm info -e" | MATCH "ID_MODEL=QEMU_USB_SERIAL"; then
|
|
echo "USB serial should not be registered anymore, exiting..."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Checking that hotplug slot is no longer present"
|
|
check_slot_not_present qemuusbserial
|
|
check_slot_not_present_in_state qemuusbserial
|
|
|
|
echo "Plugging the device back"
|
|
hotplug_add_dev1
|
|
|
|
echo "Checking that qemuusbserial hotplug slot is present again"
|
|
check_slot_present qemuusbserial
|
|
|
|
echo "Installing test snap with serial port plug"
|
|
remote.exec "sudo snap install --dangerous serial-port-hotplug_1.0_all.snap"
|
|
|
|
echo "Connecting hotplug slot of the first device"
|
|
remote.exec "sudo snap connect serial-port-hotplug:serial-port :qemuusbserial"
|
|
check_slot_connected qemuusbserial
|
|
|
|
echo "Verifying serial-port permissions of the snap"
|
|
verify_apparmor_profile "/dev/ttyUSB0"
|
|
remote.exec "/snap/bin/serial-port-hotplug.consumer write-1" | MATCH "Access to /dev/ttyUSB0 ok"
|
|
remote.exec "/snap/bin/serial-port-hotplug.consumer write-2" | MATCH "Access to /dev/ttyUSB1 failed"
|
|
MATCH "write-1 on /dev/ttyUSB0" < /tmp/serialport1
|
|
|
|
echo "Unplugging the device"
|
|
hotplug_del_dev1
|
|
|
|
echo "Checking that qemuusbserial hotplug slot is no longer present, but is remembered"
|
|
check_slot_not_present qemuusbserial
|
|
check_slot_gone qemuusbserial
|
|
|
|
echo "Plugging device back, checking that the slot and connection are restored"
|
|
hotplug_add_dev1
|
|
check_slot_connected qemuusbserial
|
|
check_slot_not_gone qemuusbserial
|
|
|
|
echo "Unplugging the device again"
|
|
hotplug_del_dev1
|
|
|
|
echo "Checking that qemuusbserial hotplug slot is not present, but is still remembered"
|
|
check_slot_not_present qemuusbserial
|
|
check_slot_gone qemuusbserial
|
|
|
|
echo "Plugging second device creates a slot with new name and it's expected on /dev/ttyUSB0"
|
|
hotplug_add_dev2
|
|
check_slot_present qemuusbserial-1
|
|
check_slot_not_gone qemuusbserial-1
|
|
check_slot_device_path qemuusbserial-1 "/dev/ttyUSB0"
|
|
|
|
echo "Plugging first device back while second device is present, checking that connection is restored"
|
|
hotplug_add_dev1
|
|
check_slot_connected qemuusbserial
|
|
check_slot_not_gone qemuusbserial
|
|
|
|
echo "Verifying serial-port permissions of the snap, the first device is now expected on ttyUSB1"
|
|
check_slot_device_path qemuusbserial "/dev/ttyUSB1"
|
|
verify_apparmor_profile "/dev/ttyUSB1"
|
|
remote.exec "/snap/bin/serial-port-hotplug.consumer write-3" | MATCH "Access to /dev/ttyUSB0 failed"
|
|
remote.exec "/snap/bin/serial-port-hotplug.consumer write-4" | MATCH "Access to /dev/ttyUSB1 ok"
|
|
MATCH "write-3 on /dev/ttyUSB1" < /tmp/serialport1
|
|
|
|
echo "Restarting snapd should restore both hotplug slots since devices are still present"
|
|
remote.exec "sudo systemctl stop snapd.service snapd.socket"
|
|
remote.exec "sudo systemctl start snapd.service snapd.socket"
|
|
check_slot_connected qemuusbserial
|
|
check_slot_not_gone qemuusbserial
|
|
check_slot_present qemuusbserial-1
|
|
remote.exec "/snap/bin/serial-port-hotplug.consumer write-5" | MATCH "Access to /dev/ttyUSB1 ok"
|
|
MATCH "write-5 on /dev/ttyUSB1" < /tmp/serialport1
|
|
|
|
echo "Unplugging first device while snapd is stopped and then starting snapd remembers the slot internally due to connection"
|
|
remote.exec "sudo systemctl stop snapd.service snapd.socket"
|
|
hotplug_del_dev1
|
|
remote.exec "sudo systemctl start snapd.service snapd.socket"
|
|
check_slot_not_present qemuusbserial
|
|
check_slot_gone qemuusbserial
|
|
|
|
echo "Plugging first device back restores the slot and connection"
|
|
hotplug_add_dev1
|
|
check_slot_connected qemuusbserial
|
|
check_slot_not_gone qemuusbserial
|
|
|
|
echo "Disconnecting first slot and then unplugging the device removes the slot completely"
|
|
# manual snap disconnect doesn't implement retry and errors out if there are conflicting changes, so wait for hotplug changes to complete
|
|
wait_for_all_changes
|
|
remote.exec "sudo snap disconnect serial-port-hotplug:serial-port :qemuusbserial"
|
|
check_slot_present qemuusbserial
|
|
hotplug_del_dev1
|
|
check_slot_not_present qemuusbserial
|
|
check_slot_not_present_in_state qemuusbserial
|
|
|
|
echo "Unplugging second device removes the slot completely"
|
|
hotplug_del_dev2
|
|
check_slot_not_present qemuusbserial-1
|
|
check_slot_not_present_in_state qemuusbserial-1
|
|
|
|
echo "Plugging device back creates the slot again"
|
|
hotplug_add_dev1
|
|
check_slot_present qemuusbserial
|
|
check_slot_not_gone qemuusbserial
|
|
check_slot_device_path qemuusbserial "/dev/ttyUSB0"
|
|
|
|
echo "Connecting hotplug slot of the first device again"
|
|
remote.exec "sudo snap connect serial-port-hotplug:serial-port :qemuusbserial"
|
|
check_slot_connected qemuusbserial
|
|
|
|
remote.exec "cat /var/snap/serial-port-hotplug/common/connect-plug-done" | MATCH "/dev/ttyUSB0"
|
|
|
|
echo "Hotplug slot stays after removing the snap"
|
|
remote.exec "sudo snap remove serial-port-hotplug"
|
|
check_slot_present qemuusbserial
|
|
check_slot_not_gone qemuusbserial
|