2 ##############################################################################
3 # Copyright (c) 2019 AT&T Intellectual Property. #
4 # Copyright (c) 2019 Nokia. #
6 # Licensed under the Apache License, Version 2.0 (the "License"); you may #
7 # not use this file except in compliance with the License. #
9 # You may obtain a copy of the License at #
10 # http://www.apache.org/licenses/LICENSE-2.0 #
12 # Unless required by applicable law or agreed to in writing, software #
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15 # See the License for the specific language governing permissions and #
16 # limitations under the License. #
17 ##############################################################################
18 """This module parses yaml file, reads layers runs container for each layer.
24 from pathlib import Path
29 from bluutil import BluvalError
30 from bluutil import ShowStopperError
32 def invoke_docker(bluprint, layer):
33 """Start docker container for given layer
36 " -v $HOME/.ssh:/root/.ssh"
37 " -v $HOME/.kube/config:/root/.kube/config"
38 " -v $VALIDATION_HOME/tests/variables.yaml:"
39 "/opt/akraino/validation/tests/variables.yaml"
40 " -v $AKRAINO_HOME/results:/opt/akraino/results"
41 " akraino/validation:{0}-latest"
43 " 'cd /opt/akraino/validation "
44 "&& python bluval/bluval.py -l {0} {1}'").format(layer, bluprint)
47 print('Invoking {}'.format(args))
48 subprocess.call(args, shell=True)
50 #print('Error while executing {}'.format(args))
51 raise BluvalError(OSError)
54 def invoke_dockers(yaml_loc, layer, blueprint_name):
55 """Parses yaml file and starts docker container for one/all layers
57 with open(str(yaml_loc)) as yaml_file:
58 yamldoc = yaml.safe_load(yaml_file)
59 blueprint = yamldoc['blueprint']
60 if layer is None or layer == "all":
61 for each_layer in blueprint['layers']:
62 invoke_docker(blueprint_name, each_layer)
64 invoke_docker(blueprint_name, layer)
68 @click.argument('blueprint')
69 @click.option('--layer', '-l')
70 def main(blueprint, layer):
71 """Takes blueprint name and optional layer. Validates inputs and derives
72 yaml location from blueprint name. Invokes validate on blue print.
74 mypath = Path(__file__).absolute()
75 yaml_loc = mypath.parents[0].joinpath('bluval-{}.yaml'.format(blueprint))
79 invoke_dockers(yaml_loc, layer, blueprint)
80 except ShowStopperError as err:
81 print('ShowStopperError:', err)
82 except BluvalError as err:
83 print('Unexpected BluvalError', err)
86 print("Exception in user code:")
88 traceback.print_exc(file=sys.stdout)
93 if __name__ == "__main__":
94 # pylint: disable=no-value-for-parameter