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
|
summary: Test running component install, pre-refresh, post-refresh, and remove hooks.
details: |
Tests a snap operations on a snap with two components. Some arbitrary
auto-connect plugs are picked for the components so that we can test that
plugs are properly connected.
The first component explicitly defines hooks that have the network-bind plug.
These plugs succeed only if they are able to bind to the network. The second
component contains implicit hooks that only receive the network plug. These
hooks succeed only if they are able create a network connection.
All of the hooks set variables that we use to verify that they are run.
systems: [ubuntu-16.04-64, ubuntu-18.04-64, ubuntu-2*, ubuntu-core-*]
prepare: |
# the hooks in this test access /etc/mdns.allow to verify that the network
# plug is connected. this is a simple way to check that the plug is connected
# without actually using the network, which can be problematic in tests run
# behind a proxy.
path="/etc/mdns.allow"
if [ -d /writable ]; then
path="/writable/system-data/etc/mdns.allow"
fi
if [ ! -f "${path}" ]; then
touch "${path}"
tests.cleanup defer rm "${path}"
fi
restore: |
if snap list test-snap-component-hooks; then
snap remove test-snap-component-hooks
fi
execute: |
snap install test-snap-component-hooks+one+two --revision=12
snap connections test-snap-component-hooks | MATCH "network-bind"
snap connections test-snap-component-hooks | MATCH "network"
snap list test-snap-component-hooks | awk 'NR != 1 { print $3 }' | MATCH 12
# 8 is the component revision
snap get test-snap-component-hooks one-installed | MATCH 10
snap get test-snap-component-hooks two-installed | MATCH 10
not snap get test-snap-component-hooks one-prerefreshed
not snap get test-snap-component-hooks two-prerefreshed
not snap get test-snap-component-hooks one-postrefreshed
not snap get test-snap-component-hooks two-postrefreshed
snap refresh test-snap-component-hooks --revision=13 --channel=latest/candidate
snap list test-snap-component-hooks | awk 'NR != 1 { print $3 }' | MATCH 13
# these shouldn't run again
snap get test-snap-component-hooks one-installed | MATCH 10
snap get test-snap-component-hooks two-installed | MATCH 10
# these run as their previous revision
snap get test-snap-component-hooks one-prerefreshed | MATCH 10
snap get test-snap-component-hooks two-prerefreshed | MATCH 10
# these run as the new revision
snap get test-snap-component-hooks one-postrefreshed | MATCH 11
snap get test-snap-component-hooks two-postrefreshed | MATCH 11
# make sure component remove hooks are run on individual component removal
snap remove test-snap-component-hooks+two
test -e /tmp/snap-private-tmp/snap.test-snap-component-hooks/tmp/two-remove-hook-executed
rm /tmp/snap-private-tmp/snap.test-snap-component-hooks/tmp/two-remove-hook-executed
# make sure component remove hooks are run on total snap removal
snap install test-snap-component-hooks+two
snap remove test-snap-component-hooks
test -e /tmp/snap-private-tmp/snap.test-snap-component-hooks/tmp/two-remove-hook-executed
|