Skip to content

Commit bb60d87

Browse files
authored
♻️✨ maintenance new settings (final round) (ITISFoundation#2836)
SEE description in ITISFoundation#2836
1 parent 4c35a9e commit bb60d87

File tree

227 files changed

+3129
-3762
lines changed

Some content is hidden

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

227 files changed

+3129
-3762
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,13 @@ push-version: tag-version
355355
.PHONY: devenv devenv-all node-env
356356

357357
.venv:
358+
@python3 --version
358359
python3 -m venv $@
359360
$@/bin/pip3 --quiet install --upgrade \
360361
pip~=21.3 \
361362
wheel \
362363
setuptools
364+
@$@/bin/pip3 list --verbose
363365

364366
devenv: .venv ## create a python virtual environment with dev tools (e.g. linters, etc)
365367
$</bin/pip3 --quiet install -r requirements/devenv.txt

packages/models-library/src/models_library/settings/rabbit.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

packages/models-library/src/models_library/settings/redis.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
)
3030
from .helpers.constants import HEADER_STR
3131
from .helpers.typing_env import EnvVarsDict
32-
from .helpers.utils_docker import get_ip, run_docker_compose_config, save_docker_infos
32+
from .helpers.utils_docker import (
33+
get_localhost_ip,
34+
run_docker_compose_config,
35+
save_docker_infos,
36+
)
3337

3438

3539
@pytest.fixture(scope="session")
@@ -49,7 +53,7 @@ def testing_environ_vars(env_devel_file: Path) -> EnvVarsDict:
4953
env_devel["LOG_LEVEL"] = "DEBUG"
5054

5155
env_devel["REGISTRY_SSL"] = "False"
52-
env_devel["REGISTRY_URL"] = "{}:5000".format(get_ip())
56+
env_devel["REGISTRY_URL"] = "{}:5000".format(get_localhost_ip())
5357
env_devel["REGISTRY_PATH"] = "127.0.0.1:5000"
5458
env_devel["REGISTRY_USER"] = "simcore"
5559
env_devel["REGISTRY_PW"] = ""
@@ -301,7 +305,7 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: ExitCode) -> None:
301305
def _minio_fix(service_environs: Dict) -> Dict:
302306
"""this hack ensures that S3 is accessed from the host at all time, thus pre-signed links work."""
303307
if "S3_ENDPOINT" in service_environs:
304-
service_environs["S3_ENDPOINT"] = f"{get_ip()}:9001"
308+
service_environs["S3_ENDPOINT"] = f"{get_localhost_ip()}:9001"
305309
return service_environs
306310

307311

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import pytest
1515
import tenacity
1616

17-
from .helpers.utils_docker import get_ip
17+
from .helpers.utils_docker import get_localhost_ip
1818

1919
log = logging.getLogger(__name__)
2020

@@ -71,7 +71,7 @@ def docker_registry(keep_docker_up: bool) -> str:
7171
os.environ["REGISTRY_SSL"] = "False"
7272
os.environ["REGISTRY_AUTH"] = "False"
7373
# the registry URL is how to access from the container (e.g. for accessing the API)
74-
os.environ["REGISTRY_URL"] = f"{get_ip()}:5000"
74+
os.environ["REGISTRY_URL"] = f"{get_localhost_ip()}:5000"
7575
# the registry PATH is how the docker engine shall access the images (usually same as REGISTRY_URL but for testing)
7676
os.environ["REGISTRY_PATH"] = "127.0.0.1:5000"
7777
os.environ["REGISTRY_USER"] = "simcore"

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
from .helpers.constants import HEADER_STR, MINUTE
2525
from .helpers.typing_env import EnvVarsDict
2626
from .helpers.utils_dict import copy_from_dict
27-
from .helpers.utils_docker import get_ip
27+
from .helpers.utils_docker import get_localhost_ip
2828

2929
log = logging.getLogger(__name__)
3030

3131

3232
#
33-
# NOTE this file must be PYTHON >=3.6 COMPATIBLE because it is used by the director service
33+
# NOTE: this file must be PYTHON >=3.6 COMPATIBLE because it is used by the director service
3434
#
3535

3636
# HELPERS --------------------------------------------------------------------------------
@@ -170,7 +170,7 @@ def docker_swarm(
170170
):
171171
with attempt:
172172
if not _in_docker_swarm(docker_client):
173-
docker_client.swarm.init(advertise_addr=get_ip())
173+
docker_client.swarm.init(advertise_addr=get_localhost_ip())
174174
# if still not in swarm, raise an error to try and initialize again
175175
_in_docker_swarm(docker_client, raise_error=True)
176176

