BB: Reset Island after finished test

This commit is contained in:
Ilija Lazoroski 2022-07-26 16:29:21 +02:00
parent 81101d4213
commit 371b020542
2 changed files with 32 additions and 5 deletions

View File

@ -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):

View File

@ -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))