From c1746d5f32728608f2cec44910ac431a07d7c67d Mon Sep 17 00:00:00 2001 From: Simran Singhal Date: Sun, 8 Nov 2020 22:58:10 +0530 Subject: Add schema validate and refresh Issue-ID: VNFSDK-614 Change-Id: I5d451b8a486f46bc37e189d3e36d0a1ffe230382 Signed-off-by: Simran Singhal --- .../resources/script/discover-robot-testcases.py | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'profiles/robot/src/main/resources') 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' \ -- cgit 1.2.3-korg