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 87 88
|
summary: Ensure that the libvirt interface works.
details: |
The libvirt interface allows a snap to access the libvirtd socket in order
to manage libvirt domains and other resources.
A snap which defines a libvirt plug must be shown in the interfaces list.
The plug must not be auto-connected on install and, as usual, must be able
to be reconnected.
A snap declaring a plug on this interface must be able to create and destroy
a domain. The test uses a snap that carries a unikernel built to be run on
top of qemu, boot and respond to ping. Once the domain is created, the test
checks connectivity to the unikernel.
systems: [ubuntu-2*]
prepare: |
if not os.query is-pc-amd64; then
echo "The snap test-snapd-libvirt-consumer is just available for amd64"
exit
fi
# Given test user is added to the libvirt group
adduser test libvirt
echo "And libvirt is configured to manage /dev/net/tun"
systemctl stop libvirtd.service || true
echo 'cgroup_device_acl = ["/dev/net/tun", "/dev/random", "/dev/urandom"]' | tee -a /etc/libvirt/qemu.conf
echo "And the required services up"
systemctl start libvirtd.service
systemctl start virtlogd.socket
echo "And a snap declaring a plug on the libvirt interface is installed"
snap install --edge test-snapd-libvirt-consumer
# Temporary workaround until the updated test snap is released
mount -o bind "$TESTSLIB/snaps/store/test-snapd-libvirt-consumer/vm/ping-unikernel.xml" \
/snap/test-snapd-libvirt-consumer/current/vm/ping-unikernel.xml
echo "And the required tap interface is in place"
ip tuntap add tap100 mode tap
ip addr add 10.0.0.1/24 dev tap100
ip link set dev tap100 up
restore: |
if not os.query is-pc-amd64; then
echo "The snap test-snapd-libvirt-consumer is just available for amd64"
exit
fi
ip link delete tap100
# remove test user from the libvirt group
deluser test libvirt
execute: |
if not os.query is-pc-amd64; then
echo "The snap test-snapd-libvirt-consumer is just available for amd64"
exit
fi
echo "The interface is not connected by default"
snap interfaces -i libvirt | MATCH '^- +test-snapd-libvirt-consumer:libvirt'
echo "When the plug is connected"
snap connect test-snapd-libvirt-consumer:libvirt
echo "Then the snap is able to create the unikernel domain"
su -l -c "test-snapd-libvirt-consumer.machine-up" test
virsh list | MATCH ping-unikernel
echo "And the unikernel is accesible"
ping -c 1 -q -W 1 10.0.0.2
echo "And the snap is able to destroy the unikernel domain"
su -l -c "test-snapd-libvirt-consumer.machine-down" test
virsh list | NOMATCH ping-unikernel
echo "When the plug is disconnected"
snap disconnect test-snapd-libvirt-consumer:libvirt
echo "Then the snap is not able to create a domain"
if su -l -c "test-snapd-libvirt-consumer.machine-up" test 2> creation.error; then
echo "Expected permission error accessing libvirtd socket with disconnected plug"
exit 1
fi
MATCH "Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied" < creation.error
|