diff options
author | Kanagaraj Manickam <kanagaraj.manickam@huawei.com> | 2020-12-16 04:25:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-12-16 04:25:08 +0000 |
commit | 81c501c7228181289d6c06b19a762b5eddbe3128 (patch) | |
tree | d5927106d990aebacfcbb7632c947e48289a2859 | |
parent | 463af50098e27111a334b2ed0fd500e38ce03196 (diff) | |
parent | c1746d5f32728608f2cec44910ac431a07d7c67d (diff) |
Merge "Add schema validate and refresh"
-rw-r--r-- | profiles/robot/src/main/resources/script/discover-robot-testcases.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/profiles/robot/src/main/resources/script/discover-robot-testcases.py b/profiles/robot/src/main/resources/script/discover-robot-testcases.py index 06c460a3..fbb8d8be 100644 --- a/profiles/robot/src/main/resources/script/discover-robot-testcases.py +++ b/profiles/robot/src/main/resources/script/discover-robot-testcases.py @@ -22,6 +22,39 @@ from yaml.representer import SafeRepresenter from yaml import Dumper from collections import OrderedDict import re +import subprocess +import sys + +class OcompException(Exception): + def __init__(self, code, message): + super(OcompException, self).__init__() + self.code = code; + self.message = message; + +class OCOMP: + def run(self, command, params={}): + CMD_NAME = 'oclip' + CMD = [CMD_NAME] + + CMD.append(command) + + for name, value in params.items(): + CMD.append('--{}'.format(name)) + CMD.append(value) + + cmd_string = ' '.join(CMD) + + try: + res = subprocess.Popen(CMD, stdout=subprocess.PIPE) + res.wait() + return res + + except OSError as e: + sys.stderr.write(str(e)) + msg = 'failed to executed the command {}'.format(cmd_string) + print (msg) + raise OcompException(9999, msg) + class LiteralString(str): pass @@ -73,6 +106,17 @@ def create_testcase_yaml(testcase_name, description, testsuite_name, test_suite_ with open(yaml_path + '/' + name + '.yaml', 'w') as file: yaml.dump(data, file, Dumper=LineBreakDumper, default_flow_style=False) + ocomp = OCOMP() + res = ocomp.run(command='schema-validate', params={'schema-location': yaml_path + '/' + name + '.yaml'}) + result = res.stdout.read().strip() + + if res.returncode != 0: + if os.path.exists(yaml_path + '/' + name + '.yaml'): + os.remove(yaml_path + '/' + name + '.yaml') + print (yaml_path + '/' + name + '.yaml') + print(result) + print() + def discover_testcases(api_tests_folder_path): for root, dirs, files in os.walk(api_tests_folder_path): @@ -90,6 +134,12 @@ def discover_testcases(api_tests_folder_path): except Exception as e: pass + ocomp = OCOMP() + res = ocomp.run(command='schema-refresh') + result = res.stdout.read().strip() + if res.returncode != 0: + raise OcompException(9999, result) + def main(): text = 'This command helps to discover all robot testcases\n' \ 'These python modules are need to be installed for running the tests\n' \ |