Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2020 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
"""REANA Workflow Operational Options implementation utils.""" | ||
|
||
import copy | ||
import subprocess | ||
import sys | ||
|
||
import click | ||
|
||
from reana_commons.errors import REANAValidationError | ||
|
||
available_options = { | ||
'CACHE': {'serial': 'CACHE'}, | ||
'FROM': {'serial': 'FROM'}, | ||
'TARGET': {'serial': 'TARGET', 'cwl': '--target'}, | ||
'toplevel': {'yadage': 'toplevel'}, | ||
'initdir': {'yadage': 'initdir'} | ||
} | ||
|
||
|
||
def validate_operational_options(workflow_type, parsed_options): | ||
"""Validate and return workflow operational options. | ||
:param workflow_type: A supported workflow specification type. | ||
:param parsed_options: A dict with the parsed operational parameters. | ||
:returns: A dictionary which represents the valid workflow specification. | ||
""" | ||
if not isinstance(parsed_options, dict): | ||
raise REANAValidationError( | ||
'==> ERROR: Operational options must be a dictionary.') | ||
elif not parsed_options: | ||
return parsed_options | ||
|
||
validated_options = copy.deepcopy(parsed_options) | ||
for option in parsed_options.keys(): | ||
if option not in available_options: | ||
raise REANAValidationError( | ||
'==> ERROR: Operational option "{0}" not supported.' | ||
.format(option)) | ||
translation = available_options[option].get(workflow_type) | ||
if not translation: | ||
raise REANAValidationError( | ||
'==> ERROR: Operational option "{0}" not supported for' | ||
' {1} workflows.' | ||
.format(option, workflow_type)) | ||
# Override engine specific options | ||
if translation not in available_options: | ||
validated_options[translation] = validated_options[option] | ||
del validated_options[option] | ||
|
||
return validated_options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2020 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""REANA-Commons utilities testing.""" | ||
|
||
import pytest | ||
|
||
from reana_commons.errors import REANAValidationError | ||
from reana_commons.operational_options import validate_operational_options | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'workflow_type, options, except_msg', | ||
[ | ||
('serial', 'CACHE=on', 'must be a dict'), | ||
('yadage', {'unsupported': 'yes'}, 'not supported'), | ||
('foo', {'TARGET': 'gendata'}, | ||
'not supported for {workflow_type} workflows'), | ||
('serial', {'toplevel': 'github:reanahub/awesome-workflow'}, | ||
'not supported for {workflow_type} workflows'), | ||
], | ||
) | ||
def test_unsupported(workflow_type, options, except_msg): | ||
"""Test unsupported operational options cases.""" | ||
with pytest.raises(REANAValidationError) as e: | ||
validate_operational_options(workflow_type, options) | ||
assert except_msg.format(workflow_type=workflow_type) in e.value.message | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'workflow_type, options, option', | ||
[ | ||
('serial', {'FROM': 'fitdata'}, 'FROM'), | ||
('yadage', {'toplevel': 'github:reanahub/awesome-workflow'}, | ||
'toplevel'), | ||
('cwl', {'TARGET': 'gendata'}, '--target') | ||
], | ||
) | ||
def test_successful(workflow_type, options, option): | ||
"""Test successful operational options cases.""" | ||
validated_options = validate_operational_options(workflow_type, options) | ||
assert validated_options[option] |