Skip to content

Commit

Permalink
workflow: add message about autoclosure of the interactive session.
Browse files Browse the repository at this point in the history
When opening an interactive session with the `open` command, the user is now
notified about the maximum inactivity time before the session is automatically
closed, if the autoclosure was enabled by the REANA administrators.

Closes reanahub#657
  • Loading branch information
giuseppe-steduto committed Jul 11, 2023
1 parent f2efcc5 commit 489c3ba
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
11 changes: 10 additions & 1 deletion reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ def workflow_open_interactive_session(
Examples:\n
\t $ reana-client open -w myanalysis.42 jupyter
"""
from reana_client.api.client import open_interactive_session
from reana_client.api.client import open_interactive_session, info

if workflow:
try:
Expand Down Expand Up @@ -1389,6 +1389,15 @@ def workflow_open_interactive_session(
display_message(
"It could take several minutes to start the interactive session."
)
reana_info = info(access_token)
max_inactivity_days_entry = (
reana_info.get("maximum_interactive_session_inactivity_period") or {}
)
max_inactivity_days = max_inactivity_days_entry.get("value")
if max_inactivity_days:
display_message(
f"Please note that it will be automatically closed after {max_inactivity_days} days of inactivity."
)
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
Expand Down
42 changes: 36 additions & 6 deletions tests/test_cli_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,11 +816,33 @@ def test_workflow_input_parameters():


@pytest.mark.parametrize(
"interactive_session_type",
INTERACTIVE_SESSION_TYPES
+ [pytest.param("wrong-interactive-type", marks=pytest.mark.xfail)],
"interactive_session_type,reana_info,is_autoclosure_message_expected",
[
(
session_type,
{"maximum_interactive_session_inactivity_period": {"value": 30}},
True,
)
for session_type in INTERACTIVE_SESSION_TYPES
]
+ [
(
INTERACTIVE_SESSION_TYPES[0],
{"maximum_interactive_session_inactivity_period": None},
False,
),
(INTERACTIVE_SESSION_TYPES[0], dict(), False),
pytest.param(
"wrong-interactive-type",
{"maximum_interactive_session_inactivity_period": {"value": 30}},
True,
marks=pytest.mark.xfail,
),
],
)
def test_open_interactive_session(interactive_session_type):
def test_open_interactive_session(
interactive_session_type, reana_info, is_autoclosure_message_expected
):
"""Test opening an interactive session."""
status_code = 200
workflow_id = "d9304bdf-0d19-45d9-ae87-d5fd18059193"
Expand All @@ -836,10 +858,14 @@ def test_open_interactive_session(interactive_session_type):
with patch(
"reana_client.api.client.current_rs_api_client",
make_mock_api_client("reana-server")(mock_response, mock_http_response),
), patch(
"reana_client.api.client.info",
return_value=reana_info,
):
expected_message = "{reana_server_url}/{workflow_id}".format(
expected_url_session = "{reana_server_url}/{workflow_id}".format(
reana_server_url=reana_server_url, workflow_id=workflow_id
)
expected_auto_closure_message = "will be automatically closed after 30 days"
result = runner.invoke(
cli,
[
Expand All @@ -851,7 +877,11 @@ def test_open_interactive_session(interactive_session_type):
interactive_session_type,
],
)
assert expected_message in result.output
assert expected_url_session in result.output
if is_autoclosure_message_expected:
assert expected_auto_closure_message in result.output
else:
assert expected_auto_closure_message not in result.output


def test_close_interactive_session():
Expand Down

0 comments on commit 489c3ba

Please sign in to comment.