Skip to content

Commit

Permalink
Merge branch 'master' into is4071/mypy-webserver-statics
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored May 4, 2023
2 parents ff7aefd + 902f3d1 commit 05b5670
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 342 deletions.
3 changes: 2 additions & 1 deletion ci/github/system-testing/swarm-deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ test() {
# WARNING: this test is heavy. Due to limited CI machine power, please do not
# add too much overhead (e.g. low log-level etc)
pytest \
--asyncio-mode=auto \
--color=yes \
-v \
--durations=5 \
--log-level=INFO \
-v \
tests/swarm-deploy
}

Expand Down
105 changes: 58 additions & 47 deletions packages/pytest-simcore/src/pytest_simcore/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _is_docker_swarm_init(docker_client: docker.client.DockerClient) -> bool:
before_sleep=before_sleep_log(log, logging.WARNING),
reraise=True,
)
def assert_service_is_running(service):
def assert_service_is_running(service) -> None:
"""Checks that a number of tasks of this service are in running state"""

def _get(obj: dict[str, Any], dotted_key: str, default=None) -> Any:
Expand Down Expand Up @@ -101,7 +101,6 @@ def _fetch_and_print_services(
print(HEADER_STR.format(f"docker services running {extra_title}"))

for service_obj in docker_client.services.list():

tasks = {}
service = {}
with suppress(Exception):
Expand Down Expand Up @@ -179,6 +178,56 @@ def docker_swarm(
assert _is_docker_swarm_init(docker_client) is keep_docker_up


def _force_restart_migration_service(docker_client: docker.client.DockerClient) -> None:
for migration_service in (
service
for service in docker_client.services.list()
if "migration" in service.name
):
print(
"WARNING: migration service detected before updating stack, it will be force-updated"
)
migration_service.force_update()
print(f"forced updated {migration_service.name}.")


def _deploy_stack(compose_file: Path, stack_name: str) -> None:
for attempt in Retrying(
stop=stop_after_delay(60),
wait=wait_random_exponential(max=5),
retry=retry_if_exception_type(TryAgain),
reraise=True,
):
with attempt:
try:
subprocess.run(
[
"docker",
"stack",
"deploy",
"--with-registry-auth",
"--compose-file",
f"{compose_file.name}",
f"{stack_name}",
],
check=True,
cwd=compose_file.parent,
capture_output=True,
)
except subprocess.CalledProcessError as err:
if b"update out of sequence" in err.stderr:
raise TryAgain from err
print(
"docker_stack failed",
f"{' '.join(err.cmd)}",
f"returncode={err.returncode}",
f"stdout={err.stdout}",
f"stderr={err.stderr}",
"\nTIP: frequent failure is due to a corrupt .env file: Delete .env and .env.bak",
)
raise


@pytest.fixture(scope="module")
def docker_stack(
docker_swarm: None,
Expand Down Expand Up @@ -211,54 +260,12 @@ def docker_stack(

# NOTE: if the migration service was already running prior to this call it must
# be force updated so that it does its job. else it remains and tests will fail
for migration_service in (
service
for service in docker_client.services.list()
if "migration" in service.name # type: ignore
):
print(
"WARNING: migration service detected before updating stack, it will be force-updated"
)
migration_service.force_update() # type: ignore
print(f"forced updated {migration_service.name}.") # type: ignore
_force_restart_migration_service(docker_client)

# make up-version
stacks_deployed: dict[str, dict] = {}
for key, stack_name, compose_file in stacks:
for attempt in Retrying(
stop=stop_after_delay(60),
wait=wait_random_exponential(max=5),
retry=retry_if_exception_type(TryAgain),
reraise=True,
):
with attempt:
try:
subprocess.run(
[
"docker",
"stack",
"deploy",
"--with-registry-auth",
"--compose-file",
f"{compose_file.name}",
f"{stack_name}",
],
check=True,
cwd=compose_file.parent,
capture_output=True,
)
except subprocess.CalledProcessError as err:
if b"update out of sequence" in err.stderr:
raise TryAgain from err
print(
"docker_stack failed",
f"{' '.join(err.cmd)}",
f"returncode={err.returncode}",
f"stdout={err.stdout}",
f"stderr={err.stderr}",
"\nTIP: frequent failure is due to a corrupt .env file: Delete .env and .env.bak",
)
raise
_deploy_stack(compose_file, stack_name)

stacks_deployed[key] = {
"name": stack_name,
Expand All @@ -281,6 +288,11 @@ async def _check_all_services_are_running():
return_when=asyncio.FIRST_EXCEPTION,
)
assert done, f"no services ready, they all failed! [{pending}]"

for future in done:
if exc := future.exception():
raise exc

assert not pending, f"some service did not start correctly [{pending}]"

asyncio.run(_check_all_services_are_running())
Expand Down Expand Up @@ -318,7 +330,6 @@ async def _check_all_services_are_running():

stacks.reverse()
for _, stack, _ in stacks:

try:
subprocess.run(
f"docker stack remove {stack}".split(" "),
Expand Down
4 changes: 3 additions & 1 deletion services/dask-sidecar/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ pyyaml==5.4.1
# dask-gateway
# distributed
redis==4.5.4
# via -r requirements/../../../packages/service-library/requirements/_base.in
# via
# -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -r requirements/../../../packages/service-library/requirements/_base.in
requests==2.28.2
# via fsspec
s3fs==2023.3.0
Expand Down
4 changes: 2 additions & 2 deletions services/dask-sidecar/requirements/_test.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
coverage
docker
faker
minio
moto[server]
pytest
pytest-aiohttp # incompatible with pytest-asyncio. See https://github.com/pytest-dev/pytest-asyncio/issues/76
pytest-aiohttp
pytest-cov
pytest-icdiff
pytest-instafail
Expand Down
Loading

0 comments on commit 05b5670

Please sign in to comment.