tests: add core revert test #3348

Merged
merged 27 commits into from Jun 8, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+160 −93
Split
View
@@ -440,12 +440,16 @@ suites:
summary: Tests for nested images
environment:
NESTED_ARCH: "$(HOST: echo ${SPREAD_NESTED_ARCH:-amd64})"
+ CORE_REFRESH_CHANNEL: "$(HOST: echo ${SPREAD_CORE_REFRESH_CHANNEL:-candidate})"
halt-timeout: 2h
kill-timeout: 2h
manual: true
prepare: |
apt update && apt install -y snapd qemu genisoimage sshpass
+
+ snap install --classic --beta ubuntu-image
restore: |
apt remove -y qemu genisoimage sshpass
+ snap remove ubuntu-image
# vim:ts=4:sw=4:et
View
@@ -0,0 +1,66 @@
+#!/bin/sh
+. $TESTSLIB/systemd.sh
+
+wait_for_ssh(){
+ retry=300
+ while ! execute_remote true; do
+ retry=$(( retry - 1 ))
+ if [ $retry -le 0 ]; then
+ echo "Timed out waiting for ssh. Aborting!"
+ exit 1
+ fi
+ sleep 1
+ done
+}
+
+prepare_ssh(){
+ execute_remote "sudo adduser --extrausers --quiet --disabled-password --gecos '' test"
+ execute_remote "echo test:ubuntu | sudo chpasswd"
+ execute_remote "echo 'test ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/test-user"
+}
+
+create_assertions_disk(){
+ dd if=/dev/null of=assertions.disk bs=1M seek=1
+ mkfs.ext4 -F assertions.disk
+ mkdir /mnt/assertions
+ mount -t ext4 -o loop assertions.disk /mnt/assertions
+ cp $TESTSLIB/assertions/auto-import.assert /mnt/assertions
+ umount /mnt/assertions && rm -rf /mnt/assertions
+}
+
+create_nested_core_vm(){
+ # determine arch related vars
+ case "$NESTED_ARCH" in
+ amd64)
+ QEMU="$(which qemu-system-x86_64)"
+ ;;
+ i386)
+ QEMU="$(which qemu-system-i386)"
@zyga

zyga Jun 8, 2017

Contributor

QEMU can expand to "". This is not a big deal but I'd rather get a qemu-system-x86_64: command not found than a more confusing message below when the first argument of qemu becomes the command. Could we please drop the which?

@fgimenez

fgimenez Jun 8, 2017

Contributor

Sure, will do in a followup

+ ;;
+ *)
+ echo "unsupported architecture"
+ exit 1
+ ;;
+ esac
+
+ # create ubuntu-core image
+ mkdir -p /tmp/work-dir
@zyga

zyga Jun 8, 2017

Contributor

I'd prefer if this was a temporary directory.

@fgimenez

fgimenez Jun 8, 2017

Contributor

Ok, noted for the followup

+ /snap/bin/ubuntu-image --image-size 3G $TESTSLIB/assertions/nested-${NESTED_ARCH}.model --channel $CORE_CHANNEL --output ubuntu-core.img
+ mv ubuntu-core.img /tmp/work-dir
+
+ create_assertions_disk
+
+ systemd_create_and_start_unit nested-vm "${QEMU} -m 1024 -nographic -net nic,model=virtio -net user,hostfwd=tcp::8022-:22 -drive file=/tmp/work-dir/ubuntu-core.img,if=virtio,cache=none -drive file=${PWD}/assertions.disk,if=virtio,cache=none"
+
+ wait_for_ssh
+ prepare_ssh
+}
+
+destroy_nested_core_vm(){
+ systemd_stop_and_destroy_unit nested-vm
+ rm -rf /tmp/work-dir
+}
+
+execute_remote(){
+ sshpass -p ubuntu ssh -p 8022 -q -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user1@localhost "$*"
+}
@@ -0,0 +1,71 @@
+summary: core revert test
@zyga

zyga Jun 8, 2017

Contributor

Could you please document the intent and mechanics of this test.

@fgimenez

fgimenez Jun 8, 2017

Contributor

Sure, I'll add a details section

+
+systems: [ubuntu-16.04-64]
@zyga

zyga Jun 8, 2017

Contributor

Can this test happen on other distributions?

@fgimenez

fgimenez Jun 8, 2017

Contributor

I think so, in fact the interesting part happens on the nested machine, if we can install qemu all should be good. I'll try locally with debian/fedora anyway.

