Skip to content

Commit dd75034

Browse files
author
Andrei Neagu
committed
Merge remote-tracking branch 'upstream/master' into pr-osparc-add-dy-sidecar-lrt-rabbit
2 parents 696c1c6 + 656c83d commit dd75034

File tree

42 files changed

+879
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+879
-267
lines changed

packages/models-library/src/models_library/projects_state.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from enum import Enum, unique
6-
from typing import Annotated, Self, TypeAlias
6+
from typing import Annotated, Final, Self, TypeAlias
77

88
from pydantic import (
99
BaseModel,
@@ -65,6 +65,13 @@ def is_running(self) -> bool:
6565
return self in self.list_running_states()
6666

6767

68+
RUNNING_STATE_COMPLETED_STATES: Final[tuple[RunningState, ...]] = (
69+
RunningState.ABORTED,
70+
RunningState.FAILED,
71+
RunningState.SUCCESS,
72+
)
73+
74+
6875
@unique
6976
class DataState(str, Enum):
7077
UP_TO_DATE = "UPTODATE"

packages/models-library/src/models_library/rabbitmq_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,4 @@ class ComputationalPipelineStatusMessage(RabbitMessageBase, ProjectMessageBase):
325325
run_result: RunningState
326326

327327
def routing_key(self) -> str | None:
328-
return f"{self.project_id}"
328+
return f"{self.project_id}.all_nodes"

packages/pytest-simcore/src/pytest_simcore/docker_registry.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import docker
1616
import jsonschema
1717
import pytest
18+
import pytest_asyncio
1819
import tenacity
1920
from pytest_simcore.helpers.logging_tools import log_context
2021
from pytest_simcore.helpers.typing_env import EnvVarsDict
@@ -146,7 +147,7 @@ def wait_till_registry_is_responsive(url: str) -> bool:
146147
# ********************************************************* Services ***************************************
147148

148149

149-
def _pull_push_service(
150+
async def _pull_push_service(
150151
pull_key: str,
151152
tag: str,
152153
new_registry: str,
@@ -213,11 +214,13 @@ def _pull_push_service(
213214
assert image.tag(new_image_tag)
214215

215216
# push the image to the new location
216-
with log_context(
217-
logging.INFO,
218-
msg=f"Pushing {pull_key}:{tag} -> {new_image_tag} ...",
219-
):
220-
client.images.push(new_image_tag)
217+
async with aiodocker.Docker() as client:
218+
await client.images.push(new_image_tag)
219+
# with log_context(
220+
# logging.INFO,
221+
# msg=f"Pushing {pull_key}:{tag} -> {new_image_tag} ...",
222+
# ):
223+
# client.images.push(new_image_tag)
221224

222225
# return image io.simcore.* labels
223226
image_labels = dict(image.labels)
@@ -230,10 +233,10 @@ def _pull_push_service(
230233
}
231234

232235

233-
@pytest.fixture(scope="session")
236+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
234237
def docker_registry_image_injector(
235238
docker_registry: str, node_meta_schema: dict
236-
) -> Callable[..., dict[str, Any]]:
239+
) -> Callable[[str, str, str | None], Awaitable[dict[str, Any]]]:
237240
def inject_image(
238241
source_image_repo: str, source_image_tag: str, owner_email: str | None = None
239242
):
@@ -249,82 +252,86 @@ def inject_image(
249252

250253

251254
@pytest.fixture
252-
def osparc_service(
255+
async def osparc_service(
253256
docker_registry: str, node_meta_schema: dict, service_repo: str, service_tag: str
254257
) -> dict[str, Any]:
255258
"""pulls the service from service_repo:service_tag and pushes to docker_registry using the oSparc node meta schema
256259
NOTE: 'service_repo' and 'service_tag' defined as parametrization
257260
"""
258-
return _pull_push_service(
261+
return await _pull_push_service(
259262
service_repo, service_tag, docker_registry, node_meta_schema
260263
)
261264

262265

263-
@pytest.fixture(scope="session")
264-
def sleeper_service(docker_registry: str, node_meta_schema: dict) -> dict[str, Any]:
266+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
267+
async def sleeper_service(
268+
docker_registry: str, node_meta_schema: dict
269+
) -> dict[str, Any]:
265270
"""Adds a itisfoundation/sleeper in docker registry"""
266-
return _pull_push_service(
271+
return await _pull_push_service(
267272
"itisfoundation/sleeper", "1.0.0", docker_registry, node_meta_schema
268273
)
269274

270275

271-
@pytest.fixture(scope="session")
272-
def jupyter_service(docker_registry: str, node_meta_schema: dict) -> dict[str, Any]:
276+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
277+
async def jupyter_service(
278+
docker_registry: str, node_meta_schema: dict
279+
) -> dict[str, Any]:
273280
"""Adds a itisfoundation/jupyter-base-notebook in docker registry"""
274-
return _pull_push_service(
281+
return await _pull_push_service(
275282
"itisfoundation/jupyter-base-notebook",
276283
"2.13.0",
277284
docker_registry,
278285
node_meta_schema,
279286
)
280287

281288

282-
@pytest.fixture(scope="session", params=["2.0.7"])
289+
@pytest_asyncio.fixture(scope="session", loop_scope="session", params=["2.0.7"])
283290
def dy_static_file_server_version(request: pytest.FixtureRequest):
284291
return request.param
285292

286293

287-
@pytest.fixture(scope="session")
288-
def dy_static_file_server_service(
294+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
295+
async def dy_static_file_server_service(
289296
docker_registry: str, node_meta_schema: dict, dy_static_file_server_version: str
290297
) -> dict[str, Any]:
291298
"""
292299
Adds the below service in docker registry
293300
itisfoundation/dy-static-file-server
294301
"""
295-
return _pull_push_service(
302+
return await _pull_push_service(
296303
"itisfoundation/dy-static-file-server",
297304
dy_static_file_server_version,
298305
docker_registry,
299306
node_meta_schema,
300307
)
301308

302309

303-
@pytest.fixture(scope="session")
304-
def dy_static_file_server_dynamic_sidecar_service(
310+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
311+
async def dy_static_file_server_dynamic_sidecar_service(
305312
docker_registry: str, node_meta_schema: dict, dy_static_file_server_version: str
306313
) -> dict[str, Any]:
307314
"""
308315
Adds the below service in docker registry
309316
itisfoundation/dy-static-file-server-dynamic-sidecar
310317
"""
311-
return _pull_push_service(
318+
return await _pull_push_service(
312319
"itisfoundation/dy-static-file-server-dynamic-sidecar",
313320
dy_static_file_server_version,
314321
docker_registry,
315322
node_meta_schema,
316323
)
317324

318325

319-
@pytest.fixture(scope="session")
320-
def dy_static_file_server_dynamic_sidecar_compose_spec_service(
326+
@pytest_asyncio.fixture(scope="session", loop_scope="session")
327+
async def dy_static_file_server_dynamic_sidecar_compose_spec_service(
321328
docker_registry: str, node_meta_schema: dict, dy_static_file_server_version: str
322329
) -> dict[str, Any]:
323330
"""
324331
Adds the below service in docker registry
325332
itisfoundation/dy-static-file-server-dynamic-sidecar-compose-spec
326333
"""
327-
return _pull_push_service(
334+
return await _pull_push_service(
328335
"itisfoundation/dy-static-file-server-dynamic-sidecar-compose-spec",
329336
dy_static_file_server_version,
330337
docker_registry,

packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,29 @@ def __call__(self, message: str) -> bool:
302302
return False
303303

304304

305+
@dataclass
306+
class SocketIOWaitNodeForOutputs:
307+
logger: logging.Logger
308+
expected_number_of_outputs: int
309+
node_id: str
310+
311+
def __call__(self, message: str) -> bool:
312+
if message.startswith(SOCKETIO_MESSAGE_PREFIX):
313+
decoded_message = decode_socketio_42_message(message)
314+
if decoded_message.name == _OSparcMessages.NODE_UPDATED:
315+
assert "data" in decoded_message.obj
316+
assert "node_id" in decoded_message.obj
317+
if decoded_message.obj["node_id"] == self.node_id:
318+
assert "outputs" in decoded_message.obj["data"]
319+
320+
return (
321+
len(decoded_message.obj["data"]["outputs"])
322+
== self.expected_number_of_outputs
323+
)
324+
325+
return False
326+
327+
305328
@dataclass
306329
class SocketIOOsparcMessagePrinter:
307330
include_logger_messages: bool = False

services/agent/src/simcore_service_agent/services/backup.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2+
import json
23
import logging
3-
import os
4+
import socket
45
import tempfile
56
from asyncio.streams import StreamReader
67
from datetime import timedelta
@@ -9,6 +10,7 @@
910
from typing import Final
1011
from uuid import uuid4
1112

13+
import httpx
1214
from fastapi import FastAPI
1315
from servicelib.container_utils import run_command_in_container
1416
from settings_library.utils_r_clone import resolve_provider
@@ -112,8 +114,28 @@ def _log_expected_operation(
112114
_logger.log(log_level, formatted_message)
113115

114116

117+
def _get_self_container_ip() -> str:
118+
return socket.gethostbyname(socket.gethostname())
119+
120+
121+
async def _get_self_container() -> str:
122+
ip = _get_self_container_ip()
123+
124+
async with httpx.AsyncClient(
125+
transport=httpx.AsyncHTTPTransport(uds="/var/run/docker.sock")
126+
) as client:
127+
response = await client.get("http://localhost/containers/json")
128+
for entry in response.json():
129+
if ip in json.dumps(entry):
130+
container_id: str = entry["Id"]
131+
return container_id
132+
133+
msg = "Could not determine self container ID"
134+
raise RuntimeError(msg)
135+
136+
115137
async def _ensure_permissions_on_source_dir(source_dir: Path) -> None:
116-
self_container = os.environ["HOSTNAME"]
138+
self_container = await _get_self_container()
117139
await run_command_in_container(
118140
self_container,
119141
command=f"chmod -R o+rX '{source_dir}'",

services/agent/tests/unit/test_services_backup.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from models_library.projects_nodes_io import NodeID
1616
from models_library.services_types import ServiceRunID
1717
from pydantic import NonNegativeInt
18+
from pytest_mock import MockerFixture
19+
from servicelib.container_utils import run_command_in_container
1820
from simcore_service_agent.core.settings import ApplicationSettings
1921
from simcore_service_agent.services.backup import backup_volume
2022
from simcore_service_agent.services.docker_utils import get_volume_details
@@ -42,7 +44,7 @@ def volume_content(tmpdir: Path) -> Path:
4244
@pytest.fixture
4345
async def mock_container_with_data(
4446
volume_content: Path, monkeypatch: pytest.MonkeyPatch
45-
) -> AsyncIterable[None]:
47+
) -> AsyncIterable[str]:
4648
async with aiodocker.Docker() as client:
4749
container = await client.containers.run(
4850
config={
@@ -56,7 +58,7 @@ async def mock_container_with_data(
5658
container_name = container_inspect["Name"][1:]
5759
monkeypatch.setenv("HOSTNAME", container_name)
5860

59-
yield None
61+
yield container_inspect["Id"]
6062

6163
await container.delete(force=True)
6264

@@ -68,8 +70,24 @@ def downlaoded_from_s3(tmpdir: Path) -> Path:
6870
return path
6971

7072

73+
@pytest.fixture
74+
async def mock__get_self_container_ip(
75+
mock_container_with_data: str,
76+
mocker: MockerFixture,
77+
) -> None:
78+
container_ip = await run_command_in_container(
79+
mock_container_with_data, command="hostname -i"
80+
)
81+
82+
mocker.patch(
83+
"simcore_service_agent.services.backup._get_self_container_ip",
84+
return_value=container_ip.strip(),
85+
)
86+
87+
7188
async def test_backup_volume(
72-
mock_container_with_data: None,
89+
mock_container_with_data: str,
90+
mock__get_self_container_ip: None,
7391
volume_content: Path,
7492
project_id: ProjectID,
7593
swarm_stack_name: str,

services/director-v2/src/simcore_service_director_v2/utils/computations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44

55
import arrow
6-
from models_library.projects_state import RunningState
6+
from models_library.projects_state import RUNNING_STATE_COMPLETED_STATES, RunningState
77
from models_library.services import ServiceKeyVersion
88
from models_library.services_regex import SERVICE_KEY_RE
99
from models_library.users import UserID
@@ -15,7 +15,7 @@
1515

1616
_logger = logging.getLogger(__name__)
1717

18-
_COMPLETED_STATES = (RunningState.ABORTED, RunningState.FAILED, RunningState.SUCCESS)
18+
1919
_RUNNING_STATES = (RunningState.STARTED,)
2020
_TASK_TO_PIPELINE_CONVERSIONS = {
2121
# tasks are initially in NOT_STARTED state, then they transition to published
@@ -50,16 +50,16 @@
5050
RunningState.NOT_STARTED,
5151
): RunningState.NOT_STARTED,
5252
# if there are only completed states with FAILED --> FAILED
53-
(*_COMPLETED_STATES,): RunningState.FAILED,
53+
(*RUNNING_STATE_COMPLETED_STATES,): RunningState.FAILED,
5454
# if there are only completed states with FAILED and not started ones --> NOT_STARTED
5555
(
56-
*_COMPLETED_STATES,
56+
*RUNNING_STATE_COMPLETED_STATES,
5757
RunningState.NOT_STARTED,
5858
): RunningState.NOT_STARTED,
5959
# the generic case where we have a combination of completed states, running states,
6060
# or published/pending tasks, not_started is a started pipeline
6161
(
62-
*_COMPLETED_STATES,
62+
*RUNNING_STATE_COMPLETED_STATES,
6363
*_RUNNING_STATES,
6464
RunningState.PUBLISHED,
6565
RunningState.PENDING,

services/director-v2/tests/integration/02/test_dynamic_services_routes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,13 @@ async def _mocked_context_manger(*args, **kwargs) -> AsyncIterator[None]:
276276
async def key_version_expected(
277277
dy_static_file_server_dynamic_sidecar_service: dict,
278278
dy_static_file_server_service: dict,
279-
docker_registry_image_injector: Callable,
279+
docker_registry_image_injector: Callable[
280+
[str, str, str | None], Awaitable[dict[str, Any]]
281+
],
280282
) -> list[tuple[ServiceKeyVersion, bool]]:
281283
results: list[tuple[ServiceKeyVersion, bool]] = []
282284

283-
sleeper_service = docker_registry_image_injector(
285+
sleeper_service = await docker_registry_image_injector(
284286
"itisfoundation/sleeper", "2.1.1", "[email protected]"
285287
)
286288

0 commit comments

Comments
 (0)