Repository: reanahub/reana-client

Issue:
interactive session: notify user of auto-closure
Administrators of a REANA cluster can specify a time limit after which inactive interactive sessions (such as Jupyter notebooks) will be automatically closed (https://github.com/reanahub/reana-workflow-controller/issues/498).

In https://github.com/reanahub/reana-ui/pull/312, the UI notification about the successful creation of an interactive session, was enriched with the inactivity time after which it will be automatically closed, if present.
However, this message is not shown in `reana-client` when creating an interactive session with `reana-client open`. We should include a similar message ("Please note that it will be automatically closed after X days of inactivity") also in the CLI client.

Discussion:
mdonadoni: Works well, good job! 

PS: This PR needs to be rebased

Patch:
diff --git a/reana_client/cli/workflow.py b/reana_client/cli/workflow.py
index f0bf692..ac55e0e 100644
--- a/reana_client/cli/workflow.py
+++ b/reana_client/cli/workflow.py
@@ -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:
@@ -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))


Test patch:
diff --git a/tests/test_cli_workflows.py b/tests/test_cli_workflows.py
index cb1c733..248ab9b 100644
--- a/tests/test_cli_workflows.py
+++ b/tests/test_cli_workflows.py
@@ -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"
@@ -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,
                 [
@@ -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():