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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
summary: Ensure that netplan works on Ubuntu Core with network-setup-{control,observe}
details: |
Netplan apply is used to apply network configuration to the system
environment:
NETPLAN: io.netplan.Netplan
prepare: |
# build the netplan snap for this system
#shellcheck source=tests/lib/snaps.sh
. "$TESTSLIB"/snaps.sh
# use no base setting to use effectively "base: core"
sed "$TESTSLIB/snaps/netplan-snap/meta/snap.yaml.in" \
-e "s/base: %BASESNAP%/# no base snap for core base/" \
-e "s|%USRMERGE%||" \
> "$TESTSLIB/snaps/netplan-snap/meta/snap.yaml"
snap pack "$TESTSLIB/snaps/netplan-snap" --filename=netplan-snap-16.snap
# use base: core18
sed "$TESTSLIB/snaps/netplan-snap/meta/snap.yaml.in" \
-e "s/base: %BASESNAP%/base: core18/" \
-e "s|%USRMERGE%||" \
> "$TESTSLIB/snaps/netplan-snap/meta/snap.yaml"
snap pack "$TESTSLIB/snaps/netplan-snap" --filename=netplan-snap-18.snap
# use base: core20
sed "$TESTSLIB/snaps/netplan-snap/meta/snap.yaml.in" \
-e "s/base: %BASESNAP%/base: core20/" \
-e "s|%USRMERGE%|/usr|" \
> "$TESTSLIB/snaps/netplan-snap/meta/snap.yaml"
snap pack "$TESTSLIB/snaps/netplan-snap" --filename=netplan-snap-20.snap
# TODO add core22 and 24?
execute: |
# test all base versions of netplan on all combos of core releases
versions="16 18 20"
for rel in $versions; do
snap install --dangerous "netplan-snap-$rel.snap"
echo "The interface is disconnected by default"
snap connections netplan-snap | MATCH 'network-setup-control +netplan-snap:network-setup-control +- +-'
echo "Running netplan apply without network-setup-control fails"
if netplan-snap.netplan apply; then
echo "Expected access denied error for netplan apply"
exit 1
fi
if ! os.query is-core16 && test "$rel" -ne 16; then
echo "Running netplan generate without network-setup-control fails"
if netplan-snap.netplan generate; then
echo "Expected access denied error for netplan generate"
exit 1
fi
else
echo "Skipping netplan generate on UC16"
fi
echo "Count how many network service restarts happened before calling netplan apply"
stopped_before="$("$TESTSTOOLS"/journal-state get-log -u systemd-networkd | grep -c 'Stopped Network Service.' || true)"
started_before="$("$TESTSTOOLS"/journal-state get-log -u systemd-networkd | grep -c 'Started Network Service.' || true)"
echo "When the interface is connected"
snap connect netplan-snap:network-setup-control
# sometimes the systems becomes unreachable after "netplan apply"
# (see LP:1949708), adding --debug might give us clues why
echo "Running netplan apply now works"
if ! netplan-snap.netplan --debug apply; then
echo "Unexpected error running netplan apply"
exit 1
fi
if ! os.query is-core16 && test "$rel" -ne 16; then
echo "Running netplan generate now works"
if ! netplan-snap.netplan generate; then
echo "Unexpected error running netplan generate"
exit 1
fi
else
echo "Skipping netplan generate on UC16"
fi
echo "Ensure that network config was stopped and restarted from netplan"
for _ in $(seq 60); do
stopped_after="$("$TESTSTOOLS"/journal-state get-log -u systemd-networkd | grep -c 'Stopped Network Service.' || true)"
started_after="$("$TESTSTOOLS"/journal-state get-log -u systemd-networkd | grep -c 'Started Network Service.' || true)"
if [ "$stopped_after" -gt "$stopped_before" ] && \
[ "$started_after" -gt "$started_before" ] ; then
break
fi
sleep 1
done
echo "Ensure that the number of network restarts is greater after netplan apply was run"
[ "$stopped_after" -gt "$stopped_before" ] && [ "$started_after" -gt "$started_before" ]
if os.query is-core16; then
echo "Skipping Ubuntu Core 16 which does not have Info D-Bus method"
exit 0
fi
echo "Disconnecting network-setup-control to test network-setup-observe"
snap disconnect netplan-snap:network-setup-control
echo "The network-setup-observe interface is disconnected by default"
snap connections netplan-snap | MATCH 'network-setup-observe +netplan-snap:network-setup-observe +- +-'
echo "Running netplan info via D-Bus without network-setup-observe fails"
if netplan-snap.netplan-info; then
echo "Expected access denied error for netplan info via D-Bus"
exit 1
fi
echo "When the interface is connected"
snap connect netplan-snap:network-setup-observe
echo "Running netplan info via D-Bus now works"
if ! netplan-snap.netplan-info; then
echo "Unexpected error running netplan info via D-Bus"
exit 1
fi
snap remove netplan-snap
done
|