summaryrefslogtreecommitdiff
path: root/tools/test-networkmanager-service.py
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-05-15 16:20:00 +0200
committerThomas Haller <thaller@redhat.com>2018-05-24 16:40:17 +0200
commitd424de10bf6d2228d36dadf3568a74a3e505e647 (patch)
treea3f35382886430fd2aac3a85fe6a2e3c86ff784b /tools/test-networkmanager-service.py
parentc834a8e822a4201c3d18c4c28b2305b292c70f1e (diff)
downloadNetworkManager-d424de10bf6d2228d36dadf3568a74a3e505e647.tar.gz
clients/tests: add SetProperties operation to test-networkmanager-service.py stub
It is a hook to set one or several D-Bus properties at once. Properties that are to be set-able, have to be whitelisted in the stub.
Diffstat (limited to 'tools/test-networkmanager-service.py')
-rwxr-xr-xtools/test-networkmanager-service.py59
1 files changed, 54 insertions, 5 deletions
diff --git a/tools/test-networkmanager-service.py b/tools/test-networkmanager-service.py
index cb045c13a1..9b4d3c8c29 100755
--- a/tools/test-networkmanager-service.py
+++ b/tools/test-networkmanager-service.py
@@ -160,11 +160,40 @@ class ExportedObj(dbus.service.Object):
return self._dbus_interface_get_property(self._dbus_interface_get(dbus_iface),
propname)
- def _dbus_property_set(self, dbus_iface, propname, value):
- dbus_interface = self._dbus_interface_get(dbus_iface)
- prop = self._dbus_interface_get_property(dbus_interface)
- assert propname in prop
- prop[propname] = value
+ def _dbus_property_set(self, dbus_iface, propname, value, allow_detect_dbus_iface = False, dry_run = False):
+ if allow_detect_dbus_iface and not dbus_iface:
+ props = None
+ for p, dbus_interface in self._dbus_ifaces.items():
+ if propname in dbus_interface.props:
+ if props is not None:
+ raise TestError("Cannot uniquely find the property '%s' on object '%s'" % (propname, self.path))
+ props = dbus_interface.props
+ dbus_iface = p
+ if props is None:
+ raise TestError("Cannot find the property '%s' on object '%s'" % (propname, self.path))
+ else:
+ try:
+ dbus_interface = self._dbus_interface_get(dbus_iface)
+ props = self._dbus_interface_get_property(dbus_interface)
+ except:
+ if dry_run:
+ raise TestError("No interface '%s' on '%s'" % (dbus_iface, self.path))
+ raise
+
+ if dry_run:
+ if propname not in props:
+ raise TestError("No property '%s' on '%s' on '%s'" % (propname, dbus_iface, self.path))
+
+ if isinstance(self, ActiveConnection) \
+ and dbus_iface == 'org.freedesktop.NetworkManager.Connection.Active' \
+ and propname == 'State':
+ return
+ else:
+ raise TestError("Cannot set property '%s' on '%s' on '%s' via D-Bus" % (propname, dbus_iface, self.path))
+
+ assert propname in props
+
+ props[propname] = value
self._dbus_property_notify(dbus_iface, propname)
def _dbus_property_notify(self, dbus_iface, propname):
@@ -942,6 +971,20 @@ class NetworkManager(ExportedObj):
def FindConnections(self, args):
return [(c.path, c.get_uuid(), c.get_id()) for c in gl.settings.find_connections(**args)]
+ @dbus.service.method(IFACE_TEST, in_signature='a(oa(sa(sv)))', out_signature='')
+ def SetProperties(self, all_args):
+ for i in [0, 1]:
+ for path, iface_args in all_args:
+ o = gl.object_manager.find_object(path)
+ if o is None:
+ raise TestError("Object %s does not exist" % (path))
+ for iface_name, args in iface_args:
+ for propname, value in args:
+ o._dbus_property_set(iface_name, propname, value,
+ allow_detect_dbus_iface = True,
+ dry_run = (i == 0))
+
+
@dbus.service.method(IFACE_TEST, in_signature='sa{sv}', out_signature='o')
def AddObj(self, class_name, args):
if class_name in ['WiredDevice', 'WifiDevice']:
@@ -1341,6 +1384,12 @@ class ObjectManager(dbus.service.Object):
dbus.service.Object.__init__(self, gl.bus, object_path)
self.objs = []
+ def find_object(self, path):
+ for o in self.objs:
+ if path == o.path:
+ return o
+ return None
+
def add_object(self, obj):
self.objs.append(obj)
self.InterfacesAdded(obj.path, obj.get_managed_ifaces())