forked from p34709852/monkey
Agent: Remove should_agent_stop from HTTPIslandAPIClient
This commit is contained in:
parent
67956358bd
commit
edf0593d4a
|
@ -147,19 +147,6 @@ class HTTPIslandAPIClient(IIslandAPIClient):
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
@handle_island_errors
|
|
||||||
@convert_json_error_to_island_api_error
|
|
||||||
def should_agent_stop(self, agent_id: str) -> bool:
|
|
||||||
url = f"{self._api_url}/monkey-control/needs-to-stop/{agent_id}"
|
|
||||||
response = requests.get( # noqa: DUO123
|
|
||||||
url,
|
|
||||||
verify=False,
|
|
||||||
timeout=SHORT_REQUEST_TIMEOUT,
|
|
||||||
)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
return response.json()["stop_agent"]
|
|
||||||
|
|
||||||
@handle_island_errors
|
@handle_island_errors
|
||||||
@convert_json_error_to_island_api_error
|
@convert_json_error_to_island_api_error
|
||||||
def get_config(self) -> AgentConfiguration:
|
def get_config(self) -> AgentConfiguration:
|
||||||
|
|
|
@ -328,52 +328,6 @@ def test_island_api_client_register_agent__status_code(
|
||||||
island_api_client.register_agent(AGENT_REGISTRATION)
|
island_api_client.register_agent(AGENT_REGISTRATION)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"actual_error, expected_error",
|
|
||||||
[
|
|
||||||
(requests.exceptions.ConnectionError, IslandAPIConnectionError),
|
|
||||||
(TimeoutError, IslandAPITimeoutError),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_island_api_client__should_agent_stop(island_api_client, actual_error, expected_error):
|
|
||||||
with requests_mock.Mocker() as m:
|
|
||||||
m.get(ISLAND_URI)
|
|
||||||
island_api_client.connect(SERVER)
|
|
||||||
|
|
||||||
with pytest.raises(expected_error):
|
|
||||||
m.get(ISLAND_AGENT_STOP_URI, exc=actual_error)
|
|
||||||
island_api_client.should_agent_stop(AGENT_ID)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"status_code, expected_error",
|
|
||||||
[
|
|
||||||
(401, IslandAPIRequestError),
|
|
||||||
(501, IslandAPIRequestFailedError),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_island_api_client_should_agent_stop__status_code(
|
|
||||||
island_api_client, status_code, expected_error
|
|
||||||
):
|
|
||||||
with requests_mock.Mocker() as m:
|
|
||||||
m.get(ISLAND_URI)
|
|
||||||
island_api_client.connect(SERVER)
|
|
||||||
|
|
||||||
with pytest.raises(expected_error):
|
|
||||||
m.get(ISLAND_AGENT_STOP_URI, status_code=status_code)
|
|
||||||
island_api_client.should_agent_stop(AGENT_ID)
|
|
||||||
|
|
||||||
|
|
||||||
def test_island_api_client_should_agent_stop__bad_json(island_api_client):
|
|
||||||
with requests_mock.Mocker() as m:
|
|
||||||
m.get(ISLAND_URI)
|
|
||||||
island_api_client.connect(SERVER)
|
|
||||||
|
|
||||||
with pytest.raises(IslandAPIRequestFailedError):
|
|
||||||
m.get(ISLAND_AGENT_STOP_URI, content=b"bad")
|
|
||||||
island_api_client.should_agent_stop(AGENT_ID)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"actual_error, expected_error",
|
"actual_error, expected_error",
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue