Skip to content

Commit

Permalink
fix(dask): use correct REANA host port for Dask service URLs (reanahu…
Browse files Browse the repository at this point in the history
…b#630)

This PR is part of harmonizing the treatment of REANA_HOSTNAME
accross all REANA components. You can refer to other PRs below.

reanahub/reana#867
reanahub/reana-server#717

Closes reanahub/reana#865
  • Loading branch information
Alputer committed Jan 31, 2025
1 parent bb7b2ff commit bf8d7e1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
26 changes: 24 additions & 2 deletions reana_workflow_controller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ def _env_vars_dict_to_k8s_list(env_vars):
return [{"name": name, "value": str(value)} for name, value in env_vars.items()]


def compose_base_reana_url(hostname: str, hostport: int) -> str:
"""
Compose a REANA API base URL while omitting the default HTTPS port (443).
Args:
hostname (str): The REANA hostname.
hostport (int): The REANA host port.
Returns:
str: The full base URL.
"""
if hostport == 443:
return f"https://{hostname}"
return f"https://{hostname}:{hostport}"


SECRET_KEY = os.getenv("REANA_SECRET_KEY", "CHANGE_ME")
"""Secret key used for the application user sessions."""

Expand Down Expand Up @@ -277,8 +293,14 @@ def _parse_interactive_sessions_environments(env_var):
REANA_GITLAB_URL = "https://{}".format(REANA_GITLAB_HOST)
"""GitLab API URL"""

REANA_HOSTNAME = os.getenv("REANA_HOSTNAME", "CHANGE_ME")
"""REANA URL"""
REANA_HOSTNAME = os.getenv("REANA_HOSTNAME", "localhost")
"""REANA host name."""

REANA_HOSTPORT = os.getenv("REANA_HOSTPORT", "30443")
"""REANA host name port number."""

BASE_REANA_URL = compose_base_reana_url(REANA_HOSTNAME, REANA_HOSTPORT)
"""Base REANA URL."""

REANA_INGRESS_ANNOTATIONS = json.loads(os.getenv("REANA_INGRESS_ANNOTATIONS", "{}"))
"""REANA Ingress annotations defined by the administrator."""
Expand Down
6 changes: 3 additions & 3 deletions reana_workflow_controller/consumer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023, 2024 CERN.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -40,7 +40,7 @@
ALIVE_STATUSES,
PROGRESS_STATUSES,
REANA_GITLAB_URL,
REANA_HOSTNAME,
BASE_REANA_URL,
REANA_JOB_STATUS_CONSUMER_PREFETCH_COUNT,
)
from reana_workflow_controller.errors import REANAWorkflowControllerError
Expand Down Expand Up @@ -196,7 +196,7 @@ def _update_commit_status(workflow, status):
return
gitlab_access_token = gitlab_access_token_secret.value_str

target_url = f"https://{REANA_HOSTNAME}/api/workflows/{workflow.id_}/logs"
target_url = f"{BASE_REANA_URL}/api/workflows/{workflow.id_}/logs"
workflow_name = urlparse.quote_plus(workflow.git_repo)
system_name = "reana"
commit_status_url = (
Expand Down
2 changes: 1 addition & 1 deletion reana_workflow_controller/rest/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2020, 2021, 2022, 2023, 2024 CERN.
# Copyright (C) 2020, 2021, 2022, 2023, 2024, 2025 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down
4 changes: 2 additions & 2 deletions reana_workflow_controller/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
get_default_quota_resource,
)
from reana_workflow_controller.config import (
REANA_HOSTNAME,
BASE_REANA_URL,
DEFAULT_NAME_FOR_WORKFLOWS,
MAX_WORKFLOW_SHARING_MESSAGE_LENGTH,
)
Expand Down Expand Up @@ -631,7 +631,7 @@ def create_workflow(): # noqa
if requires_dask(workflow):
dask_service = Service(
name=get_dask_component_name(workflow.id_, "database_model_service"),
uri=f"https://{REANA_HOSTNAME}/{workflow_uuid}/dashboard/status",
uri=f"{BASE_REANA_URL}/{workflow_uuid}/dashboard/status",
type_=ServiceType.dask,
status=ServiceStatus.created,
)
Expand Down
21 changes: 20 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023 CERN.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023, 2025 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -38,6 +38,7 @@
list_files_recursive_wildcard,
mv_files,
remove_files_recursive_wildcard,
compose_base_reana_url,
)


Expand Down Expand Up @@ -343,3 +344,21 @@ def test_mv_files(
assert target_path.exists()
if source_content:
assert target_path.read_text() == source_content


# Note that this function is inside config.py file and not in
# `rest/utils.py file due to circular import issues.` However,
# it is a utility function so it does not hurt to test it in
# this file.
@pytest.mark.parametrize(
"hostname, hostport, expected_url",
[
("reana.cern.ch", 443, "https://reana.cern.ch"),
("reana.cern.ch", 30443, "https://reana.cern.ch:30443"),
("example.com", 443, "https://example.com"),
("example.com", 8080, "https://example.com:8080"),
],
)
def test_compose_reana_url(hostname, hostport, expected_url):
"""Test composing base reana url."""
assert compose_base_reana_url(hostname, hostport) == expected_url

0 comments on commit bf8d7e1

Please sign in to comment.