All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] auto-t: hostapd.py: remove _hostapd_restarted concept
@ 2021-08-16 16:04 James Prestwood
  2021-08-16 16:33 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: James Prestwood @ 2021-08-16 16:04 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2379 bytes --]

The destructor was trying to do more than the scope of a destructor
by trying to handle this single case of hostapd being restarted.

Instead we can simply pass a keyword argument 'reinit' to the
constructor to tell it to reinitialize everything. And as for killing
hostapd this can be done in ungraceful_restart itself rather than
trying to handle it in the destructor.
---
 autotests/util/hostapd.py | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
index aabc997b..8b81d467 100644
--- a/autotests/util/hostapd.py
+++ b/autotests/util/hostapd.py
@@ -43,10 +43,10 @@ class HostapdCLI(object):
 
         return cls._instances[config]
 
-    def _init_hostapd(self, config):
+    def _init_hostapd(self, config, reinit=False):
         global ctrl_count
 
-        if self._initialized:
+        if self._initialized and not reinit:
             return
 
         self._initialized = True
@@ -60,9 +60,6 @@ class HostapdCLI(object):
 
         hapd = ctx.hostapd[config]
 
-        if not hasattr(self, '_hostapd_restarted'):
-            self._hostapd_restarted = False
-
         self.interface = hapd.intf
         self.config = hapd.config
 
@@ -131,12 +128,6 @@ class HostapdCLI(object):
         except:
             pass
 
-        if self._hostapd_restarted:
-            ctx.stop_process(ctx.hostapd.process, force)
-
-            self.interface.set_interface_state('down')
-            self.interface.set_interface_state('up')
-
     def __del__(self):
         self._del_hostapd()
 
@@ -215,8 +206,10 @@ class HostapdCLI(object):
         '''
             Ungracefully kill and restart hostapd
         '''
-        # set flag so hostapd can be killed after the test
-        self._hostapd_restarted = True
+        ctx.stop_process(ctx.hostapd.process, True)
+
+        self.interface.set_interface_state('down')
+        self.interface.set_interface_state('up')
 
         self._del_hostapd(force=True)
 
@@ -226,7 +219,7 @@ class HostapdCLI(object):
         time.sleep(1)
 
         # New hostapd process, so re-init
-        self._init_hostapd(config=self.config)
+        self._init_hostapd(config=self.config, reinit=True)
 
     def req_beacon(self, addr, request):
         '''
-- 
2.31.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] auto-t: hostapd.py: remove _hostapd_restarted concept
  2021-08-16 16:04 [PATCH] auto-t: hostapd.py: remove _hostapd_restarted concept James Prestwood
@ 2021-08-16 16:33 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-08-16 16:33 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 613 bytes --]

Hi James,

On 8/16/21 11:04 AM, James Prestwood wrote:
> The destructor was trying to do more than the scope of a destructor
> by trying to handle this single case of hostapd being restarted.
> 
> Instead we can simply pass a keyword argument 'reinit' to the
> constructor to tell it to reinitialize everything. And as for killing
> hostapd this can be done in ungraceful_restart itself rather than
> trying to handle it in the destructor.
> ---
>   autotests/util/hostapd.py | 21 +++++++--------------
>   1 file changed, 7 insertions(+), 14 deletions(-)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-16 16:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 16:04 [PATCH] auto-t: hostapd.py: remove _hostapd_restarted concept James Prestwood
2021-08-16 16:33 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.