Skip to content

Commit fed79c9

Browse files
GitHKAndrei Neagu
andauthored
🐛 dynamic-sidecar permission fixing (ITISFoundation#2847)
* fixed permissions * fixes broken test Co-authored-by: Andrei Neagu <[email protected]>
1 parent db9c2dd commit fed79c9

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/docker_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ async def get_swarm_network(dynamic_sidecar_settings: DynamicSidecarSettings) ->
106106
]
107107
if not networks or len(networks) > 1:
108108
raise DynamicSidecarError(
109-
f"Swarm network name is not configured, found following networks: {networks}"
109+
(
110+
f"Swarm network name (searching for '*{network_name}*') is not configured."
111+
f"Found following networks: {networks}"
112+
)
110113
)
111114
return networks[0]
112115

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,10 @@ async def test_nodeports_integration(
904904
dynamic_services_urls=dynamic_services_urls,
905905
)
906906

907+
# NOTE: Waits a bit for the DB to write the changes in
908+
# comp_task for the upstream service.
909+
await asyncio.sleep(2)
910+
907911
await _assert_retrieve_completed(
908912
director_v2_client=async_client,
909913
service_uuid=services_node_uuids.dy_compose_spec,

services/director-v2/tests/unit/with_swarm/test_modules_dynamic_sidecar_docker_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ async def test_get_swarm_network_missing_network(
318318
) -> None:
319319
with pytest.raises(DynamicSidecarError) as excinfo:
320320
await docker_api.get_swarm_network(dynamic_sidecar_settings)
321-
assert (
322-
str(excinfo.value)
323-
== "Swarm network name is not configured, found following networks: []"
321+
assert str(excinfo.value) == (
322+
"Swarm network name (searching for '*test_network_name*') is not configured."
323+
"Found following networks: []"
324324
)
325325

326326

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/application.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .remote_debug import setup as remote_debug_setup
1515
from .settings import DynamicSidecarSettings
1616
from .shared_handlers import on_shutdown_handler
17-
from .utils import login_registry
17+
from .utils import login_registry, volumes_fix_permissions
1818

1919
logger = logging.getLogger(__name__)
2020

@@ -80,6 +80,8 @@ def assemble_application() -> FastAPI:
8080
def create_start_app_handler() -> Callable[[], Coroutine[Any, Any, None]]:
8181
async def on_startup() -> None:
8282
await login_registry(application.state.settings.REGISTRY_SETTINGS)
83+
await volumes_fix_permissions()
84+
8385
print(WELCOME_MSG, flush=True)
8486

8587
return on_startup

services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
from tenacity.stop import stop_after_attempt
2424
from tenacity.wait import wait_fixed
2525

26+
from ..modules.mounted_fs import MountedVolumes, get_mounted_volumes
27+
2628
CommandResult = namedtuple("CommandResult", "finished_without_errors, decoded_stdout")
2729

2830
TEMPLATE_SEARCH_PATTERN = r"%%(.*?)%%"
2931

32+
HIDDEN_FILE_NAME = ".hidden_do_not_remove"
33+
3034
logger = logging.getLogger(__name__)
3135

3236

@@ -156,3 +160,20 @@ def assemble_container_names(validated_compose_content: str) -> List[str]:
156160
service_data["container_name"]
157161
for service_data in parsed_compose_spec["services"].values()
158162
]
163+
164+
165+
async def volumes_fix_permissions() -> None:
166+
# NOTE: by creating a hidden file on all mounted volumes
167+
# the same permissions are ensured and avoids
168+
# issues when starting the services
169+
mounted_volumes: MountedVolumes = get_mounted_volumes()
170+
for volume_path in [
171+
mounted_volumes.disk_inputs_path,
172+
mounted_volumes.disk_outputs_path,
173+
] + list(mounted_volumes.disk_state_paths()):
174+
hidden_file = volume_path / HIDDEN_FILE_NAME
175+
hidden_file.write_text(
176+
f"Directory must not be empty.\nCreated by {__file__}.\nRequired by "
177+
"oSPARC internals to properly enforce permissions on this "
178+
"directory and all its files"
179+
)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from simcore_service_dynamic_sidecar.core.shared_handlers import (
2525
write_file_and_run_command,
2626
)
27-
from simcore_service_dynamic_sidecar.core.utils import async_command
27+
from simcore_service_dynamic_sidecar.core.utils import HIDDEN_FILE_NAME, async_command
2828
from simcore_service_dynamic_sidecar.core.validation import parse_compose_spec
2929
from simcore_service_dynamic_sidecar.models.domains.shared_store import SharedStore
3030
from simcore_service_dynamic_sidecar.modules.mounted_fs import (
@@ -454,7 +454,13 @@ def _create_random_dir_in_inputs() -> int:
454454
mounted_volumes: MountedVolumes = get_mounted_volumes()
455455
dir_name = mounted_volumes.disk_outputs_path / f"{uuid4()}"
456456
dir_name.mkdir(parents=True)
457-
dir_count = len([1 for x in mounted_volumes.disk_outputs_path.glob("*")])
457+
dir_count = len(
458+
[
459+
1
460+
for x in mounted_volumes.disk_outputs_path.glob("*")
461+
if not f"{x}".endswith(HIDDEN_FILE_NAME)
462+
]
463+
)
458464
return dir_count
459465

460466
EVENTS_PER_DIR_CREATION = 2

0 commit comments

Comments
 (0)