@@ -217,13 +217,30 @@ def docker_stack(
217217
# make up-version
218218
stacks_deployed: Dict[str, Dict] = {}
219219
for key, stack_name, compose_file in stacks:
220-
subprocess.run(
221-
f"docker stack deploy --with-registry-auth -c {compose_file.name} {stack_name}".split(
222-
" "
223-
),
224-
check=True,
225-
cwd=compose_file.parent,
226-
)
220+
try:
221+
subprocess.run(
222+
[
223+
"docker",
224+
"stack",
225+
"deploy",
226+
"--with-registry-auth",
227+
"--compose-file",
228+
f"{compose_file.name}",
229+
f"{stack_name}",
230+
],
231+
check=True,
232+
cwd=compose_file.parent,
233+
)
234+
except subprocess.CalledProcessError as err:
235+
print(
236+
"docker_stack failed",
237+
f"{' '.join(err.cmd)}",
238+
f"returncode={err.returncode}",
239+
f"stdout={err.stdout}",
240+
f"stderr={err.stderr}",
241+
)
242+
raise
243+
227244
stacks_deployed[key] = {
228245
"name": stack_name,
229246
"compose": yaml.safe_load(compose_file.read_text()),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from typing import Any, Dict, Mapping, Optional, Set, Union
44

5+
ConfigDict = Dict[str, Any]
6+
57

68
def get_from_dict(obj: Mapping[str, Any], dotted_key: str, default=None) -> Any:
79
keys = dotted_key.split(".")

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

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414
from tenacity.stop import stop_after_attempt
1515
from tenacity.wait import wait_fixed
1616

17+
COLOR_ENCODING_RE = re.compile(r"\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]")
18+
MAX_PATH_CHAR_LEN_ALLOWED = 260
19+
kFILENAME_TOO_LONG = 36
20+
_NORMPATH_COUNT = 0
21+
22+
1723
log = logging.getLogger(__name__)
1824

1925

20-
def get_ip() -> str:
26+
def get_localhost_ip(default="127.0.0.1") -> str:
27+
"""Return the IP address for localhost"""
28+
local_ip = default
2129
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
2230
try:
2331
# doesn't even have to be reachable
2432
s.connect(("10.255.255.255", 1))
25-
IP = s.getsockname()[0]
26-
except Exception: # pylint: disable=broad-except
27-
IP = "127.0.0.1"
33+
local_ip = s.getsockname()[0]
2834
finally:
2935
s.close()
30-
return IP
36+
return local_ip
3137

3238

3339
@retry(
@@ -170,7 +176,27 @@ def run_docker_compose_config(
170176
return compose_file
171177

172178

173-
COLOR_ENCODING_RE = re.compile(r"\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]")
179+
def shorten_path(filename: str) -> Path:
180+
# These paths are composed using test name hierarchies
181+
# when the test is parametrized, it uses the str of the
182+
# object as id which could result in path that goes over
183+
# allowed limit (260 characters).
184+
# This helper function tries to normalize the path
185+
# Another possibility would be that the path has some
186+
# problematic characters but so far we did not find any case ...
187+
global _NORMPATH_COUNT # pylint: disable=global-statement
188+
189+
if len(filename) > MAX_PATH_CHAR_LEN_ALLOWED:
190+
_NORMPATH_COUNT += 1
191+
path = Path(filename)
192+
if path.is_dir():
193+
limit = MAX_PATH_CHAR_LEN_ALLOWED - 60
194+
filename = filename[:limit] + f"{_NORMPATH_COUNT}"
195+
elif path.is_file():
196+
limit = MAX_PATH_CHAR_LEN_ALLOWED - 10
197+
filename = filename[:limit] + f"{_NORMPATH_COUNT}{path.suffix}"
198+
199+
return Path(filename)
174200

175201

176202
def save_docker_infos(destination_path: Path):
@@ -180,21 +206,42 @@ def save_docker_infos(destination_path: Path):
180206
all_containers = client.containers.list(all=True)
181207

182208
if all_containers:
183-
destination_path.mkdir(parents=True, exist_ok=True)
209+
try:
210+
destination_path.mkdir(parents=True, exist_ok=True)
211+
212+
except OSError as err:
213+
if err.errno == kFILENAME_TOO_LONG:
214+
destination_path = shorten_path(err.filename)
215+
destination_path.mkdir(parents=True, exist_ok=True)
184216

185217
for container in all_containers:
186218

187219
try:
188220
# logs w/o coloring characters
189221
logs: str = container.logs(timestamps=True, tail=1000).decode()
190-
(destination_path / f"{container.name}.log").write_text(
191-
COLOR_ENCODING_RE.sub("", logs)
192-
)
222+
223+
try:
224+
(destination_path / f"{container.name}.log").write_text(
225+
COLOR_ENCODING_RE.sub("", logs)
226+
)
227+
228+
except OSError as err:
229+
if err.errno == kFILENAME_TOO_LONG:
230+
shorten_path(err.filename).write_text(
231+
COLOR_ENCODING_RE.sub("", logs)
232+
)
193233

194234
# inspect attrs
195-
(destination_path / f"{container.name}.json").write_text(
196-
json.dumps(container.attrs, indent=2)
197-
)
235+
try:
236+
(destination_path / f"{container.name}.json").write_text(
237+
json.dumps(container.attrs, indent=2)
238+
)
239+
except OSError as err:
240+
if err.errno == kFILENAME_TOO_LONG:
241+
shorten_path(err.filename).write_text(
242+
json.dumps(container.attrs, indent=2)
243+
)
244+
198245
except Exception as err: # pylint: disable=broad-except
199246
print(f"Unexpected failure while dumping {container}." f"Details {err}")
200247

0 commit comments

Comments
 (0)