Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3348 from fgimenez/core-revert
tests: add core revert test
- Loading branch information
Showing
6 changed files
with
160 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "$*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.