Skip to content

Commit

Permalink
🐛 adds exception rules for legacy services (⚠️ devops) (#2813)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Feb 9, 2022
1 parent 89c2673 commit 441542e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
37 changes: 30 additions & 7 deletions services/director/src/simcore_service_director/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime, timedelta
from distutils.version import StrictVersion
from enum import Enum
from http import HTTPStatus
from pprint import pformat
from typing import Dict, List, Optional, Tuple

Expand Down Expand Up @@ -1020,17 +1021,39 @@ async def _save_service_state(service_host_name: str, session: aiohttp.ClientSes
url=f"http://{service_host_name}/state",
timeout=ServicesCommonSettings().director_dynamic_service_save_timeout,
) as response:
response.raise_for_status()
log.info(
"Service '%s' successfully saved its state: %s",
service_host_name,
f"{response}",
)
try:
response.raise_for_status()

except ClientResponseError as err:
if err.status in (HTTPStatus.METHOD_NOT_ALLOWED, HTTPStatus.NOT_FOUND):
# NOTE: Legacy Override. Some old services do not have a state entrypoint defined
# therefore we assume there is nothing to be saved and do not raise exception
# Responses found so far:
# METHOD NOT ALLOWED https://httpstatuses.com/405
# NOT FOUND https://httpstatuses.com/404
#
log.warning(
"Service '%s' does not seem to implement save state functionality: %s. Skipping save",
service_host_name,
err,
)
else:
# re-reaise
raise
else:
log.info(
"Service '%s' successfully saved its state: %s",
service_host_name,
f"{response}",
)


@run_sequentially_in_context(target_args=["node_uuid"])
async def stop_service(app: web.Application, node_uuid: str, save_state: bool) -> None:
log.debug("stopping service with uuid %s", node_uuid)
log.debug(
"stopping service with node_uuid=%s, save_state=%s", node_uuid, save_state
)

# get the docker client
async with docker_utils.docker_client() as client: # pylint: disable=not-async-context-manager
try:
Expand Down
3 changes: 3 additions & 0 deletions services/director/tests/test_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ async def push_start_services(number_comp: int, number_dyn: int, dependant=False
# teardown stop the services
for service in started_services:
service_uuid = service["service_uuid"]
# NOTE: Fake services are not even web-services therefore we cannot
# even emulate a legacy dy-service that does not implement a save-state feature
# so here we must make save_state=False
await producer.stop_service(aiohttp_mock_app, service_uuid, save_state=False)
with pytest.raises(exceptions.ServiceUUIDNotFoundError):
await producer.get_service_details(aiohttp_mock_app, service_uuid)
Expand Down

0 comments on commit 441542e

Please sign in to comment.