From 88422f97641fa399fc6e67b59adcf267f4264040 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 22 Mar 2022 15:32:16 -0400 Subject: [PATCH] BB: Fix API call to kill all monkeys --- .../blackbox/island_client/monkey_island_client.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 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 5c5b57e09..d203d8f9c 100644 --- a/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py +++ b/envs/monkey_zoo/blackbox/island_client/monkey_island_client.py @@ -1,6 +1,6 @@ import json import logging -from time import sleep +import time from typing import Union from bson import json_util @@ -15,7 +15,7 @@ LOGGER = logging.getLogger(__name__) def avoid_race_condition(func): - sleep(SLEEP_BETWEEN_REQUESTS_SECONDS) + time.sleep(SLEEP_BETWEEN_REQUESTS_SECONDS) return func @@ -48,10 +48,15 @@ class MonkeyIslandClient(object): @avoid_race_condition def kill_all_monkeys(self): - if self.requests.get("api", {"action": "killall"}).ok: + response = self.requests.post_json( + "api/monkey_control/stop-all-agents", data={"kill_time": time.time()} + ) + if response.ok: LOGGER.info("Killing all monkeys after the test.") else: LOGGER.error("Failed to kill all monkeys.") + LOGGER.error(response.status_code) + LOGGER.error(response.content) assert False @avoid_race_condition