X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=bluval%2Fblucon.py;h=7f720485c60e893fb8b7339000c6a72e95dbd7c3;hb=cc1dfc853f1b2b70efae2c3b9dae7ebe55fb75c1;hp=5d7406bf59192f51e3fd321699a38e997d841191;hpb=5e95a40c528d9c6ae881a0e9c49628bb20c344ec;p=validation.git diff --git a/bluval/blucon.py b/bluval/blucon.py index 5d7406b..7f72048 100644 --- a/bluval/blucon.py +++ b/bluval/blucon.py @@ -29,22 +29,44 @@ import yaml from bluutil import BluvalError from bluutil import ShowStopperError +_OPTIONAL_ALSO = False + +def get_volumes(layer): + """Create a list with volumes to mount in the container for given layer + """ + mypath = Path(__file__).absolute() + volume_yaml = yaml.safe_load(mypath.parents[0].joinpath("volumes.yaml").open()) + + if layer not in volume_yaml['layers']: + return '' + if volume_yaml['layers'][layer] is None: + return '' + + volume_list = '' + for vol in volume_yaml['layers'][layer]: + if volume_yaml['volumes'][vol]['local'] == '': + continue + volume_list = (volume_list + ' -v ' + + volume_yaml['volumes'][vol]['local'] + ':' + + volume_yaml['volumes'][vol]['target']) + return volume_list + + def invoke_docker(bluprint, layer): """Start docker container for given layer """ - cmd = ("docker run" - " -v $HOME/.ssh:/root/.ssh" - " -v $HOME/.kube/config:/root/.kube/config" - " -v $VALIDATION_HOME/tests/variables.yaml:" - "/opt/akraino/validation/tests/variables.yaml" - " -v $AKRAINO_HOME/results:/opt/akraino/results" + + volume_list = get_volumes('common') + get_volumes(layer) + cmd = ("docker run" + volume_list + " akraino/validation:{0}-latest" - " bin/sh -c" + " /bin/sh -c" " 'cd /opt/akraino/validation " - "&& python bluval/bluval.py -l {0} {1}'").format(layer, bluprint) + "&& python bluval/bluval.py -l {0} {1} {2}'" + .format(layer, ("-o" if _OPTIONAL_ALSO else ""), bluprint)) + args = [cmd] try: - print('Invoking {}'.format(args)) + print('\nInvoking {}'.format(args)) subprocess.call(args, shell=True) except OSError: #print('Error while executing {}'.format(args)) @@ -67,14 +89,19 @@ def invoke_dockers(yaml_loc, layer, blueprint_name): @click.command() @click.argument('blueprint') @click.option('--layer', '-l') -def main(blueprint, layer): +@click.option('--optional_also', '-o', is_flag=True) +def main(blueprint, layer, optional_also): """Takes blueprint name and optional layer. Validates inputs and derives yaml location from blueprint name. Invokes validate on blue print. """ + global _OPTIONAL_ALSO # pylint: disable=global-statement mypath = Path(__file__).absolute() yaml_loc = mypath.parents[0].joinpath('bluval-{}.yaml'.format(blueprint)) if layer is not None: layer = layer.lower() + if optional_also: + _OPTIONAL_ALSO = True + print("_OPTIONAL_ALSO {}".format(_OPTIONAL_ALSO)) try: invoke_dockers(yaml_loc, layer, blueprint) except ShowStopperError as err: