From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH v2 03/15] auto-t: hostapd.py: update to work with test-runner rewrite
Date: Fri, 28 Aug 2020 09:40:38 -0700 [thread overview]
Message-ID: <20200828164050.1456-4-prestwoj@gmail.com> (raw)
In-Reply-To: <20200828164050.1456-1-prestwoj@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 5683 bytes --]
Before hostapd was initialized using the wiphy_map which has now
gone away. Instead we have a global config module which contains
a single 'ctx'. This is the centeral store for all test information.
This patch converts hostapd.py to lookup instances by already
initialized Hostapd object. The interface parameter was removed
since all tests have been converted to use config= instead.
In addition HostapdCLI was changed to allow no parameters if there
is only a single hostapd instance.
---
autotests/util/hostapd.py | 57 +++++++++++++++++----------------------
1 file changed, 24 insertions(+), 33 deletions(-)
diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
index 0ed4e004..b8cfe231 100644
--- a/autotests/util/hostapd.py
+++ b/autotests/util/hostapd.py
@@ -1,11 +1,11 @@
#!/usr/bin/python3
import os, os.path
-from wiphy import wiphy_map
import re
import socket
import select
import time
from gi.repository import GLib
+from config import ctx
chan_freq_map = [
None,
@@ -28,28 +28,24 @@ chan_freq_map = [
ctrl_count = 0
mainloop = GLib.MainLoop()
-hostapd_map = {ifname: intf for wname, wiphy in wiphy_map.items()
- for ifname, intf in wiphy.interface_map.items()
- if wiphy.use == 'hostapd'}
-
class HostapdCLI:
- def _init_hostapd(self, interface=None, config=None):
+ def _init_hostapd(self, config=None):
global ctrl_count
+ interface = None
+
+ if not config and len(ctx.hostapd.instances) > 1:
+ raise Exception('config must be provided if more than one hostapd instance exists')
- if not interface and not config:
- raise Exception('interface or config must be provided')
+ hapd = ctx.hostapd[config]
- if not interface:
- for intf in hostapd_map.values():
- if intf.config == config:
- interface = intf
- break
+ self.interface = hapd.intf
+ self.config = hapd.config
- if not interface:
+ if not self.interface:
raise Exception('config %s not found' % config)
- self.ifname = interface.name
- self.socket_path = os.path.dirname(interface.ctrl_interface)
+ self.ifname = self.interface.name
+ self.socket_path = os.path.dirname(self.interface.ctrl_interface)
self.cmdline = 'hostapd_cli -p"' + self.socket_path + '" -i"' + \
self.ifname + '"'
@@ -61,6 +57,7 @@ class HostapdCLI:
str(ctrl_count)
self.ctrl_sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.ctrl_sock.bind(self.local_ctrl)
+
self.ctrl_sock.connect(self.socket_path + '/' + self.ifname)
if 'OK' not in self._ctrl_request('ATTACH'):
@@ -68,8 +65,8 @@ class HostapdCLI:
ctrl_count = ctrl_count + 1
- def __init__(self, interface=None, config=None):
- self._init_hostapd(interface, config)
+ def __init__(self, config=None):
+ self._init_hostapd(config)
def wait_for_event(self, event, timeout=10):
global mainloop
@@ -115,15 +112,13 @@ class HostapdCLI:
def _del_hostapd(self, force=False):
self.ctrl_sock.close()
+ os.remove(self.local_ctrl)
if self._hostapd_restarted:
- if force:
- os.system('killall -9 hostapd')
- else:
- os.system('killall hostapd')
+ ctx.stop_process(ctx.hostapd.process, force)
- os.system('ifconfig %s down' % self.ifname)
- os.system('ifconfig %s up' % self.ifname)
+ self.interface.set_interface_state('down')
+ self.interface.set_interface_state('up')
def __del__(self):
self._del_hostapd()
@@ -139,10 +134,7 @@ class HostapdCLI:
def eapol_reauth(self, client_address):
cmd = 'IFNAME=' + self.ifname + ' EAPOL_REAUTH ' + client_address
- s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
- s.connect(self.socket_path + '/' + self.ifname)
- s.sendall(cmd.encode('utf-8'))
- s.close()
+ self.ctrl_sock.sendall(cmd.encode('utf-8'))
def reload(self):
# Seemingly all three commands needed for the instance to notice
@@ -192,7 +184,7 @@ class HostapdCLI:
def get_config_value(self, key):
# first find the right config file
- with open(hostapd_map[self.ifname].config, 'r') as f:
+ with open(self.config, 'r') as f:
# read in config file and search for key
cfg = f.read()
match = re.search(r'%s=.*' % key, cfg)
@@ -200,6 +192,7 @@ class HostapdCLI:
return match.group(0).split('=')[1]
return None
+
def get_freq(self):
return chan_freq_map[int(self.get_config_value('channel'))]
@@ -209,18 +202,16 @@ class HostapdCLI:
'''
# set flag so hostapd can be killed after the test
self._hostapd_restarted = True
- intf = hostapd_map[self.ifname]
self._del_hostapd(force=True)
- os.system('hostapd -g %s -i %s %s &' %
- (intf.ctrl_interface, intf.name, intf.config))
+ ctx.start_hostapd()
# Give hostapd a second to start and initialize the control interface
time.sleep(1)
# New hostapd process, so re-init
- self._init_hostapd(intf)
+ self._init_hostapd(config=self.config)
def req_beacon(self, addr, request):
'''
--
2.21.1
next prev parent reply other threads:[~2020-08-28 16:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-28 16:40 [PATCH v2 00/15] Test Runner rewrite James Prestwood
2020-08-28 16:40 ` [PATCH v2 01/15] auto-t: prepare autotests for test-runner re-write James Prestwood
2020-08-28 16:40 ` [PATCH v2 02/15] auto-t: introduce pure python " James Prestwood
2020-08-28 16:40 ` James Prestwood [this message]
2020-08-28 16:40 ` [PATCH v2 04/15] auto-t: testutil.py: update to work with test-runner rewrite James Prestwood
2020-08-28 16:40 ` [PATCH v2 05/15] auto-t: ofono.py: fix timeout cleanup and wait for service James Prestwood
2020-08-28 16:40 ` [PATCH v2 06/15] auto-t: iwd.py: update to work with test-runner rewrite James Prestwood
2020-08-28 16:40 ` [PATCH v2 07/15] auto-t: iwd.py: fix multiple timeout cleanup issues James Prestwood
2020-08-28 16:40 ` [PATCH v2 08/15] auto-t: remove wiphy.py James Prestwood
2020-08-28 16:40 ` [PATCH v2 09/15] auto-t: fix hidden network test James Prestwood
2020-08-28 16:40 ` [PATCH v2 10/15] auto-t: fix testSAE autoconnect_test.py James Prestwood
2020-08-28 16:40 ` [PATCH v2 11/15] auto-t: skip ofono tests if ofonod isn't running James Prestwood
2020-08-28 16:40 ` [PATCH v2 12/15] auto-t: replace hard-coded interfaces James Prestwood
2020-08-28 16:40 ` [PATCH v2 13/15] auto-t: remove device.wait_for_connected James Prestwood
2020-08-28 16:40 ` [PATCH v2 14/15] tools: post test-runner rewrite cleanup James Prestwood
2020-08-28 16:40 ` [PATCH v2 15/15] doc: update test runner docs James Prestwood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200828164050.1456-4-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox