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: new test for interface network status #4221
Merged
mvo5
merged 16 commits into
snapcore:master
from
sergiocazzolato:tests-interface-network-status
Dec 11, 2017
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7043253
Adding new test for network status interface
sergiocazzolato 0a181eb
Fix on how snaps are installed
sergiocazzolato de24b0e
Connecting interface manually
sergiocazzolato b9d89cf
Making provider to work
sergiocazzolato b849b07
Fix snap to allow interface connection
sergiocazzolato 90fe4e0
Merge branch 'master' into tests-interface-network-status
sergiocazzolato 23e4366
Removing ubuntu core from execution
sergiocazzolato 10b8b4b
Fix test issue when plug is disconnected
sergiocazzolato 6219aaa
Removing not needed check
sergiocazzolato f7eea97
Minor change in comment
sergiocazzolato 4f02a04
Changes in python code for snap and descriptions of the test
sergiocazzolato 67319a0
Removing call to dbus
sergiocazzolato adb3e16
Fix on dbus service
sergiocazzolato 0640828
Merge branch 'master' into tests-interface-network-status
sergiocazzolato 1bdd83b
Removing ubuntu-core from test execution
sergiocazzolato 8575129
Wait until the dbus name is properly reserved
sergiocazzolato
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,31 @@ | ||
| +#!/usr/bin/env python3 | ||
| + | ||
| +import dbus | ||
| +import os | ||
| +import sys | ||
| + | ||
| +INTERFACE = 'com.ubuntu.connectivity1.NetworkingStatus' | ||
| +PATH = '/com/ubuntu/connectivity1/NetworkingStatus' | ||
| + | ||
| + | ||
| +def _get_obj(): | ||
| + return dbus.SystemBus().get_object(INTERFACE, PATH) | ||
| + | ||
| + | ||
| +def get_version(): | ||
| + obj = _get_obj() | ||
| + return obj.GetVersion(dbus_interface=INTERFACE) | ||
| + | ||
| + | ||
| +def get_state(): | ||
| + obj = _get_obj() | ||
| + return obj.GetState(dbus_interface=INTERFACE) | ||
| + | ||
| + | ||
| +if __name__ == "__main__": | ||
| + if len(sys.argv) > 1 and sys.argv[1] == "GetState": | ||
| + res = get_state() | ||
| + else: | ||
| + res = get_version() | ||
| + | ||
| + print(res) |
| @@ -0,0 +1,33 @@ | ||
| +#!/usr/bin/env python3 | ||
| + | ||
| +from gi.repository import GLib | ||
| +import dbus | ||
| +import dbus.service | ||
| + | ||
| +from dbus.mainloop.glib import DBusGMainLoop | ||
| + | ||
| +INTERFACE = 'com.ubuntu.connectivity1.NetworkingStatus' | ||
| +PATH = '/com/ubuntu/connectivity1/NetworkingStatus' | ||
| + | ||
| +DBusGMainLoop(set_as_default=True) | ||
| + | ||
| + | ||
| +class DBusProvider(dbus.service.Object): | ||
| + def __init__(self): | ||
| + bus = dbus.SystemBus() | ||
| + bus_name = dbus.service.BusName(INTERFACE, bus=bus) | ||
| + dbus.service.Object.__init__(self, bus_name, PATH) | ||
| + | ||
| + @dbus.service.method(dbus_interface=INTERFACE, out_signature="s") | ||
| + def GetVersion(self): | ||
| + return "my-ap-version" | ||
| + | ||
| + @dbus.service.method(dbus_interface=INTERFACE, out_signature="s") | ||
| + def GetState(self): | ||
| + return "my-ap-state" | ||
| + | ||
| + | ||
| +if __name__ == "__main__": | ||
| + DBusProvider() | ||
| + loop = GLib.MainLoop() | ||
| + loop.run() |
| @@ -0,0 +1,26 @@ | ||
| +name: test-snapd-network-status-provider | ||
| +version: 1.0 | ||
| +summary: Basic network status provider snap | ||
| +description: A basic snap declaring an network status slot | ||
| +confinement: strict | ||
| +grade: stable | ||
| + | ||
| +apps: | ||
| + provider: | ||
| + command: wrapper | ||
| + slots: [network-status-test] | ||
| + consumer: | ||
| + command: consumer | ||
| + plugs: [network-status] | ||
| + | ||
| +slots: | ||
| + network-status-test: | ||
| + interface: network-status | ||
| + | ||
| +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 |
| @@ -0,0 +1,67 @@ | ||
| +summary: Ensure that the network-status interface works. | ||
| + | ||
| +details: | | ||
| + The network-status interface allows a snap to monitor network connection status. | ||
| + | ||
| + A snap which defines the network-status plug must be shown in the interfaces list. | ||
| + The plug is autoconnected on install and, as usual, must be able to be disconnect/reconnect. | ||
| + | ||
| + The snap is also declaring a plug on this interface must be able to ask for its status. | ||
| + | ||
| +# dbus-launch not supported in ubuntu-core | ||
| +systems: [-ubuntu-core-16-*] | ||
| + | ||
| +prepare: | | ||
| + . "$TESTSLIB/dbus.sh" | ||
| + . "$TESTSLIB/dirs.sh" | ||
| + | ||
| + echo "Given a snap declaring a plug on the network-status interface is installed" | ||
| + snap install test-snapd-network-status-provider | ||
| + | ||
| + echo "And the provider dbus loop is started" | ||
| + start_dbus_unit $SNAP_MOUNT_DIR/bin/test-snapd-network-status-provider.provider | ||
| + | ||
| +restore: | | ||
| + rm -f getstate.error | ||
| + | ||
| + . "$TESTSLIB/dbus.sh" | ||
| + stop_dbus_unit | ||
| + | ||
| +execute: | | ||
| + CONNECTED_PATTERN="^test-snapd-network-status-provider:network-status-test +test-snapd-network-status-provider:network-status" | ||
| + DISCONNECTED_PATTERN="^- +test-snapd-network-status-provider:network-status$" | ||
| + | ||
| + echo "The interface is connected by default" | ||
|
|
||
| + snap interfaces | MATCH "$CONNECTED_PATTERN" | ||
| + | ||
| + echo "Then wait until the dbus name is properly reserved" | ||
| + for i in $(seq 10); do | ||
stolowski
Contributor
|
||
| + if ! test-snapd-network-status-provider.consumer GetVersion | MATCH "my-ap-version"; then | ||
| + sleep 1 | ||
| + else | ||
| + break | ||
| + fi | ||
| + done | ||
| + | ||
| + echo "Check the network-status is working from the consumer app in the snap" | ||
| + test-snapd-network-status-provider.consumer GetState | MATCH "my-ap-state" | ||
| + test-snapd-network-status-provider.consumer GetVersion | MATCH "my-ap-version" | ||
stolowski
Contributor
|
||
| + | ||
| + if [ "$(snap debug confinement)" = partial ] ; then | ||
| + exit 0 | ||
| + fi | ||
| + | ||
| + echo "When the plug is disconnected" | ||
| + snap disconnect test-snapd-network-status-provider:network-status test-snapd-network-status-provider:network-status-test | ||
| + snap interfaces | MATCH "$DISCONNECTED_PATTERN" | ||
| + | ||
| + echo "And the snap state cannot be accessed" | ||
| + if test-snapd-network-status-provider.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 | ||
| + | ||
| + echo "When the plug is re-connected the interfaces show the connection" | ||
| + snap connect test-snapd-network-status-provider:network-status test-snapd-network-status-provider:network-status-test | ||
| + snap interfaces | MATCH "$CONNECTED_PATTERN" | ||
Newline.