Skip to content

Commit 7e86ce6

Browse files
author
Andrei Neagu
committed
fixed issue
1 parent 5e25e91 commit 7e86ce6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import asyncio
22
import logging
3+
import os
34
import tempfile
45
from asyncio.streams import StreamReader
6+
from datetime import timedelta
57
from pathlib import Path
68
from textwrap import dedent
79
from typing import Final
810
from uuid import uuid4
911

1012
from fastapi import FastAPI
13+
from servicelib.container_utils import run_command_in_container
1114
from settings_library.utils_r_clone import resolve_provider
1215

1316
from ..core.settings import ApplicationSettings
1417
from ..models.volumes import DynamicServiceVolumeLabels, VolumeDetails
1518

19+
_TIMEOUT_PERMISSION_CHANGES: Final[timedelta] = timedelta(minutes=5)
20+
1621
_logger = logging.getLogger(__name__)
1722

1823

@@ -107,6 +112,15 @@ def _log_expected_operation(
107112
_logger.log(log_level, formatted_message)
108113

109114

115+
async def _ensure_permissions_on_source_dir(source_dir: Path) -> None:
116+
self_container = os.environ["HOSTNAME"]
117+
await run_command_in_container(
118+
self_container,
119+
command=f"chmod -R o+rX '{source_dir}'",
120+
timeout=_TIMEOUT_PERMISSION_CHANGES.total_seconds(),
121+
)
122+
123+
110124
async def _store_in_s3(
111125
settings: ApplicationSettings, volume_name: str, volume_details: VolumeDetails
112126
) -> None:
@@ -148,6 +162,8 @@ async def _store_in_s3(
148162
volume_details.labels, s3_path, r_clone_ls_output, volume_name
149163
)
150164

165+
await _ensure_permissions_on_source_dir(source_dir)
166+
151167
# sync files via rclone
152168
r_clone_sync = [
153169
"rclone",

services/agent/tests/unit/test_services_backup.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
23

34
import asyncio
4-
from collections.abc import Awaitable, Callable
5+
import contextlib
6+
from collections.abc import AsyncIterable, Awaitable, Callable
57
from pathlib import Path
68
from typing import Final
79
from uuid import uuid4
810

911
import aioboto3
12+
import aiodocker
1013
import pytest
1114
from fastapi import FastAPI
1215
from models_library.projects import ProjectID
@@ -37,6 +40,30 @@ def volume_content(tmpdir: Path) -> Path:
3740
return path
3841

3942

43+
@pytest.fixture
44+
async def mock_container_with_data(
45+
volume_content: Path, monkeypatch: pytest.MonkeyPatch
46+
) -> AsyncIterable[None]:
47+
async with aiodocker.Docker() as client:
48+
container = await client.containers.run(
49+
config={
50+
"Image": "alpine:latest",
51+
"Cmd": ["/bin/ash", "-c", "sleep 10000"],
52+
"HostConfig": {"Binds": [f"{volume_content}:{volume_content}:rw"]},
53+
}
54+
)
55+
container_inspect = await container.show()
56+
57+
container_name = container_inspect["Name"][1:]
58+
monkeypatch.setenv("HOSTNAME", container_name)
59+
60+
yield None
61+
62+
with contextlib.suppress(aiodocker.DockerError):
63+
await container.kill()
64+
await container.delete()
65+
66+
4067
@pytest.fixture
4168
def downlaoded_from_s3(tmpdir: Path) -> Path:
4269
path = Path(tmpdir) / "downloaded_from_s3"
@@ -45,6 +72,7 @@ def downlaoded_from_s3(tmpdir: Path) -> Path:
4572

4673

4774
async def test_backup_volume(
75+
mock_container_with_data: None,
4876
volume_content: Path,
4977
project_id: ProjectID,
5078
swarm_stack_name: str,

0 commit comments

Comments
 (0)