+
+prepare: |
+ apt install -y --no-install-recommends kpartx
+
+ . $TESTSLIB/nested.sh
+ create_nested_core_vm
+
+restore: |
+ apt autoremove -y --purge kpartx
+
+ . $TESTSLIB/nested.sh
+ destroy_nested_core_vm
+
+debug: |
+ systemctl stop nested-vm || true
+ if [ -f /tmp/work-dir/ubuntu-core.img ]; then
+ loops=$(kpartx -avs /tmp/work-dir/ubuntu-core.img | cut -d' ' -f 3)
+
+ part=$(echo "$loops" | tail -1)
+
+ tmp=$(mktemp -d)
+ mount /dev/mapper/$part $tmp
+
+ grep --text "hsearch_r failed for.* No such process" $tmp/system-data/var/log/syslog
+
+ umount $tmp
+ rm -rf $tmp
+ kpartx -ds /tmp/work-dir/ubuntu-core.img
+ fi
+
+kill-timeout: 35m
+
+execute: |
+ . $TESTSLIB/nested.sh
+
+ cd $SPREAD_PATH
+ execute_remote "sudo snap install network-manager"
+ execute_remote "snap aliases" | MATCH "nmcli"
+
+ # configure network-manager to take over the connection control on next reboot
+ execute_remote "sudo mv /etc/netplan/00-snapd-config.yaml /etc/netplan/00-snapd-config.yaml.back"
+ execute_remote "sudo sed -i 's/unmanaged-devices+=interface-name:eth*/#unmanaged-devices+=interface-name:eth*/' /var/snap/network-manager/current/conf.d/disable-ethernet.conf"
+
+ execute_remote "snap info core" | MATCH "tracking: +${CORE_CHANNEL}"
+ execute_remote "sudo snap refresh --${CORE_REFRESH_CHANNEL} core" || true
+
+ wait_for_ssh
+
+ while ! execute_remote "snap changes" | MATCH "Done.*Refresh \"core\" snap from \"${CORE_REFRESH_CHANNEL}\" channel"; do sleep 1 ; done
+ execute_remote "snap info core" | MATCH "tracking: +${CORE_REFRESH_CHANNEL}"
+ # make sure network-manager is on charge of eth0
+ execute_remote "nmcli c" | MATCH eth0
+ execute_remote "nmcli d" | MATCH "eth0 +ethernet +connected"
+ # sanity check, no refresh should be done here but the command shouldn't fail
+ execute_remote "sudo snap refresh"
+
+ execute_remote "snap aliases" | MATCH "nmcli"
+
+ execute_remote "sudo snap revert core" || true
+
+ wait_for_ssh
+
+ while ! execute_remote "snap changes" | MATCH "Done.*Revert \"core\" snap"; do sleep 1 ; done
+ execute_remote "snap aliases" | MATCH "nmcli"
+ execute_remote "snap info core" | MATCH "tracking: +${CORE_REFRESH_CHANNEL}"
+ execute_remote "ifconfig" | MATCH eth0
+ # this currently fails, refresh from the old version conflicts with aliases
+ # execute_remote "sudo snap refresh"
@@ -23,7 +23,6 @@ prepare: |
# create ubuntu-core image
mkdir -p /tmp/work-dir
- snap install --devmode --beta ubuntu-image
# bind mount the snap binary installed from the package built with the branch to the binary used by ubuntu-image
mount -o bind /usr/bin/snap /snap/ubuntu-image/current/bin/snap
@@ -32,44 +31,28 @@ prepare: |
/snap/bin/ubuntu-image --image-size 3G $TESTSLIB/assertions/nested-${NESTED_ARCH}.model --channel $CORE_CHANNEL --output ubuntu-core.img --extra-snaps core_*.snap
mv ubuntu-core.img /tmp/work-dir
- # create assertion block device
- genisoimage -volid cidata -joliet -rock -o assertions.disk $TESTSLIB/assertions/auto-import.assert
+ create_assertions_disk
. $TESTSLIB/systemd.sh
systemd_create_and_start_unit nested-vm "${QEMU} -m 1024 -nographic -net nic,model=virtio -net user,hostfwd=tcp::8022-:22 -drive file=/tmp/work-dir/ubuntu-core.img,if=virtio,cache=none -drive file=${PWD}/assertions.disk,if=virtio,cache=none"
restore: |
- snap remove ubuntu-image
. $TESTSLIB/systemd.sh
systemd_stop_and_destroy_unit nested-vm
rm -rf /tmp/work-dir
execute: |
- execute_remote(){
- sshpass -p ubuntu ssh -p 8022 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user1@localhost "$*"
- }
-
- # wait_for_ssh
- retry=300
- while ! execute_remote true; do
- retry=$(( retry - 1 ))
- if [ $retry -le 0 ]; then
- echo "Timed out waiting for ssh. Aborting!"
- exit 1
- fi
- sleep 1
- done
-
- # prepare_ssh
- execute_remote "sudo adduser --extrausers --quiet --disabled-password --gecos '' test"
- execute_remote "echo test:ubuntu | sudo chpasswd"
- execute_remote "echo 'test ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/test-user"
+ . $TESTSLIB/nested.sh
+ wait_for_ssh
+ prepare_ssh
cd $SPREAD_PATH
- curl -s -O https://niemeyer.s3.amazonaws.com/spread-amd64.tar.gz && tar xzvf spread-amd64.tar.gz && rm -f spread-amd64.tar.gz && mv spread /tmp/work-dir
+ echo "Wait for first boot to be done"
+ while ! execute_remote "snap changes" | MATCH "Done.*Initialize system state"; do sleep 1; done
+
+ echo "We have a model assertion"
+ execute_remote "snap known model" | MATCH "series: 16"
- set +x
- export SPREAD_EXTERNAL_ADDRESS=localhost:8022
- rm -f snapd-state.tar.gz npm-debug.log
- /tmp/work-dir/spread -v external:ubuntu-core-16-64:tests/nested/prepare-image-check
+ echo "Make sure core has an actual revision"
+ execute_remote "snap list" | MATCH "^core +[0-9]+\-[0-9]+ +[0-9]+ +canonical +\-"
@@ -3,68 +3,23 @@ summary: create ubuntu-core image and execute the suite in a nested qemu instanc
systems: [ubuntu-16.04-64]
prepare: |
- # determine arch related vars
- case "$NESTED_ARCH" in
- amd64)
- QEMU="$(which qemu-system-x86_64)"
- ;;
- i386)
- QEMU="$(which qemu-system-i386)"
- ;;
- *)
- echo "unsupported architecture"
- exit 1
- ;;
- esac
-
- . $TESTSLIB/dirs.sh
-
- # create ubuntu-core image
- mkdir -p /tmp/work-dir
- snap install --devmode --beta ubuntu-image
- $SNAPMOUNTDIR/bin/ubuntu-image --image-size 3G $TESTSLIB/assertions/nested-${NESTED_ARCH}.model --channel $CORE_CHANNEL --output ubuntu-core.img
- mv ubuntu-core.img /tmp/work-dir
-
- # create assertion block device
- genisoimage -volid cidata -joliet -rock -o assertions.disk $TESTSLIB/assertions/auto-import.assert
-
- . $TESTSLIB/systemd.sh
- systemd_create_and_start_unit nested-vm "${QEMU} -m 1024 -nographic -net nic,model=virtio -net user,hostfwd=tcp::8022-:22 -drive file=/tmp/work-dir/ubuntu-core.img,if=virtio,cache=none -drive file=${PWD}/assertions.disk,if=virtio,cache=none"
+ . $TESTSLIB/nested.sh
+ create_nested_core_vm
restore: |
- snap remove ubuntu-image
- . $TESTSLIB/systemd.sh
- systemd_stop_and_destroy_unit nested-vm
- rm -rf /tmp/work-dir
+ . $TESTSLIB/nested.sh
+ destroy_nested_core_vm
execute: |
- execute_remote(){
- sshpass -p ubuntu ssh -p 8022 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user1@localhost "$*"
- }
-
- # wait_for_ssh
- retry=300
- while ! execute_remote true; do
- retry=$(( retry - 1 ))
- if [ $retry -le 0 ]; then
- echo "Timed out waiting for ssh. Aborting!"
- exit 1
- fi
- sleep 1
- done
-
- # prepare_ssh
- execute_remote "sudo adduser --extrausers --quiet --disabled-password --gecos '' test"
- execute_remote "echo test:ubuntu | sudo chpasswd"
- execute_remote "echo 'test ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/test-user"
-
cd $SPREAD_PATH
- curl -s -O https://niemeyer.s3.amazonaws.com/spread-amd64.tar.gz && tar xzvf spread-amd64.tar.gz && rm -f spread-amd64.tar.gz && mv spread /tmp/work-dir
+ tmp=$(mktemp -d)
+ trap 'rm $tmp' EXIT
+ curl -s -O https://niemeyer.s3.amazonaws.com/spread-amd64.tar.gz && tar xzvf spread-amd64.tar.gz && rm -f spread-amd64.tar.gz && mv spread $tmp
set +x
export SPREAD_EXTERNAL_ADDRESS=localhost:8022
- /tmp/work-dir/spread -v external:ubuntu-core-16-64:tests/main/ubuntu-core-reboot \
+ $tmp/spread -v external:ubuntu-core-16-64:tests/main/ubuntu-core-reboot \
external:ubuntu-core-16-64:tests/main/install-store \
external:ubuntu-core-16-64:tests/main/interfaces-system-observe \
external:ubuntu-core-16-64:tests/main/op-remove-retry | while read line; do echo "> $line"; done
@@ -1,12 +0,0 @@
-summary: check that prepare-image worked well from inside the generated image
-systems: [ubuntu-core-16-*]
-manual: true
-execute: |
- echo "Wait for first boot to be done"
- while ! snap changes | grep -q "Done.*Initialize system state"; do sleep 1; done
-
- echo "We have a model assertion"
- snap known model|grep "series: 16"
-
- echo "Make sure core has an actual revision"
- snap list | MATCH "^core +[0-9]+\-[0-9]+ +[0-9]+ +canonical +\-"