From 371b020542e8722c013bcb9ae8eaaa71be67a4be Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Tue, 26 Jul 2022 16:29:21 +0200 Subject: [PATCH] BB: Reset Island after finished test --- .../island_client/monkey_island_client.py | 35 ++++++++++++++++--- .../monkey_zoo/blackbox/tests/exploitation.py | 2 +- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py index 1e6387283..4319b1eff 100644 --- a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py +++ b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py @@ -74,11 +74,38 @@ class MonkeyIslandClient(object): assert False @avoid_race_condition - def reset_env(self): - if self.requests.get("api", {"action": "reset"}).ok: - LOGGER.info("Resetting environment after the test.") + def reset_island(self): + self._reset_agent_configuration() + self._reset_simulation_data() + self._reset_credentials() + self._reset_island_mode() + + def _reset_agent_configuration(self): + if self.requests.post("api/reset-agent-configuration", data=None).ok: + LOGGER.info("Resetting agent-configuration after the test.") else: - LOGGER.error("Failed to reset the environment.") + LOGGER.error("Failed to reset agent configuration.") + assert False + + def _reset_simulation_data(self): + if self.requests.post("api/clear-simulation-data", data=None).ok: + LOGGER.info("Clearing simulation data.") + else: + LOGGER.error("Failed to clear simulation data") + assert False + + def _reset_credentials(self): + if self.requests.delete("api/propagation-credentials/configured-credentials").ok: + LOGGER.info("Resseting configured credentials after the test.") + else: + LOGGER.error("Failed to reset configured credentials") + assert False + + def _reset_island_mode(self): + if self.requests.post("api/island-mode", data='{"mode": "unset"}').ok: + LOGGER.info("Resseting island mode after the test.") + else: + LOGGER.error("Failed to reset island mode") assert False def find_monkeys_in_db(self, query): diff --git a/envs/monkey_zoo/blackbox/tests/exploitation.py b/envs/monkey_zoo/blackbox/tests/exploitation.py index b4cf40eba..e794321f7 100644 --- a/envs/monkey_zoo/blackbox/tests/exploitation.py +++ b/envs/monkey_zoo/blackbox/tests/exploitation.py @@ -32,7 +32,7 @@ class ExploitationTest(BasicTest): self.wait_until_monkeys_die() self.wait_for_monkey_process_to_finish() self.parse_logs() - self.island_client.reset_env() + self.island_client.reset_island() def print_test_starting_info(self): LOGGER.info("Started {} test".format(self.name))