Add schema validate and refresh 78/114678/2
authorSimran Singhal <singhalsimran0@gmail.com>
Sun, 8 Nov 2020 17:28:10 +0000 (22:58 +0530)
committerSimran Singhal <singhalsimran0@gmail.com>
Sat, 14 Nov 2020 04:40:33 +0000 (10:10 +0530)
Issue-ID: VNFSDK-614

Change-Id: I5d451b8a486f46bc37e189d3e36d0a1ffe230382
Signed-off-by: Simran Singhal <singhalsimran0@gmail.com>
profiles/robot/src/main/resources/script/discover-robot-testcases.py

index 06c460a..fbb8d8b 100644 (file)
@@ -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' \