diff --git a/reana_server/rest/workflows.py b/reana_server/rest/workflows.py index be620e2b..716b247d 100644 --- a/reana_server/rest/workflows.py +++ b/reana_server/rest/workflows.py @@ -525,9 +525,6 @@ def create_workflow(user): # noqa if is_uuid_v4(workflow_name): return jsonify({"message": "Workflow name cannot be a valid UUIDv4."}), 400 - validate_workflow(reana_spec_file, input_parameters={}) - workspace_root_path = reana_spec_file.get("workspace", {}).get("root_path") - workflow_engine = reana_spec_file["workflow"]["type"] if workflow_engine not in REANA_WORKFLOW_ENGINES: raise Exception("Unknown workflow type.") @@ -536,6 +533,9 @@ def create_workflow(user): # noqa workflow_engine, reana_spec_file.get("inputs", {}).get("options", {}) ) + workspace_root_path = reana_spec_file.get("workspace", {}).get("root_path") + validate_workspace_path(reana_spec_file) + retention_days = reana_spec_file.get("workspace", {}).get("retention_days") retention_rules = get_workspace_retention_rules(retention_days) @@ -1230,6 +1230,12 @@ def start_workflow(workflow_id_or_name, user): # noqa ) if "yadage" in (workflow.type_, restart_type): _load_and_save_yadage_spec(workflow, operational_options) + + input_parameters = parameters.get("input_parameters", {}) + validate_workflow( + workflow.reana_specification, input_parameters=input_parameters + ) + publish_workflow_submission(workflow, user.id_, parameters) response = { "message": "Workflow submitted.", diff --git a/tests/test_views.py b/tests/test_views.py index d0d3ade9..8a49da90 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -10,6 +10,7 @@ import copy import json +import logging from io import BytesIO from uuid import uuid4 @@ -134,7 +135,7 @@ def test_create_workflow( ) assert res.status_code == 400 - # not valid specification + # not valid specification. but there is no validation workflow_specification = { "workflow": {"specification": {}, "type": "serial"}, } @@ -147,7 +148,7 @@ def test_create_workflow( }, data=json.dumps(workflow_specification), ) - assert res.status_code == 400 + assert res.status_code == 200 # correct case workflow_specification = sample_serial_workflow_in_db.reana_specification @@ -163,6 +164,33 @@ def test_create_workflow( assert res.status_code == 200 +def test_start_workflow_validates_specification( + app, session, default_user, sample_serial_workflow_in_db +): + with app.test_client() as client: + sample_serial_workflow_in_db.status = RunStatus.created + sample_serial_workflow_in_db.name = "test" + workflow_specification = copy.deepcopy( + sample_serial_workflow_in_db.reana_specification + ) + workflow_specification["workflow"]["type"] = "unknown" + sample_serial_workflow_in_db.reana_specification = workflow_specification + session.add(sample_serial_workflow_in_db) + session.commit() + res = client.post( + url_for( + "workflows.start_workflow", + workflow_id_or_name=str(sample_serial_workflow_in_db.id_), + ), + headers={"Content-Type": "application/json"}, + query_string={ + "access_token": default_user.access_token, + }, + data=json.dumps({}), + ) + assert res.status_code == 400 + + def test_restart_workflow_validates_specification( app, session, default_user, sample_serial_workflow_in_db ):