Skip to content

Commit

Permalink
rest: remove specification validate from "create" endpoint
Browse files Browse the repository at this point in the history
- because client doesn't include Yadage specification in "create" endpoint, validation fails;
- workflow validation is moved to "start_workflow" so in case Yadage specification has multiple files, they can be loaded and properly validated.

closes reanahub#535
  • Loading branch information
Vladyslav Moisieienkov committed Aug 9, 2022
1 parent 4952c16 commit 0a3a1bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 9 additions & 3 deletions reana_server/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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)

Expand Down Expand Up @@ -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.",
Expand Down
31 changes: 29 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,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"},
}
Expand All @@ -147,7 +147,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
Expand All @@ -163,6 +163,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"
session.add(sample_serial_workflow_in_db)
session.commit()

workflow_specification = copy.deepcopy(
sample_serial_workflow_in_db.reana_specification
)
workflow_specification["workflow"]["steps"] = "unknown"
body = {
"reana_specification": workflow_specification,
}
res = client.post(
url_for("workflows.start_workflow", workflow_id_or_name="test"),
headers={"Content-Type": "application/json"},
query_string={
"access_token": default_user.access_token,
},
data=json.dumps(body),
)
assert res.status_code == 400


def test_restart_workflow_validates_specification(
app, session, default_user, sample_serial_workflow_in_db
):
Expand Down

0 comments on commit 0a3a1bd

Please sign in to comment.