commit cb7e9b58851ded285a66ab5b4ef699d3f7de5889
parent 1a0148617077868d35ac775449a88fde7d69749e
Author: James Prestwood <prestwoj@gmail.com>
Date: Thu, 26 Aug 2021 13:33:32 -0700
auto-t: hostapd.py: properly implement singleton (per-config)
This shouldn't change any functionality but it is much more convenient
in the cleanup path i.e. nothing special needs to be done.
Diffstat:
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
@@ -5,6 +5,7 @@ import socket
import select
import time
from gi.repository import GLib
+from weakref import WeakValueDictionary
from config import ctx
chan_freq_map = [
@@ -29,7 +30,7 @@ ctrl_count = 0
mainloop = GLib.MainLoop()
class HostapdCLI(object):
- _instances = {}
+ _instances = WeakValueDictionary()
def __new__(cls, config=None, *args, **kwargs):
hapd = ctx.hostapd[config]
@@ -38,8 +39,10 @@ class HostapdCLI(object):
config = hapd.config
if not config in cls._instances.keys():
- cls._instances[config] = object.__new__(cls, *args, **kwargs)
- cls._instances[config]._initialized = False
+ obj = object.__new__(cls, *args, **kwargs)
+ obj._initialized = False
+
+ cls._instances[config] = obj
return cls._instances[config]
@@ -123,13 +126,6 @@ class HostapdCLI(object):
except:
pass
- HostapdCLI._instances[self.config] = None
-
- # Check if this is the final instance
- destroy = len([hapd for hapd in HostapdCLI._instances.values() if hapd is not None]) == 0
- if destroy:
- HostapdCLI._instances = {}
-
def set_value(self, key, value):
cmd = self.cmdline + ['set', key, value]
ctx.start_process(cmd).wait()
diff --git a/tools/test-runner b/tools/test-runner
@@ -541,13 +541,6 @@ class Hostapd:
except:
print("Failed to remove %s" % self.global_ctrl_iface)
- for hapd in self.instances:
- if not hapd.cli:
- continue
-
- hapd.cli._instances[hapd.config] = None
- hapd.cli = None
-
self.instances = None
# Hostapd may have already been stopped