aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-05-29 04:13:58 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2017-05-29 04:32:13 +0200
commit4d688c2faf2eb780143d4600450df6f7c3664dc2 (patch)
tree2f76f5c08de20837909fd02f6fc84455445aa5aa
parent896f08f6ab275e60104d2a442b8d1040ce61ca76 (diff)
fix multi-suite runs: implement modem cleanup
After a suite was done, the modem object would linger. If two suites were run consecutively, the first suite's modem objects would still log incoming SMS. Add an object cleanup mechanism in the SuiteRun class. Start by adding a cleanup() to the Modem object and subscribing created modems there. Move the modem_obj() function into SuiteRun, there is no use of it being separate, and it makes for better logging. Change-Id: I0048d33e661d683a263c98128cd5c38b8d897dab
-rw-r--r--src/osmo_gsm_tester/ofono_client.py9
-rw-r--r--src/osmo_gsm_tester/suite.py22
2 files changed, 25 insertions, 6 deletions
diff --git a/src/osmo_gsm_tester/ofono_client.py b/src/osmo_gsm_tester/ofono_client.py
index 9425671..c5ae1ff 100644
--- a/src/osmo_gsm_tester/ofono_client.py
+++ b/src/osmo_gsm_tester/ofono_client.py
@@ -98,11 +98,14 @@ class ModemDbusInteraction(log.Origin):
# { I_SMS: ( token1, token2, ... ), }
self.connected_signals = util.listdict()
- def __del__(self):
+ def cleanup(self):
self.unwatch_interfaces()
for interface_name in list(self.connected_signals.keys()):
self.remove_signals(interface_name)
+ def __del__(self):
+ self.cleanup()
+
def get_new_dbus_obj(self):
return systembus_get(self.modem_path)
@@ -268,6 +271,10 @@ class Modem(log.Origin):
}
self.dbus.watch_interfaces()
+ def cleanup(self):
+ self.dbus.cleanup()
+ self.dbus = None
+
def properties(self, *args, **kwargs):
'''Return a dict of properties on this modem. For the actual arguments,
see ModemDbusInteraction.properties(), which this function calls. The
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index 6a1796f..75c461e 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -174,6 +174,7 @@ class SuiteRun(log.Origin):
trial = None
resources_pool = None
reserved_resources = None
+ objects_to_clean_up = None
_resource_requirements = None
_config = None
_processes = None
@@ -186,6 +187,16 @@ class SuiteRun(log.Origin):
self.set_log_category(log.C_TST)
self.resources_pool = resource.ResourcesPool()
+ def register_for_cleanup(self, *obj):
+ assert all([hasattr(o, 'cleanup') for o in obj])
+ self.objects_to_clean_up = self.objects_to_clean_up or []
+ self.objects_to_clean_up.extend(obj)
+
+ def objects_cleanup(self):
+ while self.objects_to_clean_up:
+ obj = self.objects_to_clean_up.pop()
+ obj.cleanup()
+
def mark_start(self):
self.tests = []
self.start_timestamp = time.time()
@@ -248,6 +259,7 @@ class SuiteRun(log.Origin):
# base exception is raised. Make sure to stop processes in this
# finally section. Resources are automatically freed with 'atexit'.
self.stop_processes()
+ self.objects_cleanup()
self.free_resources()
event_loop.unregister_poll_func(self.poll)
self.duration = time.time() - self.start_timestamp
@@ -306,7 +318,11 @@ class SuiteRun(log.Origin):
return bts_obj(self, self.reserved_resources.get(resource.R_BTS))
def modem(self):
- return modem_obj(self.reserved_resources.get(resource.R_MODEM))
+ conf = self.reserved_resources.get(resource.R_MODEM)
+ self.dbg('create Modem object', conf=conf)
+ modem = ofono_client.Modem(conf)
+ self.register_for_cleanup(modem)
+ return modem
def modems(self, count):
l = []
@@ -398,8 +414,4 @@ def bts_obj(suite_run, conf):
raise RuntimeError('No such BTS type is defined: %r' % bts_type)
return bts_class(suite_run, conf)
-def modem_obj(conf):
- log.dbg(None, None, 'create Modem object', conf=conf)
- return ofono_client.Modem(conf)
-
# vim: expandtab tabstop=4 shiftwidth=4