autotests: Support multiple hostapd instances in HostapdCLI

Make the HostapdCLI class non-static so that each objects corresponds
to a hostapd instance on one network interface (this is independent of
whether the AP instances use one or separate hostapd processes)
This commit is contained in:
Andrew Zaborowski 2017-03-26 03:16:53 +02:00 committed by Denis Kenzior
parent 76339a8184
commit c72cd38e76
4 changed files with 32 additions and 10 deletions

View File

@ -10,6 +10,7 @@ from iwd import DeviceState
from iwd import NetworkType
from hostapd import HostapdCLI
from hostapd import hostapd_map
class Test(unittest.TestCase):
@ -20,6 +21,9 @@ class Test(unittest.TestCase):
self.assertIsNotNone(devices)
device = devices[0]
hostapd_if = list(hostapd_map.values())[0]
hostapd = HostapdCLI(hostapd_if)
device.scan()
condition = 'not obj.scanning'
@ -33,7 +37,7 @@ class Test(unittest.TestCase):
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition)
HostapdCLI.deauthenticate(device.address)
hostapd.deauthenticate(device.address)
condition = 'obj.state == DeviceState.connecting'
wd.wait_for_object_condition(device, condition)

View File

@ -9,6 +9,7 @@ from iwd import IWD
from iwd import DeviceState
from hostapd import HostapdCLI
from hostapd import hostapd_map
class Test(unittest.TestCase):
@ -32,7 +33,10 @@ class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
HostapdCLI.wps_push_button()
cls.hostapd_if = list(hostapd_map.values())[0]
cls.hostapd = HostapdCLI(cls.hostapd_if)
cls.hostapd.wps_push_button()
@classmethod
def tearDownClass(cls):

View File

@ -9,6 +9,7 @@ from iwd import IWD
from iwd import DeviceState
from hostapd import HostapdCLI
from hostapd import hostapd_map
class Test(unittest.TestCase):
@ -32,7 +33,10 @@ class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
HostapdCLI.wps_push_button()
cls.hostapd_if = list(hostapd_map.values())[0]
cls.hostapd = HostapdCLI(cls.hostapd_if)
cls.hostapd.wps_push_button()
@classmethod
def tearDownClass(cls):

View File

@ -1,15 +1,25 @@
#!/usr/bin/python3
import os
import os, os.path
import wiphy
hostapd_map = {ifname: intf for wname, wiphy in wiphy.wiphy_map.items()
for ifname, intf in wiphy.items() if intf.use == 'hostapd'}
class HostapdCLI:
def __init__(self, interface):
self.ifname = interface.name
self.ctrl_interface = interface.ctrl_interface
@staticmethod
def wps_push_button():
os.system('hostapd_cli wps_pbc')
socket_path = os.path.dirname(self.ctrl_interface)
@staticmethod
def deauthenticate(client_address):
os.system('hostapd_cli deauthenticate ' + client_address)
self.cmdline = 'hostapd_cli -p"' + socket_path + '" -i"' + \
self.ifname + '"'
def wps_push_button(self):
os.system(self.cmdline + ' wps_pbc')
def deauthenticate(self, client_address):
os.system(self.cmdline + ' deauthenticate ' + client_address)
@staticmethod
def kill_all():