Skip to content

Commit 7b9dfd7

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

File tree

10 files changed

+296
-0
lines changed

10 files changed

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