def test_interactive_session_closure(sample_serial_workflow_in_db): """Test closure of an interactive sessions.""" mocked_k8s_client = Mock() workflow = sample_serial_workflow_in_db with patch.multiple('reana_workflow_controller.k8s', current_k8s_appsv1_api_client=mocked_k8s_client, current_k8s_networking_v1beta1=DEFAULT, current_k8s_corev1_api_client=DEFAULT) as mocks: kwrm = KubernetesWorkflowRunManager(workflow) if len(INTERACTIVE_SESSION_TYPES): kwrm.start_interactive_session(INTERACTIVE_SESSION_TYPES[0]) assert workflow.interactive_session_name assert workflow.interactive_session assert workflow.interactive_session_type kwrm.stop_interactive_session() assert workflow.interactive_session_name is None assert workflow.interactive_session is None assert workflow.interactive_session_type is None
def test_interactive_session_closure(sample_serial_workflow_in_db, session): """Test closure of an interactive sessions.""" mocked_k8s_client = Mock() workflow = sample_serial_workflow_in_db with patch.multiple( "reana_workflow_controller.k8s", current_k8s_appsv1_api_client=mocked_k8s_client, current_k8s_networking_api_client=DEFAULT, current_k8s_corev1_api_client=DEFAULT, ): kwrm = KubernetesWorkflowRunManager(workflow) if len(InteractiveSessionType): kwrm.start_interactive_session(InteractiveSessionType(0).name) int_session = InteractiveSession.query.filter_by( owner_id=workflow.owner_id, type_=InteractiveSessionType(0).name, ).first() assert int_session.status == RunStatus.created kwrm.stop_interactive_session(int_session.id_) assert not workflow.sessions.first()
def close_interactive_session(workflow_id_or_name): # noqa r"""Close an interactive workflow session. --- post: summary: Close an interactive workflow session. description: >- This resource is expecting a workflow to close an interactive session within its workspace. operationId: close_interactive_session consumes: - application/json produces: - application/json parameters: - name: user in: query description: Required. UUID of workflow owner. required: true type: string - name: workflow_id_or_name in: path description: Required. Workflow UUID or name. required: true type: string responses: 200: description: >- Request succeeded. The interactive session has been closed. schema: type: object properties: message: type: string examples: application/json: { "message": "The interactive session has been closed", } 400: description: >- Request failed. The incoming data specification seems malformed. examples: application/json: { "message": "Malformed request." } 404: description: >- Request failed. Either User or Workflow does not exist. examples: application/json: { "message": "Workflow 256b25f4-4cfb-4684-b7a8-73872ef455a1 does not exist" } 500: description: >- Request failed. Internal controller error. """ try: user_uuid = request.args["user"] workflow = None workflow = _get_workflow_with_uuid_or_name(workflow_id_or_name, user_uuid) if workflow.interactive_session_name is None: return jsonify({ "message": "Workflow - {} has no open interactive session.".format( workflow_id_or_name) }), 404 kwrm = KubernetesWorkflowRunManager(workflow) kwrm.stop_interactive_session() return jsonify({"message": "The interactive session has been closed"}), 200 except (KeyError, ValueError) as e: status_code = 400 if workflow else 404 return jsonify({"message": str(e)}), status_code except Exception as e: return jsonify({"message": str(e)}), 500