X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=validation.git;a=blobdiff_plain;f=bluval%2Fbluval.py;fp=bluval%2Fbluval.py;h=bf5e0c854a0f35f1301099df1ae046be0a1ebafe;hp=0000000000000000000000000000000000000000;hb=ab78424814fb38a688567daad9c7091b5f58d3d6;hpb=9d259351c724e101ea3bdee657c5f669efbb149c diff --git a/bluval/bluval.py b/bluval/bluval.py new file mode 100644 index 0000000..bf5e0c8 --- /dev/null +++ b/bluval/bluval.py @@ -0,0 +1,62 @@ +#!/usr/bin/python3 +############################################################################## +# Copyright (c) 2019 AT&T Intellectual Property. # +# Copyright (c) 2019 Nokia. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. # +# # +# You may obtain a copy of the License at # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +############################################################################## +"""This module parses yaml file, reads sections, testcases and executes each +testcase +""" + +import subprocess +import sys +import yaml + +def run_testcase(testcase): + """Runs a single testcase + """ + show_stopper = testcase.get('show_stopper', False) + + print('Executing testcase {}'.format(testcase['name'])) + print(' show_stopper {}'.format(show_stopper)) + cmd = 'robot {}'.format(testcase['what']) + print('Invoking {}'.format(cmd)) + try: + status = subprocess.call(cmd, shell=True) + if status != 0 and testcase['show_stopper']: + print('Show stopper testcase failed') + return status + except OSError: + print('Error while executing {}'.format(cmd)) + return -1 + return status + + +def parse_yaml(testcase_loc): + """Parse yaml file and do tasks on each testcase + """ + with open(testcase_loc) as testcase_file: + testcases = yaml.safe_load(testcase_file) + blueprint = testcases['blueprint'] + for section in blueprint['sections']: + print('## Section {}'.format(section)) + for testcase in blueprint[section]: + run_testcase(testcase) + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print('usage: bluval.py ') + sys.exit(1) + parse_yaml(sys.argv[1])