1515from models_library .projects_nodes_io import NodeID
1616from models_library .services_types import ServiceRunID
1717from pydantic import NonNegativeInt
18+ from pytest_mock import MockerFixture
19+ from servicelib .container_utils import run_command_in_container
1820from simcore_service_agent .core .settings import ApplicationSettings
1921from simcore_service_agent .services .backup import backup_volume
2022from simcore_service_agent .services .docker_utils import get_volume_details
@@ -42,7 +44,7 @@ def volume_content(tmpdir: Path) -> Path:
4244@pytest .fixture
4345async 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+
7188async 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 ,
0 commit comments