Merge "printyaml method fix"
authorKanagaraj Manickam <kanagaraj.manickam@huawei.com>
Wed, 16 Dec 2020 04:25:37 +0000 (04:25 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 16 Dec 2020 04:25:37 +0000 (04:25 +0000)
deployment/zip/src/main/release/conf/open-cli.properties
framework/src/main/resources/open-cli.properties
framework/src/test/resources/open-cli.properties
profiles/robot/src/main/java/org/onap/cli/fw/robot/cmd/OnapRobotCommand.java
profiles/robot/src/main/java/org/onap/cli/fw/robot/conf/OnapCommandRobotConstants.java
profiles/robot/src/main/resources/open-cli-robot.properties [new file with mode: 0644]
profiles/robot/src/main/resources/open-cli-schema/robot/auto-discover-robot-testcases.yaml [new file with mode: 0644]
profiles/robot/src/main/resources/script/discover-robot-testcases.py
validate/validation/src/test/resources/open-cli.properties

index 27b592a..b289df2 100644 (file)
@@ -48,4 +48,4 @@ cli.schema.profile.available=http,snmp,cmd,robot
 
 #other properties to load (it should be hanled when plugins are made as externally register-able
 #when command plugin management support is enabled in oclip
-cli.schema.profile.confs=open-cli-http.properties,open-cli-snmp.properties,open-cli-cmd.properties
\ No newline at end of file
+cli.schema.profile.confs=open-cli-http.properties,open-cli-snmp.properties,open-cli-cmd.properties,open-cli-robot.properties
\ No newline at end of file
index 5f2a3d8..a22559a 100644 (file)
@@ -43,7 +43,7 @@ cli.sample.gen.name=sample1
 cli.sample.gen.target=./open-cli-sample
 
 # mrkanag Move this to db, once exteranl command registration is supported in place of discovery
-cli.schema.profile.available=http,snmp,cmd
+cli.schema.profile.available=http,snmp,cmd,robot
 
 #other properties to load (it should be hanled when plugins are made as externally register-able
 #when command plugin management support is enabled in oclip
index bd8a6ac..07696c4 100644 (file)
@@ -42,7 +42,7 @@ cli.sample.gen.enable=false
 cli.sample.gen.target=./open-cli-sample
 
 # mrkanag Move this to db, once exteranl command registration is supported in place of discovery
-cli.schema.profile.available=http,snmp,cmd
+cli.schema.profile.available=http,snmp,cmd,robot
 
 #other properties to load (it should be hanled when plugins are made as externally register-able
 #when command plugin management support is enabled in oclip
index fa99595..c4dc1bc 100644 (file)
@@ -19,11 +19,14 @@ package org.onap.cli.fw.robot.cmd;
 import java.util.List;
 import java.util.Map;
 
+import org.onap.cli.fw.conf.OnapCommandConfig;
 import org.onap.cli.fw.schema.OnapCommandSchema;
+import org.onap.cli.fw.cmd.OnapCommand;
 import org.onap.cli.fw.cmd.cmd.OpenCommandShellCmd;
 import org.onap.cli.fw.robot.conf.OnapCommandRobotConstants;
 import org.onap.cli.fw.robot.schema.OnapCommandSchemaRobotLoader;
 import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.registrar.OnapCommandRegistrar;
 
 /**
  * Oclip robot Command.
@@ -32,8 +35,16 @@ import org.onap.cli.fw.error.OnapCommandException;
 @OnapCommandSchema(type = OnapCommandRobotConstants.ROBOT_SCHEMA_PROFILE)
 public class OnapRobotCommand extends OpenCommandShellCmd {
 
-  public OnapRobotCommand() {
+  public OnapRobotCommand() throws OnapCommandException {
     super.addDefaultSchemas(OnapCommandRobotConstants.DEFAULT_PARAMETER_ROBOT_FILE_NAME);
+    if(Boolean.parseBoolean(OnapCommandConfig.getPropertyValue(OnapCommandRobotConstants.ROBOT_DISCOVER_TESTCASES)))
+      this.discover();
+  }
+
+  public void discover() throws OnapCommandException {
+    OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("auto-discover-robot-testcases");
+    cmd.getParametersMap().get("api-tests-folder-path").setValue(OnapCommandRobotConstants.ROBOT_API_TESTS_FOLDER_PATH);
+    cmd.execute();
   }
 
   @Override
index 9aac11e..c081489 100644 (file)
@@ -21,11 +21,16 @@ package org.onap.cli.fw.robot.conf;
  *
  */
 public class OnapCommandRobotConstants {
+    public static final String CONF = "open-cli-robot.properties";
     public static final String ROBOT_SCHEMA_PROFILE = "robot";
     public static final String ROBOT = "robot";
 
     public static final String DEFAULT_PARAMETER_ROBOT_FILE_NAME = "default_input_parameters_robot.yaml";
 
+    // discover robot testcases
+    public static final String ROBOT_DISCOVER_TESTCASES = "cli.robot.discover";
+    public static final String ROBOT_API_TESTS_FOLDER_PATH = "cli.robot.api_tests_folder_path";
+
     private OnapCommandRobotConstants() {
         //as per coding standard !
     }
diff --git a/profiles/robot/src/main/resources/open-cli-robot.properties b/profiles/robot/src/main/resources/open-cli-robot.properties
new file mode 100644 (file)
index 0000000..9b15759
--- /dev/null
@@ -0,0 +1,16 @@
+# Copyright 2020 Simran Singhal.
+#
+# 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.
+
+cli.robot.discover=false
+cli.robot.api_tests_folder_path=
\ No newline at end of file
diff --git a/profiles/robot/src/main/resources/open-cli-schema/robot/auto-discover-robot-testcases.yaml b/profiles/robot/src/main/resources/open-cli-schema/robot/auto-discover-robot-testcases.yaml
new file mode 100644 (file)
index 0000000..a03dbd1
--- /dev/null
@@ -0,0 +1,48 @@
+# Copyright 2020 Simran Singhal.
+#
+# 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.
+
+open_cli_schema_version: 1.0
+
+name: auto-discover-robot-testcases
+
+description: Auto discover and register all robot test cases
+
+info:
+  product: open-cli
+  service: discover
+  type: cmd
+  author: Simran Singhal singhalsimran0@gmail.com
+
+parameters:
+  - name: api-tests-folder-path
+    type: string
+    description: Location to api-tests folder
+    short_option: l
+    long_option: api-tests-folder-path
+    is_optional: false
+  - name: format
+    type: string
+    description: Output formats, supported formats such as table, csv, json, yaml
+    short_option: f
+    long_option: format
+    default_value: text
+    is_default_param: true
+
+robot:
+  command:
+    -  python3 $s{env:OPEN_CLI_HOME}/script/discover-robot-testcases.py --api-tests-folder-path ${api-tests-folder-path}
+  success_codes:
+    - 0
+  working_directory: .
+  output: $stdout
\ No newline at end of file
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' \
index b2f0f81..500632b 100644 (file)
@@ -38,8 +38,8 @@ cli.sample.gen.enable=false
 cli.sample.gen.target=.
 
 # mrkanag Move this to db, once exteranl command registration is supported in place of discovery
-cli.schema.profile.available=http,snmp
+cli.schema.profile.available=http,snmp,robot
 
 #other properties to load (it should be hanled when plugins are made as externally register-able
 #when command plugin management support is enabled in oclip
-cli.schema.profile.confs=open-cli-http.properties,open-cli-snmp.properties
+cli.schema.profile.confs=open-cli-http.properties,open-cli-snmp.properties,open-cli-robot.properties