-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9132 from jhenstridge/snapctl-is-connected-pid
o/hookstate/ctlcmd: add optional --pid and --apparmor-label arguments to "snapctl is-connected"
- Loading branch information
Showing
12 changed files
with
320 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
summary: Ensure "snapctl is-connected" --pid and --apparmor-label options work. | ||
|
||
prepare: | | ||
tests.cleanup prepare | ||
#shellcheck source=tests/lib/snaps.sh | ||
. "$TESTSLIB"/snaps.sh | ||
install_local test-snap1 | ||
install_local test-snap2 | ||
#shellcheck source=tests/lib/dirs.sh | ||
. "$TESTSLIB"/dirs.sh | ||
case "$SPREAD_SYSTEM" in | ||
fedora-*|arch-*|centos-*) | ||
# although classic snaps do not work out of the box on fedora, | ||
# we still want to verify if the basics do work if the user | ||
# symlinks /snap to $SNAP_MOUNT_DIR themselves | ||
ln -sf $SNAP_MOUNT_DIR /snap | ||
tests.cleanup defer rm -f /snap | ||
;; | ||
esac | ||
restore: | | ||
tests.cleanup restore | ||
execute: | | ||
echo "The test-snap1 service is running" | ||
systemctl is-active snap.test-snap1.svc.service | ||
svc_pid=$(systemctl show --property=MainPID snap.test-snap1.svc.service | cut -d = -f 2) | ||
expect_status() { | ||
expected="$1" | ||
shift | ||
# Temporarily turn off "set -e" so we can check the exit status | ||
set +e; "$@"; local ret=$?; set -e | ||
test "$ret" -eq "$expected" | ||
} | ||
echo "Plugs and slots are initially disconnected" | ||
not test-snap2.snapctl is-connected foo-slot | ||
echo "Disconnected interfaces are not connected to a snap process" | ||
expect_status 1 test-snap2.snapctl is-connected --pid "$svc_pid" foo-slot | ||
echo "Disconnected interfaces are not connected to non-snap process" | ||
expect_status 11 test-snap2.snapctl is-connected --pid 1 foo-slot | ||
echo "Connect interface" | ||
snap connect test-snap1:foo-plug test-snap2:foo-slot | ||
echo "Connected interfaces report as connected to snap process" | ||
test-snap2.snapctl is-connected --pid "$svc_pid" foo-slot | ||
echo "Interfaces still not connected to non-snap process" | ||
expect_status 11 test-snap2.snapctl is-connected --pid 1 foo-slot | ||
if [[ "$(snap debug confinement)" = strict ]]; then | ||
svc_label=$(sed 's/ (.*)$//' < "/proc/$svc_pid/attr/current") | ||
echo "We can detect connected interfaces by AppArmor label too" | ||
test-snap2.snapctl is-connected --apparmor-label "$svc_label" foo-slot | ||
snap disconnect test-snap1:foo-plug test-snap2:foo-slot | ||
expect_status 1 test-snap2.snapctl is-connected --apparmor-label "$svc_label" foo-slot | ||
echo "Non-snap AppArmor labels return a special exit code" | ||
expect_status 11 test-snap2.snapctl is-connected --apparmor-label /usr/bin/evince foo-slot | ||
fi | ||
# The remaining tests rely on classic confinement, so skip Ubuntu Core | ||
if [[ "$SPREAD_SYSTEM" = ubuntu-core-* ]]; then | ||
exit 0 | ||
fi | ||
# We also skip Ubuntu 14.04, since it does not allow us track | ||
# classic confined snap processes (there is no systemd based | ||
# tracking, and they aren't added to a freezer cgroup). | ||
if [[ "$SPREAD_SYSTEM" = ubuntu-14.04-* ]]; then | ||
exit 0 | ||
fi | ||
#shellcheck source=tests/lib/snaps.sh | ||
. "$TESTSLIB"/snaps.sh | ||
install_local_classic test-snap-classic | ||
echo "The test-snap-classic service is running" | ||
systemctl is-active snap.test-snap-classic.svc.service | ||
classic_pid=$(systemctl show --property=MainPID snap.test-snap-classic.svc.service | cut -d = -f 2) | ||
echo "Unconnected classic snaps report a special exit code" | ||
expect_status 10 test-snap2.snapctl is-connected --pid "$classic_pid" foo-slot | ||
echo "But still reports success when connected" | ||
snap connect test-snap-classic:foo-plug test-snap2:foo-slot | ||
test-snap2.snapctl is-connected --pid "$classic_pid" foo-slot |
4 changes: 4 additions & 0 deletions
4
tests/main/snapctl-is-connected-pid/test-snap-classic/bin/service.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
echo "service running" | ||
exec sleep infinity |
Oops, something went wrong.