Skip to content

Commit c610fd2

Browse files
GitHKAndrei Neagu
andauthored
✨adds cli to list the content of state directories in dy-sidecar (ITISFoundation#3255)
* adds endpoint to list the path and content of the dy-sidecar Co-authored-by: Andrei Neagu <[email protected]>
1 parent 8d9d07e commit c610fd2

File tree

2 files changed

+33
-5
lines changed
  • services/dynamic-sidecar

2 files changed

+33
-5
lines changed

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/cli.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ def _print_highlight(message: str) -> None:
5252
typer.echo(typer.style(message, fg=typer.colors.MAGENTA))
5353

5454

55+
@main.command()
56+
def state_list_dirs():
57+
"""Lists files inside state directories"""
58+
59+
async def _async_state_list_dirs() -> None:
60+
app = await _setup_app_for_task_execution()
61+
62+
mounted_volumes: MountedVolumes = app.state.mounted_volumes
63+
64+
for state_path in mounted_volumes.state_paths:
65+
state_path_content = list(state_path.glob("*"))
66+
typer.echo(f"Entries in {state_path}: {state_path_content}")
67+
68+
asyncio.run(_async_state_list_dirs())
69+
70+
5571
@main.command()
5672
def state_save():
5773
"""Saves the state, usually workspace directory"""
@@ -67,15 +83,15 @@ async def _async_save_state() -> None:
6783
TaskProgress.create(), settings, mounted_volumes, rabbitmq
6884
)
6985

70-
asyncio.get_event_loop().run_until_complete(_async_save_state())
86+
asyncio.run(_async_save_state())
7187
_print_highlight("state save finished successfully")
7288

7389

7490
@main.command()
7591
def outputs_push():
7692
"""Pushes the output ports"""
7793

78-
async def _async_save_state() -> None:
94+
async def _async_outputs_push() -> None:
7995
app = await _setup_app_for_task_execution()
8096

8197
mounted_volumes: MountedVolumes = app.state.mounted_volumes
@@ -85,7 +101,7 @@ async def _async_save_state() -> None:
85101
TaskProgress.create(), None, mounted_volumes, rabbitmq
86102
)
87103

88-
asyncio.get_event_loop().run_until_complete(_async_save_state())
104+
asyncio.run(_async_outputs_push())
89105
_print_highlight("output ports push finished successfully")
90106

91107

services/dynamic-sidecar/tests/unit/test_cli.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# pylint: disable=unused-argument
22
# pylint: disable=redefined-outer-name
33

4+
import os
5+
46
import pytest
57
from pytest_mock.plugin import MockerFixture
68
from pytest_simcore.helpers.typing_env import EnvVarsDict
@@ -39,17 +41,27 @@ def mock_nodeports(mocker: MockerFixture) -> None:
3941
# TESTS
4042

4143

44+
def test_list_state_dirs(
45+
cli_runner: CliRunner, mock_rabbitmq: None, mock_data_manager: None
46+
):
47+
result = cli_runner.invoke(main, ["state-list-dirs"])
48+
assert result.exit_code == os.EX_OK, result.stdout
49+
assert result.stdout.strip() == "\n".join(
50+
[f"Entries in /data/state_dir{i}: []" for i in range(4)]
51+
)
52+
53+
4254
def test_outputs_push_interface(
4355
cli_runner: CliRunner, mock_rabbitmq: None, mock_data_manager: None
4456
):
4557
result = cli_runner.invoke(main, ["state-save"])
46-
assert result.exit_code == 0
58+
assert result.exit_code == os.EX_OK, result.stdout
4759
assert result.stdout == "state save finished successfully\n"
4860

4961

5062
def test_state_save_interface(
5163
cli_runner: CliRunner, mock_rabbitmq: None, mock_nodeports: None
5264
):
5365
result = cli_runner.invoke(main, ["outputs-push"])
54-
assert result.exit_code == 0
66+
assert result.exit_code == os.EX_OK, result.stdout
5567
assert result.stdout == "output ports push finished successfully\n"

0 commit comments

Comments
 (0)