Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
tests: add autopilot-introspection interface test #3484
Merged
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c9d2bcd
added autopilot-introspection interface test
fgimenez 126df8e
merged master and deconflicted
fgimenez a786ca1
Merge branch 'master' into spread-autopilot
fgimenez 79800b9
address review comments
fgimenez 31c4668
only run strict confinement checks on system supporting it
fgimenez bd79254
address review comments (thanks gustavo)
fgimenez 287d163
merged master
fgimenez 6becb0d
remove unneded package install and remove commands
fgimenez bf78506
address review comments (thanks sergio)
fgimenez 7a1db6d
merged master and addressed review comments
fgimenez 57f06a8
add missing SNAP_MOUNT_DIR replacements
fgimenez db25e3d
merged master and deconflicted
fgimenez aa916ed
removed dbus-x11 uninstalls
fgimenez 122832c
install xdg-utils for opensuse
fgimenez c45c427
remove init_dbus_env
fgimenez bdb8321
merged master and deconflicted
fgimenez 469ba6b
merged master and deconflicted
fgimenez
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,34 @@ | ||
| +#!/bin/bash | ||
| + | ||
| +start_dbus_unit(){ | ||
| + local executable="$1" | ||
| + | ||
| + dbus-launch > dbus.env | ||
| + export $(cat dbus.env) | ||
| + if [[ "$SPREAD_SYSTEM" == ubuntu-14.04-* ]]; then | ||
| + cat <<EOF > /etc/init/dbus-provider.conf | ||
| +env DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS" | ||
| +env DBUS_SESSION_BUS_PID="$DBUS_SESSION_BUS_PID" | ||
| +script | ||
| + $executable | ||
| +end script | ||
| +EOF | ||
| + initctl reload-configuration | ||
| + start dbus-provider | ||
| + else | ||
| + systemd-run --unit dbus-provider \ | ||
| + --setenv=DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \ | ||
| + --setenv=DBUS_SESSION_BUS_PID=$DBUS_SESSION_BUS_PID \ | ||
| + $executable | ||
| + fi | ||
| +} | ||
| + | ||
| +stop_dbus_unit(){ | ||
| + rm -f dbus.env | ||
| + if [[ "$SPREAD_SYSTEM" == ubuntu-14.04-* ]]; then | ||
| + stop dbus-provider | ||
| + rm -f /etc/init/dbus-provider.conf | ||
| + else | ||
| + systemctl stop dbus-provider | ||
| + fi | ||
| +} |
| @@ -0,0 +1,22 @@ | ||
| +#!/usr/bin/env python | ||
| + | ||
| +import dbus | ||
| +import os | ||
| +import sys | ||
| + | ||
| +def _get_obj(): | ||
| + return dbus.SessionBus().get_object("com.canonical.Autopilot.Introspection", "/com/canonical/Autopilot/Introspection") | ||
| + | ||
| +def get_version(): | ||
| + obj = _get_obj() | ||
| + print(obj.GetVersion(dbus_interface="com.canonical.Autopilot.Introspection")) | ||
| + | ||
| +def get_state(): | ||
| + obj = _get_obj() | ||
| + print(obj.GetState(dbus_interface="com.canonical.Autopilot.Introspection")) | ||
| + | ||
| +if __name__ == "__main__": | ||
| + if len(sys.argv) > 1 and sys.argv[1] == "GetState": | ||
| + sys.exit(get_state()) | ||
| + else: | ||
| + sys.exit(get_version()) |
| @@ -0,0 +1,30 @@ | ||
| +#!/usr/bin/env python3 | ||
| + | ||
| +from gi.repository import GLib | ||
| +import dbus | ||
| +import dbus.service | ||
| + | ||
| +from dbus.mainloop.glib import DBusGMainLoop | ||
| + | ||
| +DBusGMainLoop(set_as_default=True) | ||
| + | ||
| +class DBusProvider(dbus.service.Object): | ||
| + def __init__(self): | ||
| + bus = dbus.SessionBus() | ||
| + bus_name = dbus.service.BusName("com.canonical.Autopilot.Introspection", bus=bus) | ||
| + dbus.service.Object.__init__(self, bus_name, "/com/canonical/Autopilot/Introspection") | ||
| + | ||
| + @dbus.service.method(dbus_interface="com.canonical.Autopilot.Introspection", | ||
| + out_signature="s") | ||
| + def GetVersion(self): | ||
| + return "my-ap-version" | ||
| + | ||
| + @dbus.service.method(dbus_interface="com.canonical.Autopilot.Introspection", | ||
| + out_signature="s") | ||
| + def GetState(self): | ||
| + return "my-ap-state" | ||
| + | ||
| +if __name__ == "__main__": | ||
| + DBusProvider() | ||
| + loop = GLib.MainLoop() | ||
| + loop.run() |
| @@ -0,0 +1,28 @@ | ||
| +name: test-snapd-autopilot-consumer | ||
| +version: 1.0 | ||
| +summary: Basic autopilot consumer snap | ||
| +description: A basic snap declaring an autopilot plug | ||
| +confinement: strict | ||
| +grade: stable | ||
| + | ||
| +apps: | ||
| + provider: | ||
| + command: wrapper | ||
| + slots: [autopilot-test] | ||
| + consumer: | ||
| + command: consumer | ||
| + plugs: [autopilot-introspection] | ||
| + | ||
| +slots: | ||
| + autopilot-test: | ||
| + interface: dbus | ||
| + bus: session | ||
| + name: com.canonical.Autopilot.Introspection | ||
| + | ||
| +parts: | ||
| + deps: | ||
| + plugin: python | ||
| + stage-packages: [python3-gi, python3-dbus, gir1.2-glib-2.0] | ||
| + copy: | ||
| + plugin: dump | ||
| + source: . |
| @@ -0,0 +1,3 @@ | ||
| +export GI_TYPELIB_PATH=$SNAP/usr/lib/girepository-1.0:$(ls -d $SNAP/usr/lib/*/girepository-1.0) | ||
| + | ||
| +$SNAP/usr/bin/python3 $SNAP/provider.py | ||
fgimenez
Contributor
|
||
| @@ -0,0 +1,85 @@ | ||
| +summary: Ensure that the autopilot-introspection interface works | ||
| + | ||
| +details: | | ||
| + The autopilot-intrspection interface allows an application to be introspected | ||
| + and export its ui status over DBus. | ||
| + | ||
| + The test uses an snap that declares a plug on autopilot-intrsopection, it | ||
| + needs to request a dbus name on start so that its state can be queried. | ||
| + | ||
| +systems: [-ubuntu-core-16-*] | ||
| + | ||
| +prepare: | | ||
| + . "$TESTSLIB/dirs.sh" | ||
| + | ||
| + echo "Given a snap declaring an autopilot-intrspection plug in installed" | ||
| + snap install --edge test-snapd-autopilot-consumer | ||
| + | ||
| + echo "And the provider dbus loop is started" | ||
| + . "$TESTSLIB/dbus.sh" | ||
| + start_dbus_unit $SNAP_MOUNT_DIR/bin/test-snapd-autopilot-consumer.provider | ||
| + | ||
| +restore: | | ||
| + rm -f *.error | ||
| + . "$TESTSLIB/dbus.sh" | ||
| + stop_dbus_unit | ||
| + | ||
| +execute: | | ||
| + . "$TESTSLIB/dirs.sh" | ||
| + | ||
| + dbus_send(){ | ||
| + local method="$1" | ||
| + echo $(dbus-send --print-reply --dest=com.canonical.Autopilot.Introspection /com/canonical/Autopilot/Introspection com.canonical.Autopilot.Introspection.${method}) | ||
| + } | ||
| + | ||
| + CONNECTED_PATTERN=":autopilot-introspection +test-snapd-autopilot-consumer" | ||
| + DISCONNECTED_PATTERN="^\- +test-snapd-autopilot-consumer:autopilot-introspection" | ||
| + | ||
| + export $(cat dbus.env) | ||
| + | ||
| + echo "Then the plug is disconnected by default" | ||
| + snap interfaces | MATCH "$DISCONNECTED_PATTERN" | ||
| + | ||
| + echo "When the plug is connected" | ||
| + snap connect test-snapd-autopilot-consumer:autopilot-introspection | ||
| + snap interfaces | MATCH "$CONNECTED_PATTERN" | ||
| + | ||
| + echo "Then the dbus name is properly reserved and the snap app version can be introspected" | ||
| + | ||
| + for i in $(seq 10); do | ||
| + if ! dbus_send GetVersion | MATCH "my-ap-version"; then | ||
| + sleep 1 | ||
| + else | ||
| + break | ||
| + fi | ||
| + done | ||
| + $SNAP_MOUNT_DIR/bin/test-snapd-autopilot-consumer.consumer GetVersion | MATCH "my-ap-version" | ||
| + | ||
| + echo "And the snap app state can be intrsopected" | ||
| + $SNAP_MOUNT_DIR/bin/test-snapd-autopilot-consumer.consumer GetState | MATCH "my-ap-state" | ||
| + | ||
| + if [ "$(snap debug confinement)" = none ]; then | ||
| + exit 0 | ||
| + fi | ||
| + | ||
| + echo "=================================" | ||
| + | ||
| + if [ "$(snap debug confinement)" = strict ] ; then | ||
| + echo "When the plug is disconnected" | ||
| + snap disconnect test-snapd-autopilot-consumer:autopilot-introspection | ||
| + snap interfaces | MATCH "$DISCONNECTED_PATTERN" | ||
| + | ||
| + echo "Then the snap version is not introspectable" | ||
| + if $SNAP_MOUNT_DIR/bin/test-snapd-autopilot-consumer.consumer GetVersion 2>${PWD}/getversion.error ; then | ||
| + echo "Expected permission error trying to introspect version with disconnected plug" | ||
| + exit 1 | ||
| + fi | ||
| + MATCH "Permission denied" < getversion.error | ||
| + | ||
| + echo "And the snap state is not introspectable" | ||
| + if $SNAP_MOUNT_DIR/bin/test-snapd-autopilot-consumer.consumer GetState 2>${PWD}/getstate.error; then | ||
| + echo "Expected permission error trying to introspect state with disconnected plug" | ||
| + exit 1 | ||
| + fi | ||
| + MATCH "Permission denied" < getstate.error | ||
| + fi |
Is the wrapper necessary? Can't it leverage "environment:" in snapcraft.yaml?