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, testcases and executes each
26 def run_testcase(testcase):
27 """Runs a single testcase
29 show_stopper = testcase.get('show_stopper', False)
30 what = testcase.get('what')
31 results = "results/"+what
32 command = '{} {} {} {}'.format("robot", "-d", results, what)
34 print('Executing testcase {}'.format(testcase['name']))
35 print(' show_stopper {}'.format(show_stopper))
36 print('Invoking {}'.format(command))
38 status = subprocess.call(command, shell=True)
39 if status != 0 and show_stopper:
40 print('Show stopper testcase failed')
43 print('Error while executing {}'.format(command))
48 def validate_layer(blueprint, layer):
49 """validates a layer by validating all testcases under that layer
51 print('## Layer {}'.format(layer))
52 for testcase in blueprint[layer]:
53 run_testcase(testcase)
56 def validate_blueprint(yaml_loc, layer):
57 """Parse yaml file and validates given layer. If no layer given all layers
60 with open(yaml_loc) as yaml_file:
61 yamldoc = yaml.safe_load(yaml_file)
62 blueprint = yamldoc['blueprint']
64 for each_layer in blueprint['layers']:
65 validate_layer(blueprint, each_layer)
67 validate_layer(blueprint, layer)
71 @click.argument('blueprint')
72 @click.option('--layer', '-l')
73 def main(blueprint, layer):
74 """Takes blueprint name and optional layer. Validates inputs and derives
75 yaml location from blueprint name. Invokes validate on blue print.
77 yaml_loc = 'bluval/bluval-{}.yaml'.format(blueprint)
79 validate_blueprint(yaml_loc, layer)
82 if __name__ == "__main__":
83 # pylint: disable=no-value-for-parameter