summaryrefslogtreecommitdiff
path: root/tools/test-networkmanager-service.py
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-05-06 08:51:26 +0200
committerThomas Haller <thaller@redhat.com>2018-05-11 16:51:20 +0200
commit9628aabc2fbf9315eb9c87478da1588c72d8b44c (patch)
treee6eb56b0d25e50d009b79f880ba910677def9e9d /tools/test-networkmanager-service.py
parent3934a2c392e8d6c600b211afee871989a338a1fe (diff)
downloadNetworkManager-9628aabc2fbf9315eb9c87478da1588c72d8b44c.tar.gz
tests: use libnm via pygobject in tools/test-networkmanager-service.py
tools/test-networkmanager-service.py is our NetworkManager stub server. NetworkManager uses libnm(-core) heavily, for example to decide whether a connection verifies (nm_connection_verify()) and for normalizing connections (nm_connection_normalize()). If the stub server wants to mimic NetworkManager, it also must use these function. Luckily, we already can do so, by loading libnm using python GObject introspection. We already correctly set GI_TYPELIB_PATH search path, so that the correct libnm is loaded -- provided that we build with introspection enabled. We still need to gracefully fail, if starting the stub server fails. That requries some extra effort. If the stub server notices that something is missing, it shall exit with status 77. That will cause the tests to g_test_skip().
Diffstat (limited to 'tools/test-networkmanager-service.py')
-rwxr-xr-xtools/test-networkmanager-service.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/tools/test-networkmanager-service.py b/tools/test-networkmanager-service.py
index 68097778ea..17bd7e28c0 100755
--- a/tools/test-networkmanager-service.py
+++ b/tools/test-networkmanager-service.py
@@ -3,8 +3,18 @@
from __future__ import print_function
-from gi.repository import GLib
import sys
+
+import gi
+from gi.repository import GLib
+
+try:
+ gi.require_version('NM', '1.0')
+ from gi.repository import NM
+except Exception as e:
+ print("Cannot load gi.NM: %s" % (str(e)))
+ sys.exit(77)
+
import dbus
import dbus.service
import dbus.mainloop.glib