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):
|
||||
logger.debug(sys._getframe().f_code.co_name)
|
||||
for path in objectList:
|
||||
if utility.IWD_DEVICE_INTERFACE not in objectList[path]:
|
||||
if utility.IWD_NETWORK_INTERFACE not in objectList[path]:
|
||||
continue
|
||||
for path2 in objectList:
|
||||
if not path2.startswith(path) or \
|
||||
utility.IWD_NETWORK_INTERFACE not in objectList[path2]:
|
||||
continue
|
||||
network = objectList[path2][utility.IWD_NETWORK_INTERFACE]
|
||||
for key in network.keys():
|
||||
if key in ["Name"]:
|
||||
network = objectList[path][utility.IWD_NETWORK_INTERFACE]
|
||||
# skip the first connected network
|
||||
if (network[key] == firstNetworkName):
|
||||
if network["Name"] == firstNetworkName:
|
||||
continue
|
||||
return path2
|
||||
return path
|
||||
return ""
|
||||
|
||||
class TestTwoNetworks(unittest.TestCase):
|
||||
|
@ -27,13 +27,9 @@ def getNetworkList(objects, bus):
|
||||
logger.debug(sys._getframe().f_code.co_name)
|
||||
networkList = []
|
||||
for path in objects:
|
||||
if IWD_DEVICE_INTERFACE not in objects[path]:
|
||||
if IWD_NETWORK_INTERFACE not in objects[path]:
|
||||
continue
|
||||
for path2 in objects:
|
||||
if not path2.startswith(path) or \
|
||||
IWD_NETWORK_INTERFACE not in objects[path2]:
|
||||
continue
|
||||
networkList.append(path2)
|
||||
networkList.append(path)
|
||||
return networkList
|
||||
|
||||
def connect(networkToConnect, self, mainloop, bus):
|
||||
@ -73,11 +69,9 @@ def getNetworkToConnectTo(objects):
|
||||
logger.debug(sys._getframe().f_code.co_name)
|
||||
networkList = []
|
||||
for path in objects:
|
||||
for path2 in objects:
|
||||
if not path2.startswith(path) or \
|
||||
IWD_NETWORK_INTERFACE not in objects[path2]:
|
||||
if IWD_NETWORK_INTERFACE not in objects[path]:
|
||||
continue
|
||||
return path2
|
||||
return path
|
||||
return ""
|
||||
|
||||
# return the currently connected device by
|
||||
@ -102,42 +96,27 @@ def getCurrentlyConnectedNetworkName():
|
||||
logger.debug(sys._getframe().f_code.co_name)
|
||||
bus = dbus.SystemBus()
|
||||
deviceList = getObjectList(bus)
|
||||
networkList = getNetworkList(deviceList, bus)
|
||||
for path in deviceList:
|
||||
for path2 in deviceList:
|
||||
if not path2.startswith(path) or \
|
||||
IWD_NETWORK_INTERFACE not in deviceList[path2]:
|
||||
if IWD_NETWORK_INTERFACE not in deviceList[path]:
|
||||
continue
|
||||
network = deviceList[path2][IWD_NETWORK_INTERFACE]
|
||||
for key in network.keys():
|
||||
name = ""
|
||||
if key in ["Connected"]:
|
||||
network = deviceList[path][IWD_NETWORK_INTERFACE]
|
||||
# this check is needed in case when we are testing
|
||||
# connectivity with multiple networks. The previously
|
||||
# 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"
|
||||
if not network["Connected"]: # if "Connected is 0"
|
||||
continue
|
||||
for key2 in network.keys():
|
||||
if key2 in ["Name"]:
|
||||
return network[key2]
|
||||
return network["Name"]
|
||||
return ""
|
||||
|
||||
# get name of the network
|
||||
def getNetworkName(deviceList):
|
||||
logger.debug(sys._getframe().f_code.co_name)
|
||||
for path in deviceList:
|
||||
if IWD_DEVICE_INTERFACE not in deviceList[path]:
|
||||
if IWD_NETWORK_INTERFACE not in deviceList[path]:
|
||||
continue
|
||||
for path2 in deviceList:
|
||||
if not path2.startswith(path) or \
|
||||
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]
|
||||
network = deviceList[path][IWD_NETWORK_INTERFACE]
|
||||
return network["Name"]
|
||||
return ""
|
||||
|
||||
def initLogger():
|
||||
|
Loading…
Reference in New Issue
Block a user