Skip to content

Commit

Permalink
global: validate reana.yaml operational options
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Apr 1, 2020
1 parent 253638f commit 26d66d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
1 change: 0 additions & 1 deletion reana_client/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ def workflow_create(ctx, file, name,
try:
reana_specification = load_reana_spec(click.format_filename(file),
skip_validation)
# TODO: Validate operational options
logging.info('Connecting to {0}'.format(get_api_url()))
response = create_workflow(reana_specification,
name,
Expand Down
34 changes: 23 additions & 11 deletions reana_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import yaml
from jsonschema import ValidationError, validate
from reana_commons.serial import serial_load
from reana_commons.errors import REANAValidationError
from reana_commons.operational_options import validate_operational_options
from reana_commons.utils import get_workflow_status_change_verb

from reana_client.config import (reana_yaml_schema_file_path,
Expand Down Expand Up @@ -109,19 +111,12 @@ def load_workflow_spec(workflow_type, workflow_file, **kwargs):
def load_reana_spec(filepath, skip_validation=False):
"""Load and validate reana specification file.
:raises IOError: Error while reading REANA spec file from given filepath`.
:raises IOError: Error while reading REANA spec file from given `filepath`.
:raises ValidationError: Given REANA spec file does not validate against
REANA specification.
"""
try:
with open(filepath) as f:
reana_yaml = yaml.load(f.read(), Loader=yaml.FullLoader)

if not skip_validation:
logging.info('Validating REANA specification file: {filepath}'
.format(filepath=filepath))
_validate_reana_yaml(reana_yaml)

def _prepare_kwargs(reana_yaml):
kwargs = {}
workflow_type = reana_yaml['workflow']['type']
if workflow_type == 'serial':
Expand All @@ -132,13 +127,30 @@ def load_reana_spec(filepath, skip_validation=False):
kwargs['original'] = True

if 'options' in reana_yaml['inputs']:
# TODO: Validate operational options
try:
reana_yaml['inputs']['options'] = validate_operational_options(
workflow_type,
reana_yaml['inputs']['options'])
except REANAValidationError as e:
click.secho(e.message, err=True, fg='red')
sys.exit(1)
kwargs.update(reana_yaml['inputs']['options'])
return kwargs

try:
with open(filepath) as f:
reana_yaml = yaml.load(f.read(), Loader=yaml.FullLoader)

if not skip_validation:
logging.info('Validating REANA specification file: {filepath}'
.format(filepath=filepath))
_validate_reana_yaml(reana_yaml)

workflow_type = reana_yaml['workflow']['type']
reana_yaml['workflow']['specification'] = load_workflow_spec(
workflow_type,
reana_yaml['workflow'].get('file'),
**kwargs
**_prepare_kwargs(reana_yaml)
)

if workflow_type == 'cwl' and \
Expand Down

0 comments on commit 26d66d6

Please sign in to comment.