From 0db0ce43b80abb11225dbf55dc3eb07977a63d6a Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Mon, 29 Jan 2018 10:37:05 -0800 Subject: [PATCH] auto-t: add ungraceful restart to hostapd util For testing SA Query, the autotest needs the ablility to force kill (and restart) hostapd without giving it time to deauth its stations gracefully. A method was added to the HostapdCLI class which does a killall -9 hostapd, resets the wlnX interface, and restarts hostapd with the same arguments as it had before. --- autotests/util/hostapd.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py index d5678107..ed04391d 100644 --- a/autotests/util/hostapd.py +++ b/autotests/util/hostapd.py @@ -15,6 +15,12 @@ class HostapdCLI: self.cmdline = 'hostapd_cli -p"' + socket_path + '" -i"' + \ self.ifname + '"' + self._hostapd_restarted = False + + def __del__(self): + if self._hostapd_restarted: + os.system('killall hostapd') + def wps_push_button(self): os.system(self.cmdline + ' wps_pbc') @@ -66,3 +72,21 @@ class HostapdCLI: @staticmethod def kill_all(): os.system('killall hostapd') + + def ungraceful_restart(self): + ''' + Ungracefully kill and restart hostapd + ''' + for wname in wiphy.wiphy_map: + name = wiphy.wiphy_map[wname] + intf = list(name.values())[0] + if intf.use == 'hostapd': + os.system('killall -9 hostapd') + os.system('ifconfig %s down' % intf.name) + 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 + self._hostapd_restarted = True