From 68ec9eb586a07152bff41b76dff30b235390d1a7 Mon Sep 17 00:00:00 2001 From: Philip Withnall <philip.withnall@collabora.co.uk> Date: Thu, 17 Mar 2016 11:31:20 +0000 Subject: [PATCH] bluez: Refactor test_dun and test_pan to share code This introduces no behavioural changes. Reviewed-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk> Signed-off-by: Philip Withnall <philip.withnall@collabora.co.uk> Differential Revision: https://phabricator.apertis.org/D2310 --- bluez/ubt | 90 +++++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 59 deletions(-) diff --git a/bluez/ubt b/bluez/ubt index 23e36a9..a314046 100755 --- a/bluez/ubt +++ b/bluez/ubt @@ -446,40 +446,41 @@ class PbapDeviceProfileTester(DeviceProfileTester): signal_name="PropertiesChanged", path_keyword='path') + def __test_dun_pan(self, path): + bus = dbus.SystemBus() + + manager = dbus.Interface(bus.get_object("net.connman", "/"), + "net.connman.Manager") + services = manager.GetServices() + + device_name = self._device_obj.Get( + 'org.bluez.Device1', + 'Name', + dbus_interface='org.freedesktop.DBus.Properties') + + path = None + for s in services: + if s[1]["Name"] == device_name: + path = s[0] + break + if not path: + raise + + service = dbus.Interface(bus.get_object("net.connman", path), + "net.connman.Service") + service.Connect(timeout=60000) + url = urllib.request.urlopen("http://connman.net") + f = open(path, 'w') + f.write(url.read(1000000)) + f.close() + service.Disconnect(timeout=60000) + def test_dun(self): TEST_START("DUN GW") try: - bus = dbus.SystemBus() - - manager = dbus.Interface(bus.get_object("net.connman", "/"), - "net.connman.Manager") - services = manager.GetServices() - - device_name = self._device_obj.Get( - 'org.bluez.Device1', - 'Name', - dbus_interface='org.freedesktop.DBus.Properties') - - path = None - for s in services: - if s[1]["Name"] == device_name: - path = s[0] - break - if not path: - raise - - service = dbus.Interface(bus.get_object("net.connman", path), - "net.connman.Service") - service.Connect(timeout=60000) - url = urllib.request.urlopen("http://connman.net") - f = open(BASE_PATH + "/DUN", 'w') - f.write(url.read(1000000)) - f.close() - service.Disconnect(timeout=60000) - + self.__test_dun_pan(BASE_PATH + "/DUN") TEST_PASSED("DUN GW") - except Exception as error: TEST_FAILED("DUN GW: " + str(error)) @@ -489,36 +490,7 @@ class PbapDeviceProfileTester(DeviceProfileTester): TEST_START("PAN NAP") try: - bus = dbus.SystemBus() - - manager = dbus.Interface(bus.get_object("net.connman", "/"), - "net.connman.Manager") - - services = manager.GetServices() - - device_name = self._device_obj.Get( - 'org.bluez.Device1', - 'Name', - dbus_interface='org.freedesktop.DBus.Properties') - - path = None - for s in services: - if s[1]["Name"] == device_name: - path = s[0] - break - if not path: - raise - - service = dbus.Interface(bus.get_object("net.connman", path), - "net.connman.Service") - - service.Connect(timeout=60000) - url = urllib2.urlopen("http://connman.net") - f = open(BASE_PATH + "/PAN", 'w') - f.write(url.read(1000000)) - f.close() - service.Disconnect(timeout=60000) - + self.__test_dun_pan(BASE_PATH + "/PAN") TEST_PASSED("PAN NAP") except Exception as error: TEST_FAILED("PAN NAP: " + str(error)) -- GitLab