Skip to content

Commit

Permalink
Merge pull request #3348 from fgimenez/core-revert
Browse files Browse the repository at this point in the history
tests: add core revert test
  • Loading branch information
mvo5 committed Jun 8, 2017
2 parents beff23c + 78802c4 commit 8742e4c
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 93 deletions.
4 changes: 4 additions & 0 deletions spread.yaml
Expand Up @@ -456,12 +456,16 @@ suites:
systems: [-fedora-*]
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
66 changes: 66 additions & 0 deletions tests/lib/nested.sh
@@ -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)"
;;
*)
echo "unsupported architecture"
exit 1
;;
esac

# create ubuntu-core image
mkdir -p /tmp/work-dir
/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 "$*"
}
71 changes: 71 additions & 0 deletions tests/nested/core-revert/task.yaml
@@ -0,0 +1,71 @@
summary: core revert test

systems: [ubuntu-16.04-64]

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"
39 changes: 11 additions & 28 deletions tests/nested/extra-snaps-assertions/task.yaml
Expand Up @@ -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
Expand All @@ -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 +\-"
61 changes: 8 additions & 53 deletions tests/nested/image-build/task.yaml
Expand Up @@ -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
12 changes: 0 additions & 12 deletions tests/nested/prepare-image-check/task.yaml

This file was deleted.

0 comments on commit 8742e4c

Please sign in to comment.