Skip to content

Commit a5802b1

Browse files
committed
tests/main/layout-content-delayed-effects: spread test
Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
1 parent 271cb16 commit a5802b1

File tree

10 files changed

+297
-0
lines changed

10 files changed

+297
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
src_dir="$1"
4+
dst_dir="$2"
5+
suffix="$3"
6+
7+
if [ -z "$src_dir" ] || [ -z "$dst_dir" ] || [ -z "$suffix" ]; then
8+
echo "Usage: $0 <src-dir> <dst-dir> <suffix-to-patch>"
9+
exit 1
10+
fi
11+
12+
if [ -d "$dst_dir" ]; then
13+
echo "$dst_dir already exists"
14+
exit 1
15+
fi
16+
17+
cp -av "$src_dir" "$dst_dir"
18+
19+
sed -i "s/%SUFF%/$suffix/g" "$dst_dir/meta/snap.yaml"
20+
if [ -f "$dst_dir"/special-content-file ]; then
21+
sed -i "s/%SUFF%/$suffix/g" "$dst_dir"/special-content-file
22+
fi
23+
24+
echo "Generated snap at $dst_dir with patched suffix: $suffix"
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
summary: Exercise update with multiple content connections and observe delayed effects
2+
3+
details: |
4+
Exercise an update where content providers have multiple consumers connected
5+
and observe delayed mount backend side effects in action.
6+
7+
prepare: |
8+
snap install core24
9+
10+
execute: |
11+
# Generate and install a bunch of content consumer and provider snaps, the
12+
# naming pattern is:
13+
# test-snapd-content-consumer-c1, test-snapd-content-consumer-c2, ..
14+
# test-snapd-content-provider-p1, test-snapd-content-provider-p2, ..
15+
for suff in c1 c2 c3; do
16+
./gen-snap test-snapd-content-consumer "test-snapd-content-consumer-$suff" "$suff"
17+
"$TESTSTOOLS"/snaps-state install-local "test-snapd-content-consumer-$suff"
18+
done
19+
20+
for suff in p1 p2 p3; do
21+
./gen-snap test-snapd-content-provider "test-snapd-content-provider-$suff" "$suff"
22+
"$TESTSTOOLS"/snaps-state install-local "test-snapd-content-provider-$suff"
23+
done
24+
25+
"$TESTSTOOLS"/snaps-state install-local test-snapd-content-provider-v2
26+
27+
# prepare modified versions
28+
(
29+
cd test-snapd-content-provider-p1
30+
echo 'content mod p1' > special-content-file
31+
snap pack
32+
)
33+
34+
(
35+
cd test-snapd-content-provider-v2
36+
echo 'special content mod v2' > special-content-file
37+
snap pack
38+
)
39+
40+
# establish some connections
41+
# c1 -> p1, p2
42+
# c2 -> p2
43+
# c3 -> p2, p3
44+
45+
# c1 -> p1
46+
snap connect test-snapd-content-consumer-c1:special-content \
47+
test-snapd-content-provider-p1:special-content
48+
# c1 -> p2
49+
snap connect test-snapd-content-consumer-c1:special-content \
50+
test-snapd-content-provider-p2:special-content
51+
52+
# c1 -> p-v2
53+
snap connect test-snapd-content-consumer-c1:special-content-v2 \
54+
test-snapd-content-provider-v2:special-content-v2
55+
56+
# c2 -> p2
57+
snap connect test-snapd-content-consumer-c2:special-content \
58+
test-snapd-content-provider-p2:special-content
59+
60+
# c3 -> p2
61+
snap connect test-snapd-content-consumer-c3:special-content \
62+
test-snapd-content-provider-p2:special-content
63+
# c3 -> p3
64+
snap connect test-snapd-content-consumer-c3:special-content \
65+
test-snapd-content-provider-p3:special-content
66+
# c3 -> p-v2
67+
snap connect test-snapd-content-consumer-c3:special-content-v2 \
68+
test-snapd-content-provider-v2:special-content-v2
69+
70+
# make sure the mount namespaces are created and assert that the right
71+
# content is visible
72+
test-snapd-content-consumer-c1.app | MATCH "hello from app test-snapd-content-consumer-c1"
73+
# shellcheck disable=SC2016
74+
snap run --shell test-snapd-content-consumer-c1.app -c \
75+
'cat $SNAP/connected-content{,-2,-v2}/special-content-file' | \
76+
tr '\n' ';' | \
77+
MATCH '^(content p1;content p2|content p2;content p1);special content v2;$'
78+
test-snapd-content-consumer-c2.app | MATCH "hello from app test-snapd-content-consumer-c2"
79+
# shellcheck disable=SC2016
80+
snap run --shell test-snapd-content-consumer-c2.app -c \
81+
'cat $SNAP/connected-content/special-content-file' | \
82+
MATCH '^content p2$'
83+
test-snapd-content-consumer-c3.app | MATCH "hello from app test-snapd-content-consumer-c3"
84+
# shellcheck disable=SC2016
85+
snap run --shell test-snapd-content-consumer-c3.app -c \
86+
'cat $SNAP/connected-content{,-2,-v2}/special-content-file' | \
87+
tr '\n' ';' | \
88+
MATCH '^(content p2;content p3|content p3;content p2);special content v2;$'
89+
test -e /run/snapd/ns/test-snapd-content-consumer-c1.mnt
90+
test -e /run/snapd/ns/test-snapd-content-consumer-c2.mnt
91+
test -e /run/snapd/ns/test-snapd-content-consumer-c3.mnt
92+
93+
# update p1, affects test-snapd-content-consumer
94+
echo "Update a snap affecting test-snapd-content-consumer only"
95+
"$TESTSTOOLS"/snaps-state install-local "test-snapd-content-provider-p1"
96+
snap change --last install | tee change.out
97+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c1"' < change.out
98+
# only one Apply effects task
99+
test "$(grep -c 'Apply delayed' < change.out)" = "1"
100+
101+
# no apps were running, so one got discarded
102+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c1.mnt
103+
# but the other 2 remain
104+
test -e /run/snapd/ns/test-snapd-content-consumer-c2.mnt
105+
test -e /run/snapd/ns/test-snapd-content-consumer-c3.mnt
106+
107+
# we observe the modified content (which recreates the mount ns0)
108+
# shellcheck disable=SC2016
109+
snap run --shell test-snapd-content-consumer-c1.app -c \
110+
'cat $SNAP/connected-content{,-2,-v2}/special-content-file' | \
111+
tr '\n' ';' | \
112+
MATCH '^(content mod p1;content p2|content p2;content mod p1);special content v2;$'
113+
114+
# update p2, affects test-snapd-content-consumer{,-c2,-c3}
115+
echo "Update a snap affecting all instances of test-snapd-content-consumer (c1, c2 and c3)"
116+
"$TESTSTOOLS"/snaps-state install-local "test-snapd-content-provider-p2"
117+
snap change --last install | tee change.out
118+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c1"' < change.out
119+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c2"' < change.out
120+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c3"' < change.out
121+
# for all 3 affected snaps
122+
test "$(grep -c 'Apply delayed' < change.out)" = "3"
123+
124+
# all 3 were discarded
125+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c1.mnt
126+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c2.mnt
127+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c3.mnt
128+
129+
# restore
130+
test-snapd-content-consumer-c1.app | MATCH "hello from app test-snapd-content-consumer-c1"
131+
test-snapd-content-consumer-c2.app | MATCH "hello from app test-snapd-content-consumer-c2"
132+
test-snapd-content-consumer-c3.app | MATCH "hello from app test-snapd-content-consumer-c3"
133+
134+
# affects test-snapd-content-consumer-c3 only
135+
echo "Update a snap affecting test-snapd-content-consumer-c3 only"
136+
"$TESTSTOOLS"/snaps-state install-local "test-snapd-content-provider-p3"
137+
snap change --last install | tee change.out
138+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c3"' < change.out
139+
test "$(grep -c 'Apply delayed' < change.out)" = "1"
140+
141+
test -e /run/snapd/ns/test-snapd-content-consumer-c1.mnt
142+
test -e /run/snapd/ns/test-snapd-content-consumer-c2.mnt
143+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c3.mnt
144+
# restore
145+
test-snapd-content-consumer-c3.app | MATCH "hello from app test-snapd-content-consumer-c3"
146+
147+
# update of 2 provider snaps, affects test-snapd-content-consumer{,-c3}, due
148+
# to the following connections:
149+
# c1 -> p1 & p-v2
150+
# c3 -> p-v2
151+
echo "Update a snap affecting test-snapd-content-consumer c1 and c3"
152+
snap install --dangerous \
153+
test-snapd-content-provider-p1/test-snapd-content-provider-p1_*.snap \
154+
test-snapd-content-provider-v2/test-snapd-content-provider-v2_*.snap
155+
snap change --last install | tee change.out
156+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c1"' < change.out
157+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c3"' < change.out
158+
test "$(grep -c 'Apply delayed' < change.out)" = "2"
159+
160+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c1.mnt
161+
test -e /run/snapd/ns/test-snapd-content-consumer-c2.mnt
162+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c3.mnt
163+
164+
# both affected snaps see modified content
165+
# shellcheck disable=SC2016
166+
snap run --shell test-snapd-content-consumer-c1.app -c \
167+
'cat $SNAP/connected-content{,-2,-v2}/special-content-file' | \
168+
tr '\n' ';' | \
169+
MATCH '^(content mod p1;content p2|content p2;content mod p1);special content mod v2;$'
170+
# c3 shows updated content from p-v2
171+
# shellcheck disable=SC2016
172+
snap run --shell test-snapd-content-consumer-c3.app -c \
173+
'cat $SNAP/connected-content{,-2,-v2}/special-content-file' | \
174+
tr '\n' ';' | \
175+
MATCH '^(content p2;content p3|content p3;content p2);special content mod v2;$'
176+
177+
echo "Observe mount namespace update when an application is running"
178+
# another modification
179+
(
180+
cd test-snapd-content-provider-v2
181+
echo 'special content mod v3' > special-content-file
182+
snap pack
183+
)
184+
185+
# restore c3 mount ns
186+
test-snapd-content-consumer-c3.app | MATCH "hello from app test-snapd-content-consumer-c3"
187+
# start application that prevents the mount ns from being discarded
188+
snap run --shell test-snapd-content-consumer-c1.app -c \
189+
'sleep 3600' &
190+
sleeppid=$!
191+
192+
# grab info about the inode of the captured mount namespace
193+
before_inode="$(stat -c '%i:%y' /run/snapd/ns/test-snapd-content-consumer-c1.mnt)"
194+
195+
snap install --dangerous \
196+
test-snapd-content-provider-p1/test-snapd-content-provider-p1_*.snap \
197+
test-snapd-content-provider-v2/test-snapd-content-provider-v2_*.snap
198+
snap change --last install | tee change.out
199+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c1"' < change.out
200+
MATCH 'Done +.* +Apply delayed security backend side effects for snap "test-snapd-content-consumer-c3"' < change.out
201+
test "$(grep -c 'Apply delayed' < change.out)" = "2"
202+
203+
test -e /run/snapd/ns/test-snapd-content-consumer-c1.mnt
204+
test -e /run/snapd/ns/test-snapd-content-consumer-c2.mnt
205+
test ! -e /run/snapd/ns/test-snapd-content-consumer-c3.mnt
206+
207+
after_inode="$(stat -c '%i:%y' /run/snapd/ns/test-snapd-content-consumer-c1.mnt)"
208+
# the mount ns is the same, it hasn't been discarded
209+
test "$before_inode" = "$after_inode"
210+
211+
kill "$sleeppid"
212+
wait || true
213+
214+
# join it to observe updated content
215+
# TODO: the output should be:
216+
# > content mod v1;content p2;special content mod v3;
217+
# however due to a buggy mount ns update new content is not, or shows up at
218+
# connected-content-v2-2, the previously visible content from p2 and p2 is
219+
# messed up as well
220+
# shellcheck disable=SC2016
221+
snap run --shell test-snapd-content-consumer-c1.app -c \
222+
'cat $SNAP/connected-content{,-2,-v2}/special-content-file' | \
223+
tr '\n' ';' | \
224+
MATCH '^.*;special content mod v2;$'
225+
226+
# discard and observe correct content'
227+
snapd.tool exec snap-discard-ns test-snapd-content-consumer-c1
228+
# shellcheck disable=SC2016
229+
snap run --shell test-snapd-content-consumer-c1.app -c \
230+
'cat $SNAP/connected-content{,-2,-v2}/special-content-file' | \
231+
tr '\n' ';' | \
232+
MATCH '^(content mod p1;content p2|content p2;content mod p1);special content mod v3;$'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
echo "hello from app $SNAP_INSTANCE_NAME"

tests/main/layout-content-delayed-effects/test-snapd-content-consumer/connected-content-v2/.gitkeep

Whitespace-only changes.

tests/main/layout-content-delayed-effects/test-snapd-content-consumer/connected-content/.gitkeep

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: test-snapd-content-consumer-%SUFF%
2+
version: 1.0.0
3+
base: core24
4+
5+
apps:
6+
app:
7+
command: bin/app
8+
plugs:
9+
- special-content
10+
11+
plugs:
12+
special-content:
13+
interface: content
14+
target: $SNAP/connected-content
15+
16+
special-content-v2:
17+
interface: content
18+
target: $SNAP/connected-content-v2
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: test-snapd-content-provider-v2
2+
version: 2.0.0
3+
base: core24
4+
5+
slots:
6+
special-content-v2:
7+
interface: content
8+
read:
9+
- /
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
special content v2
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: test-snapd-content-provider-%SUFF%
2+
version: 1.0.0
3+
base: core24
4+
5+
slots:
6+
special-content:
7+
interface: content
8+
read:
9+
- /
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content %SUFF%

0 commit comments

Comments
 (0)