From 5c12651e4ea53a2e55bda754b870c983fe003945 Mon Sep 17 00:00:00 2001 From: bharnden <32446120+bharnden@users.noreply.github.com> Date: Thu, 24 Oct 2019 13:05:02 -0700 Subject: [PATCH] updates to session.clear to clear out all configuration data as well, updated session.shutdown to use clear, updated tests to account for this --- daemon/core/api/tlv/corehandlers.py | 12 ++++++++---- daemon/core/emane/emanemanager.py | 1 - daemon/core/emulator/session.py | 15 +++++++++------ daemon/tests/conftest.py | 9 --------- daemon/tests/test_gui.py | 7 +------ 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/daemon/core/api/tlv/corehandlers.py b/daemon/core/api/tlv/corehandlers.py index ffb28073..1e7be162 100644 --- a/daemon/core/api/tlv/corehandlers.py +++ b/daemon/core/api/tlv/corehandlers.py @@ -1092,10 +1092,14 @@ class CoreHandler(socketserver.BaseRequestHandler): if message_type == ConfigFlags.RESET: node_id = config_data.node - self.session.location.reset() - self.session.services.reset() - self.session.mobility.config_reset(node_id) - self.session.emane.config_reset(node_id) + if node_id is not None: + self.session.mobility.config_reset(node_id) + self.session.emane.config_reset(node_id) + else: + self.session.location.reset() + self.session.services.reset() + self.session.mobility.config_reset() + self.session.emane.config_reset() else: raise Exception(f"cant handle config all: {message_type}") diff --git a/daemon/core/emane/emanemanager.py b/daemon/core/emane/emanemanager.py index a66f9de7..f097b7ad 100644 --- a/daemon/core/emane/emanemanager.py +++ b/daemon/core/emane/emanemanager.py @@ -376,7 +376,6 @@ class EmaneManager(ModelManager): with self._emane_node_lock: self._emane_nets.clear() - # don't clear self._ifccounts here; NEM counts are needed for buildxml self.platformport = self.session.options.get_config_int( "emane_platform_port", 8100 ) diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index 2a2c4f11..c950fd4e 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -876,10 +876,15 @@ class Session: :return: nothing """ + self.emane.shutdown() self.delete_nodes() self.distributed.shutdown() self.del_hooks() self.emane.reset() + self.emane.config_reset() + self.location.reset() + self.services.reset() + self.mobility.config_reset() def start_events(self): """ @@ -919,13 +924,11 @@ class Session: self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True) self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True) - # shutdown/cleanup feature helpers - self.emane.shutdown() - self.sdt.shutdown() + # clear out current core session + self.clear() - # remove and shutdown all nodes and tunnels - self.delete_nodes() - self.distributed.shutdown() + # shutdown sdt + self.sdt.shutdown() # remove this sessions working directory preserve = self.options.get_config("preservedir") == "1" diff --git a/daemon/tests/conftest.py b/daemon/tests/conftest.py index adfe3e24..0c60bb2f 100644 --- a/daemon/tests/conftest.py +++ b/daemon/tests/conftest.py @@ -120,10 +120,6 @@ def session(global_session): global_session.set_state(EventTypes.CONFIGURATION_STATE) yield global_session global_session.clear() - global_session.location.reset() - global_session.services.reset() - global_session.mobility.config_reset() - global_session.emane.config_reset() @pytest.fixture @@ -133,11 +129,6 @@ def coretlv(module_coretlv): coreemu.sessions[session.id] = session yield module_coretlv coreemu.shutdown() - session.clear() - session.location.reset() - session.services.reset() - session.mobility.config_reset() - session.emane.config_reset() def pytest_addoption(parser): diff --git a/daemon/tests/test_gui.py b/daemon/tests/test_gui.py index 21c14c2c..fc9d183e 100644 --- a/daemon/tests/test_gui.py +++ b/daemon/tests/test_gui.py @@ -645,14 +645,9 @@ class TestGui: assert len(coretlv.session.nodes) == 1 def test_config_all(self, coretlv): - node = coretlv.session.add_node() message = coreapi.CoreConfMessage.create( MessageFlags.ADD.value, - [ - (ConfigTlvs.OBJECT, "all"), - (ConfigTlvs.NODE, node.id), - (ConfigTlvs.TYPE, ConfigFlags.RESET.value), - ], + [(ConfigTlvs.OBJECT, "all"), (ConfigTlvs.TYPE, ConfigFlags.RESET.value)], ) coretlv.session.location.refxyz = (10, 10, 10)