3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2025-05-01 21:37:22 +02:00

autotests: Remove unneded loops

The hostapd_map dictionary is indexed by the interface name so there's
no point iterating over it to find that entry whose name matches, we can
look up by the name directly.  Simplify code.
This commit is contained in:
Andrew Zaborowski 2019-04-20 22:29:02 +02:00 committed by Denis Kenzior
parent e13c749d1e
commit 0a196025f2

View File

@ -29,9 +29,7 @@ hostapd_map = {ifname: intf for wname, wiphy in wiphy_map.items()
class HostapdCLI: class HostapdCLI:
def __init__(self, interface): def __init__(self, interface):
self.ifname = interface.name self.ifname = interface.name
self.ctrl_interface = interface.ctrl_interface self.socket_path = os.path.dirname(interface.ctrl_interface)
self.socket_path = os.path.dirname(self.ctrl_interface)
self.cmdline = 'hostapd_cli -p"' + self.socket_path + '" -i"' + \ self.cmdline = 'hostapd_cli -p"' + self.socket_path + '" -i"' + \
self.ifname + '"' self.ifname + '"'
@ -106,14 +104,12 @@ class HostapdCLI:
def get_config_value(self, key): def get_config_value(self, key):
# first find the right config file # first find the right config file
for wname in hostapd_map: with open(hostapd_map[self.ifname].config, 'r') as f:
if wname == self.ifname: # read in config file and search for key
with open(hostapd_map[wname].config, 'r') as f: cfg = f.read()
# read in config file and search for key match = re.search(r'%s=.*' % key, cfg)
cfg = f.read() if match:
match = re.search(r'%s=.*' % key, cfg) return match.group(0).split('=')[1]
if match:
return match.group(0).split('=')[1]
return None return None
def get_freq(self): def get_freq(self):
@ -123,16 +119,12 @@ class HostapdCLI:
''' '''
Ungracefully kill and restart hostapd Ungracefully kill and restart hostapd
''' '''
for wname in wiphy.wiphy_map: intf = hostapd_map[self.ifname]
name = wiphy.wiphy_map[wname] os.system('killall -9 hostapd')
intf = list(name.values())[0] os.system('ifconfig %s down' % intf.name)
if intf.use == 'hostapd': os.system('ifconfig %s up' % intf.name)
os.system('killall -9 hostapd') os.system('hostapd -g %s -i %s %s &' %
os.system('ifconfig %s down' % intf.name) (intf.ctrl_interface, intf.name, intf.config))
os.system('ifconfig %s up' % intf.name)
os.system('hostapd -g %s -i %s %s &' %
(intf.ctrl_interface, intf.name, intf.config))
break
# set flag so hostapd can be killed after the test # set flag so hostapd can be killed after the test
self._hostapd_restarted = True self._hostapd_restarted = True