mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-20 09:34:06 +01:00
autotest: Simplify iterating over network objects
Where the code just needs to find all of the network objects, don't look for the device objects first because this only adds overhead. With the structure now having three levels it can be even more confusing, especially in getCurrentlyConnectedNetworkName where the outer loop didn't check for the Device interface. In getNetworkList don't return after the first device's networks are listed.
This commit is contained in:
parent
4ebdf4e2ca
commit
c26b0ad3db
@ -18,19 +18,13 @@ import utility
|
|||||||
def getSecondNetworkToConnect(objectList, firstNetworkName):
|
def getSecondNetworkToConnect(objectList, firstNetworkName):
|
||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
for path in objectList:
|
for path in objectList:
|
||||||
if utility.IWD_DEVICE_INTERFACE not in objectList[path]:
|
if utility.IWD_NETWORK_INTERFACE not in objectList[path]:
|
||||||
continue
|
continue
|
||||||
for path2 in objectList:
|
network = objectList[path][utility.IWD_NETWORK_INTERFACE]
|
||||||
if not path2.startswith(path) or \
|
# skip the first connected network
|
||||||
utility.IWD_NETWORK_INTERFACE not in objectList[path2]:
|
if network["Name"] == firstNetworkName:
|
||||||
continue
|
continue
|
||||||
network = objectList[path2][utility.IWD_NETWORK_INTERFACE]
|
return path
|
||||||
for key in network.keys():
|
|
||||||
if key in ["Name"]:
|
|
||||||
# skip the first connected network
|
|
||||||
if (network[key] == firstNetworkName):
|
|
||||||
continue
|
|
||||||
return path2
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
class TestTwoNetworks(unittest.TestCase):
|
class TestTwoNetworks(unittest.TestCase):
|
||||||
|
@ -27,14 +27,10 @@ def getNetworkList(objects, bus):
|
|||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
networkList = []
|
networkList = []
|
||||||
for path in objects:
|
for path in objects:
|
||||||
if IWD_DEVICE_INTERFACE not in objects[path]:
|
if IWD_NETWORK_INTERFACE not in objects[path]:
|
||||||
continue
|
continue
|
||||||
for path2 in objects:
|
networkList.append(path)
|
||||||
if not path2.startswith(path) or \
|
return networkList
|
||||||
IWD_NETWORK_INTERFACE not in objects[path2]:
|
|
||||||
continue
|
|
||||||
networkList.append(path2)
|
|
||||||
return networkList
|
|
||||||
|
|
||||||
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)
|
||||||
@ -73,11 +69,9 @@ def getNetworkToConnectTo(objects):
|
|||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
networkList = []
|
networkList = []
|
||||||
for path in objects:
|
for path in objects:
|
||||||
for path2 in objects:
|
if IWD_NETWORK_INTERFACE not in objects[path]:
|
||||||
if not path2.startswith(path) or \
|
continue
|
||||||
IWD_NETWORK_INTERFACE not in objects[path2]:
|
return path
|
||||||
continue
|
|
||||||
return path2
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
# return the currently connected device by
|
# return the currently connected device by
|
||||||
@ -102,42 +96,27 @@ 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 = getObjectList(bus)
|
deviceList = getObjectList(bus)
|
||||||
networkList = getNetworkList(deviceList, bus)
|
|
||||||
for path in deviceList:
|
for path in deviceList:
|
||||||
for path2 in deviceList:
|
if IWD_NETWORK_INTERFACE not in deviceList[path]:
|
||||||
if not path2.startswith(path) or \
|
continue
|
||||||
IWD_NETWORK_INTERFACE not in deviceList[path2]:
|
network = deviceList[path][IWD_NETWORK_INTERFACE]
|
||||||
continue
|
# this check is needed in case when we are testing
|
||||||
network = deviceList[path2][IWD_NETWORK_INTERFACE]
|
# connectivity with multiple networks. The previously
|
||||||
for key in network.keys():
|
# connected network will still have the 'Connected' property
|
||||||
name = ""
|
# even though it will be set to 0.
|
||||||
if key in ["Connected"]:
|
if not network["Connected"]: # if "Connected is 0"
|
||||||
# this check is needed in case when we are testing
|
continue
|
||||||
# connectivity with multiple networks. The previously
|
return network["Name"]
|
||||||
# connected network will still have the 'Connected' property
|
|
||||||
# even though it will be set to 0.
|
|
||||||
val = network[key]
|
|
||||||
if network[key] == 0: # if "Connected is 0"
|
|
||||||
continue
|
|
||||||
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(deviceList):
|
def getNetworkName(deviceList):
|
||||||
logger.debug(sys._getframe().f_code.co_name)
|
logger.debug(sys._getframe().f_code.co_name)
|
||||||
for path in deviceList:
|
for path in deviceList:
|
||||||
if IWD_DEVICE_INTERFACE not in deviceList[path]:
|
if IWD_NETWORK_INTERFACE not in deviceList[path]:
|
||||||
continue
|
continue
|
||||||
for path2 in deviceList:
|
network = deviceList[path][IWD_NETWORK_INTERFACE]
|
||||||
if not path2.startswith(path) or \
|
return network["Name"]
|
||||||
IWD_NETWORK_INTERFACE not in deviceList[path2]:
|
|
||||||
continue
|
|
||||||
network = deviceList[path2][IWD_NETWORK_INTERFACE]
|
|
||||||
for key in network.keys():
|
|
||||||
if key in ["Name"]:
|
|
||||||
return network[key]
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def initLogger():
|
def initLogger():
|
||||||
|
Loading…
Reference in New Issue
Block a user