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:
Andrew Zaborowski 2016-07-12 04:13:55 +02:00 committed by Denis Kenzior
parent 4ebdf4e2ca
commit c26b0ad3db
2 changed files with 25 additions and 52 deletions

View File

@ -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"]:
# skip the first connected network
if (network[key] == firstNetworkName):
continue
return path2
network = objectList[path][utility.IWD_NETWORK_INTERFACE]
# skip the first connected network
if network["Name"] == firstNetworkName:
continue
return path
return ""
class TestTwoNetworks(unittest.TestCase):

View File

@ -27,14 +27,10 @@ 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)
return networkList
networkList.append(path)
return networkList
def connect(networkToConnect, self, mainloop, bus):
logger.debug(sys._getframe().f_code.co_name)
@ -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]:
continue
return path2
if IWD_NETWORK_INTERFACE not in objects[path]:
continue
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]:
continue
network = deviceList[path2][IWD_NETWORK_INTERFACE]
for key in network.keys():
name = ""
if key in ["Connected"]:
# 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"
continue
for key2 in network.keys():
if key2 in ["Name"]:
return network[key2]
if IWD_NETWORK_INTERFACE not in deviceList[path]:
continue
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.
if not network["Connected"]: # if "Connected is 0"
continue
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():