3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 23:09:34 +01:00

autotests: fixed utility after objectManager changes

This commit is contained in:
Rahul Rahul 2016-06-01 11:23:48 -07:00 committed by Denis Kenzior
parent 2b781d544d
commit 39b9f26e44

View File

@ -6,21 +6,26 @@ import logging
import traceback import traceback
# get all the available networks # get all the available networks
def getDeviceList(bus): def getObjectList(bus):
logger.debug(sys._getframe().f_code.co_name) logger.debug(sys._getframe().f_code.co_name)
manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"), manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"),
"net.connman.iwd.Manager") "org.freedesktop.DBus.ObjectManager")
return manager.GetDevices() return manager.GetManagedObjects()
# get all the available networks # get all the available networks
def getNetworkList(devices, bus): def getNetworkList(objects, bus):
logger.debug(sys._getframe().f_code.co_name) logger.debug(sys._getframe().f_code.co_name)
for path in devices: networkList = []
device = dbus.Interface(bus.get_object("net.connman.iwd", path), for path in objects:
"net.connman.iwd.Device") if 'net.connman.iwd.Device' not in objects[path]:
return device.GetNetworks() continue
for path2 in objects:
if not path2.startswith(path) or \
'net.connman.iwd.Network' not in objects[path2]:
continue
networkList.append(path2)
return networkList
# try to connect to the network.
def connect(networkToConnect, self, mainloop, bus): def connect(networkToConnect, self, mainloop, bus):
logger.debug(sys._getframe().f_code.co_name) logger.debug(sys._getframe().f_code.co_name)
logger.debug(" %s", networkToConnect) logger.debug(" %s", networkToConnect)
@ -54,11 +59,15 @@ def disconnect(deviceToDisconnect, mainloop, bus):
return True return True
# get the 1st network found to connect to # get the 1st network found to connect to
def getNetworkToConnectTo(networkList): def getNetworkToConnectTo(objects):
logger.debug(sys._getframe().f_code.co_name) logger.debug(sys._getframe().f_code.co_name)
for networkInfo in networkList: networkList = []
logger.debug(" %s", networkInfo) for path in objects:
return networkInfo for path2 in objects:
if not path2.startswith(path) or \
'net.connman.iwd.Network' not in objects[path2]:
continue
return path2
return "" return ""
# return the currently connected device by # return the currently connected device by
@ -68,10 +77,12 @@ def getCurrentlyConnectedDevice():
bus = dbus.SystemBus() bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"), manager = dbus.Interface(bus.get_object("net.connman.iwd", "/"),
"net.connman.iwd.Manager") "net.connman.iwd.Manager")
devices = manager.GetDevices() objects = getObjectList(bus)
for path in devices: for path in objects:
properties = devices[path] if 'net.connman.iwd.Device' not in objects[path]:
for key in properties.keys(): continue
device = objects[path]['net.connman.iwd.Device']
for key in device.keys():
if key in ["ConnectedNetwork"]: if key in ["ConnectedNetwork"]:
return path return path
return "" return ""
@ -80,44 +91,45 @@ def getCurrentlyConnectedDevice():
def getCurrentlyConnectedNetworkName(): def getCurrentlyConnectedNetworkName():
logger.debug(sys._getframe().f_code.co_name) logger.debug(sys._getframe().f_code.co_name)
bus = dbus.SystemBus() bus = dbus.SystemBus()
deviceList = getDeviceList(bus) deviceList = getObjectList(bus)
networkList = getNetworkList(deviceList, bus) networkList = getNetworkList(deviceList, bus)
for path in networkList: for path in deviceList:
properties = networkList[path] for path2 in deviceList:
for key in properties.keys(): if not path2.startswith(path) or \
'net.connman.iwd.Network' not in deviceList[path2]:
continue
network = deviceList[path2]['net.connman.iwd.Network']
for key in network.keys():
name = ""
if key in ["Connected"]: if key in ["Connected"]:
# this check is needed in case when we are testing # this check is needed in case when we are testing
# connectivity with multiple networks. The previously # connectivity with multiple networks. The previously
# connected network will still have the 'Connected' property # connected network will still have the 'Connected' property
# even though it will be set to 0. # even though it will be set to 0.
if properties["Connected"] == 0: val = network[key]
if network[key] == 0: # if "Connected is 0"
continue continue
return properties["Name"] for key2 in network.keys():
if key2 in ["Name"]:
return network[key2]
return "" return ""
# get name of the network # get name of the network
def getNetworkName(networkList): def getNetworkName(deviceList):
logger.debug(sys._getframe().f_code.co_name) logger.debug(sys._getframe().f_code.co_name)
for network in networkList: for path in deviceList:
properties = networkList[network] if 'net.connman.iwd.Device' not in deviceList[path]:
return properties["Name"] continue
for path2 in deviceList:
if not path2.startswith(path) or \
'net.connman.iwd.Network' not in deviceList[path2]:
continue
network = deviceList[path2]['net.connman.iwd.Network']
for key in network.keys():
if key in ["Name"]:
return network[key]
return "" return ""
# print information about all the networks found
def printNetworkInfo(networkList):
logger.debug(sys._getframe().f_code.co_name)
for path in networkList:
logger.debug(" [ %s ]" % path)
properties = networkList[path]
for key in properties.keys():
if key in ["SSID"]:
val = properties[key]
val = "".join(map(chr, val))
else:
val = properties[key]
logger.info(" %s = %s" % (key, val))
def initLogger(): def initLogger():
global logger global logger
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)