Skip to content

Commit 441542e

Browse files
authored
🐛 adds exception rules for legacy services (⚠️ devops) (ITISFoundation#2813)
1 parent 89c2673 commit 441542e

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

services/director/src/simcore_service_director/producer.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime, timedelta
66
from distutils.version import StrictVersion
77
from enum import Enum
8+
from http import HTTPStatus
89
from pprint import pformat
910
from typing import Dict, List, Optional, Tuple
1011

@@ -1020,17 +1021,39 @@ async def _save_service_state(service_host_name: str, session: aiohttp.ClientSes
10201021
url=f"http://{service_host_name}/state",
10211022
timeout=ServicesCommonSettings().director_dynamic_service_save_timeout,
10221023
) as response:
1023-
response.raise_for_status()
1024-
log.info(
1025-
"Service '%s' successfully saved its state: %s",
1026-
service_host_name,
1027-
f"{response}",
1028-
)
1024+
try:
1025+
response.raise_for_status()
1026+
1027+
except ClientResponseError as err:
1028+
if err.status in (HTTPStatus.METHOD_NOT_ALLOWED, HTTPStatus.NOT_FOUND):
1029+
# NOTE: Legacy Override. Some old services do not have a state entrypoint defined
1030+
# therefore we assume there is nothing to be saved and do not raise exception
1031+
# Responses found so far:
1032+
# METHOD NOT ALLOWED https://httpstatuses.com/405
1033+
# NOT FOUND https://httpstatuses.com/404
1034+
#
1035+
log.warning(
1036+
"Service '%s' does not seem to implement save state functionality: %s. Skipping save",
1037+
service_host_name,
1038+
err,
1039+
)
1040+
else:
1041+
# re-reaise
1042+
raise
1043+
else:
1044+
log.info(
1045+
"Service '%s' successfully saved its state: %s",
1046+
service_host_name,
1047+
f"{response}",
1048+
)
10291049

10301050

10311051
@run_sequentially_in_context(target_args=["node_uuid"])
10321052
async def stop_service(app: web.Application, node_uuid: str, save_state: bool) -> None:
1033-
log.debug("stopping service with uuid %s", node_uuid)
1053+
log.debug(
1054+
"stopping service with node_uuid=%s, save_state=%s", node_uuid, save_state
1055+
)
1056+
10341057
# get the docker client
10351058
async with docker_utils.docker_client() as client: # pylint: disable=not-async-context-manager
10361059
try:

services/director/tests/test_producer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ async def push_start_services(number_comp: int, number_dyn: int, dependant=False
9696
# teardown stop the services
9797
for service in started_services:
9898
service_uuid = service["service_uuid"]
99+
# NOTE: Fake services are not even web-services therefore we cannot
100+
# even emulate a legacy dy-service that does not implement a save-state feature
101+
# so here we must make save_state=False
99102
await producer.stop_service(aiohttp_mock_app, service_uuid, save_state=False)
100103
with pytest.raises(exceptions.ServiceUUIDNotFoundError):
101104
await producer.get_service_details(aiohttp_mock_app, service_uuid)

0 commit comments

Comments
 (0)