aboutsummaryrefslogtreecommitdiffstats
path: root/profiles
diff options
context:
space:
mode:
Diffstat (limited to 'profiles')
-rw-r--r--profiles/robot/src/main/resources/script/discover-robot-testcases.py131
-rw-r--r--profiles/robot/src/main/resources/script/run-robot-testcase.py56
2 files changed, 163 insertions, 24 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 fbb8d8be..a7f03552 100644
--- a/profiles/robot/src/main/resources/script/discover-robot-testcases.py
+++ b/profiles/robot/src/main/resources/script/discover-robot-testcases.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# Copyright 2020 Simran Singhal.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# Copyright 2020 Huawei Technologies Co., Ltd.
+# 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.
+
import os
import argparse
from argparse import RawTextHelpFormatter
@@ -33,7 +44,6 @@ class OcompException(Exception):
class OCOMP:
def run(self, command, params={}):
- CMD_NAME = 'oclip'
CMD = [CMD_NAME]
CMD.append(command)
@@ -65,7 +75,7 @@ class LineBreakDumper(Dumper):
if len(self.indents) == 1:
super().write_line_break()
-def create_testcase_yaml(testcase_name, description, testsuite_name, test_suite_folder_path):
+def create_testcase_yaml(testcase_name, description, path_test_suite, testsuite_name, test_suite_folder_path, api_tests_folder_path):
def change_style(style, representer):
def new_representer(dumper, data):
@@ -83,24 +93,72 @@ def create_testcase_yaml(testcase_name, description, testsuite_name, test_suite_
open_cli_schema_version = 1.0
name = re.sub(re.compile('(?:\-){2,}'), '-', testcase_name.replace(' ', '-').lower())
- description = LiteralString(description.replace(r'\n', '\n') + '\n')
-
- product = "etsi-mano"
- service = test_suite_folder_path.split('/')[0]
- info = OrderedDict(product = product, service = service)
-
- test_suite_path = '${api-tests-folder-path}/api-tests/' + test_suite_folder_path + '/' + testsuite_name + '.robot'
- command = ['python3 $s{env:OPEN_CLI_HOME}/script/run-robot-testcase.py --variables-file-path ${variables-file-path} --test-suite ' +
- test_suite_path + ' --testcase ' + testcase_name]
+ if(not description):
+ description = name
+ else:
+ description = LiteralString(description.replace(r'\n', '\n') + '\n')
+
+ product = os.getenv('OPEN_CLI_PRODUCT')
+ if not product:
+ product = "etsi-mano"
+ robotName = testsuite_name.replace(' ', '_')
+ service = test_suite_folder_path.split('/')[0] + '_' + robotName
+
+ if not test_suite_folder_path.split('/')[0]:
+ service = service[1:]
+ author = os.getenv('AUTHOR')
+ if not author:
+ author = 'edgeT team'
+ info = OrderedDict(product = product, service = service, author = author)
+
+ if(data_list_file_path and data_list_file_path1):
+ param_name = "envFilePath"
+ description = "env File Path"
+ type = "string"
+ short_option = "x"
+ long_option = "envFilePath"
+ is_optional = 'false'
+ parameters = [OrderedDict(name = param_name, description = description, type = type, short_option = short_option, long_option = long_option, is_optional = is_optional)]
+
+ rdirection = 'landscape'
+ rname = 'reports_path'
+ rdescription = 'reports path'
+ rscope = 'short'
+ rtype = 'string'
+ attributes = [OrderedDict(name=rname, description=rdescription, scope=rscope, type=rtype)]
+ results = OrderedDict(direction=rdirection, attributes=attributes)
+
+ if path_test_suite.split('.')[-1] != "robot":
+ tcappend = ""
+ else:
+ tcappend = " --testcase " + testcase_name
+ if (data_list_file_path and data_list_file_path1):
+ openCliHome= os.getenv('OPEN_CLI_HOME')
+ command = ['python3 '+openCliHome+'/script/run-robot-testcase.py --test-suite ' +
+ path_test_suite + tcappend + ' --env-file-path ${envFilePath}']
+ else:
+ test_suite_path = '${api-tests-folder-path}/api-tests/' + test_suite_folder_path + '/' + testsuite_name + '.robot'
+ command = ['python3 $s{env:OPEN_CLI_HOME}/script/run-robot-testcase.py --variables-file-path ${variables-file-path} --test-suite ' +
+ test_suite_path + tcappend]
success_codes = [0]
working_directory = '.'
output = '$stdout'
- robot = OrderedDict(command=command, success_codes=success_codes, working_directory=working_directory, output=output)
+ if(data_list_file_path and data_list_file_path1):
+ reports_path = '$s{env:OPEN_CLI_REQUEST_ID}/logs/'
+ result_map = OrderedDict(reports_path=reports_path)
+ robot = OrderedDict(command=command, success_codes=success_codes, working_directory=working_directory, output=output, result_map=result_map)
+ else:
+ robot = OrderedDict(command=command, success_codes=success_codes, working_directory=working_directory,
+ output=output)
- data = OrderedDict(open_cli_schema_version=open_cli_schema_version, name=name, description=description,
- info=info, robot=robot)
+ if(data_list_file_path and data_list_file_path1):
+ data = OrderedDict(open_cli_schema_version=open_cli_schema_version, name=name, description=description, info=info, cmd=robot, parameters=parameters, results=results)
+ yaml_path = openCliHome + '/open-cli-schema/robot' + test_suite_folder_path + testsuite_name
+ else:
+ data = OrderedDict(open_cli_schema_version=open_cli_schema_version, name=name, description=description, info=info,
+ robot=robot)
- yaml_path = os.getenv('OPEN_CLI_HOME') + '/open-cli-schema/robot/' + test_suite_folder_path + '/' + testsuite_name
+ yaml_path = os.getenv('OPEN_CLI_HOME') + '/open-cli-schema/robot/' + test_suite_folder_path + '/' + testsuite_name
os.makedirs(yaml_path, exist_ok=True)
with open(yaml_path + '/' + name + '.yaml', 'w') as file:
@@ -118,7 +176,14 @@ def create_testcase_yaml(testcase_name, description, testsuite_name, test_suite_
print()
def discover_testcases(api_tests_folder_path):
-
+ product = os.getenv('OPEN_CLI_PRODUCT')
+ if data_list_file_path and data_list_file_path1:
+ with open(os.getenv('OPEN_CLI_HOME') + "/conf/vtp.properties", 'w') as file:
+ file.write("cmd." + product + ".envpath=" + data_list_file_path + "\n")
+ with open(os.getenv('OPEN_CLI_HOME') + "/conf/vtp.properties", 'a') as file:
+ file.write("cmd." + product + ".envpath1=" + data_list_file_path1 + "\n")
+
+ #create yaml at file level
for root, dirs, files in os.walk(api_tests_folder_path):
for file in files:
@@ -129,10 +194,20 @@ def discover_testcases(api_tests_folder_path):
suite = TestData(parent=None, source=path_to_test_suite)
for testcase in suite.testcase_table:
test_suite_folder_path = root[len(api_tests_folder_path):]
- create_testcase_yaml(testcase.name, testcase.doc.value, suite.name, test_suite_folder_path)
+ create_testcase_yaml(testcase.name, testcase.doc.value, path_to_test_suite, suite.name, test_suite_folder_path, api_tests_folder_path)
except Exception as e:
pass
+ #create yaml at folder level
+ for root, dirs, files in os.walk(api_tests_folder_path):
+ test_suite_folder_path = api_tests_folder_path
+ for dir in dirs:
+ try:
+ create_testcase_yaml(dir, "run " + test_suite_folder_path + "/" + dir + " suite", os.path.join(root, dir),
+ dir, api_tests_folder_path.split('/')[-1], api_tests_folder_path)
+ except Exception as e:
+ pass
+ break
ocomp = OCOMP()
res = ocomp.run(command='schema-refresh')
@@ -141,6 +216,7 @@ def discover_testcases(api_tests_folder_path):
raise OcompException(9999, result)
def main():
+ global CMD_NAME
text = 'This command helps to discover all robot testcases\n' \
'These python modules are need to be installed for running the tests\n' \
'robotframework==3.1\n' \
@@ -153,9 +229,19 @@ def main():
parser = argparse.ArgumentParser(description=text, formatter_class=RawTextHelpFormatter)
parser.add_argument('--api-tests-folder-path', action='store', dest='api_tests_folder_path',
help='Location to api-tests folder', required=True)
+ parser.add_argument('--data_list_file_path', action='store', dest='data_list_file_path',
+ help='Location to data list file path')
+ parser.add_argument('--data_list_file_path1', action='store', dest='data_list_file_path1',
+ help='Location to data list1 file path')
args = parser.parse_args()
- api_tests_folder_path = args.api_tests_folder_path + '/api-tests/'
+ api_tests_folder_path = args.api_tests_folder_path
+ global data_list_file_path,data_list_file_path1
+ data_list_file_path = args.data_list_file_path
+ data_list_file_path1 = args.data_list_file_path1
+
+ if not (data_list_file_path and data_list_file_path1):
+ api_tests_folder_path = args.api_tests_folder_path + '/api-tests/'
if os.path.exists(api_tests_folder_path):
@@ -165,6 +251,13 @@ def main():
else:
raise Exception('Given api-tests folder location does not exist\n')
+ try:
+ subprocess.check_call('ocomp -v', shell=True)
+ CMD_NAME = 'ocomp'
+ except subprocess.CalledProcessError:
+ subprocess.check_call('oclip -v', shell=True)
+ CMD_NAME = 'oclip'
+
discover_testcases(api_tests_folder_path)
if __name__ == '__main__':
diff --git a/profiles/robot/src/main/resources/script/run-robot-testcase.py b/profiles/robot/src/main/resources/script/run-robot-testcase.py
index 9fe0f607..57a93eb8 100644
--- a/profiles/robot/src/main/resources/script/run-robot-testcase.py
+++ b/profiles/robot/src/main/resources/script/run-robot-testcase.py
@@ -13,6 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# Copyright 2020 Huawei Technologies Co., Ltd.
+# 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.
+
import os
import argparse
import uuid
@@ -21,13 +32,33 @@ from argparse import RawTextHelpFormatter
def execute_robot_run(request_id, test_suite, testcase, variables_file_path):
output_dir = os.getenv('OPEN_CLI_HOME') + '/data/executions/' + request_id + '/logs'
+ if env_file_path:
+ product = os.getenv('OPEN_CLI_PRODUCT')
+ data_list_file_path = data_list_file_path1 = ""
+ with open(os.getenv('OPEN_CLI_HOME') + '/conf/vtp.properties') as fp:
+ line = fp.readline()
+ while line:
+ key = line.split("=")[0]
+ value = line.split("=")[-1]
+ if key == "cmd." + product + ".envpath":
+ data_list_file_path = value.replace("\n", "")
+ if key == "cmd." + product + ".envpath1":
+ data_list_file_path1 = value.replace("\n", "")
+ line = fp.readline()
+ if(data_list_file_path and data_list_file_path1):
+ os.system("cat " + data_list_file_path + ">" + data_list_file_path1)
+ cmd = 'sed -i -e "s/sysdev/' + os.environ['SYSDEV'].replace('"', '') + '/g" -e "s/sysapp/' + os.environ['SYSAPP'].replace('"', '') + '/g" -e "s/sysmecm/' + os.environ['SYSMECM'].replace('"', '') + '/g" -e "s/schema/' + os.environ['SCHEMA'].replace('"', '') + '/g" -e "s/rhost/' + os.environ['HOST'].replace('"', '') + '/g" -e "s/Port/' + os.environ['PORT'].replace('"', '') + '/g" -e "s/H_Ip/' + os.environ['HOSTIP'].replace('"', '') + '/g" -e "s/apmPORT/' + os.environ['APMPORT'].replace('"', '') + '/g" -e "s/esrPORT/' + os.environ['ESRPORT'].replace('"', '') + '/g" -e "s/appoPORT/' + os.environ['APPOPORT'].replace('"', '') + '/g" -e "s/lcmPORT/' + os.environ['LCMPORT'].replace('"', '') + '/g" -e "s/righthip/' + os.environ['RIGHTHOSTIP'].replace('"', '') + '/g" -e "s/xsdkdate/' + os.environ['XSDKDATE'].replace('"', '') + '/g" -e "s/signature/' + os.environ['SIGNATURE'].replace('"', '') + '/g" -e "s/loginname/' + os.environ['LOGINNAME'].replace('"', '') + '/g" -e "s/loginpass/' + os.environ['LOGINPASS'].replace('"', '') + '/g" -e "s/loginphone/' + os.environ['LOGINPHONE'].replace('"', '') + '/g" -e "s/packagename/' + os.environ['APPNAME'].replace('"', '') + '/g" -e "s/industry/' + os.environ['INDUSTRY'].replace('"', '') + '/g" -e "s/apptype/' + os.environ['TYPE'].replace('"', '') + '/g" -e "s/affinity/' + os.environ['AFFINITY'].replace('"', '') + '/g" -e "s/yFile/' + os.environ['YAMLFile'].replace('"', '') + '/g" -e "s/servicename/' + os.environ['SERVICENAME'].replace('"', '') + '/g" ' + data_list_file_path1
+ cmd = cmd.replace("\n", "")
+ os.system(cmd)
with open('run.txt', 'w') as output:
if(variables_file_path):
- run(test_suite, report=None, log=None, test=testcase, variablefile=variables_file_path, stdout=output, stderr=output, outputdir=output_dir)
+ result = run(test_suite, test=testcase, variablefile=variables_file_path, stdout=output, stderr=output, outputdir=output_dir)
else:
- run(test_suite, report=None, log=None, test=testcase, stdout=output, stderr=output, outputdir=output_dir)
+ result = run(test_suite, test=testcase, stdout=output, stderr=output, outputdir=output_dir)
+ if result != 0:
+ raise Exception('RUN TEST CASE FAILED return-code:', result)
if os.path.exists('run.txt'):
with open('run.txt', 'r') as log:
print(log.read())
@@ -50,15 +81,30 @@ def main():
parser.add_argument('--test-suite', action='store', dest='test_suite',
help='Location to test suite file', required=True)
parser.add_argument('--testcase', action='store', dest='testcase',
- help='Name of the testcase', required=True, nargs='+')
+ help='Name of the testcase', required=False, nargs='+')
parser.add_argument('--variables-file-path', action='store', dest='variables_file_path',
help='Location to variable file', nargs='?', const='')
+ parser.add_argument('--env-file-path', action='store', dest='env_file_path',
+ help='Location to env file', required=False)
args = parser.parse_args()
-
+ global env_file_path
+ env_file_path = args.env_file_path
+
+ if env_file_path:
+ with open(env_file_path) as fp:
+ line = fp.readline()
+ while line:
+ key = line.split("=")[0]
+ value = line.split("=")[-1]
+ os.environ[key] = value
+ line = fp.readline()
request_id = args.request_id
test_suite = args.test_suite
- testcase = ' '.join(args.testcase)
+ if args.testcase:
+ testcase = ' '.join(args.testcase)
+ else:
+ testcase = '*'
variables_file_path = ''
if not request_id: