aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xfunctest/ci/exec_test.sh15
-rwxr-xr-xfunctest/ci/run_tests.py2
-rw-r--r--functest/core/testcase_base.py47
-rwxr-xr-xfunctest/opnfv_tests/openstack/vping/vping_base.py2
-rwxr-xr-xfunctest/opnfv_tests/sdn/odl/odl.py3
-rw-r--r--functest/tests/unit/core/test_testcase_base.py9
-rw-r--r--functest/tests/unit/odl/test_odl.py8
-rw-r--r--functest/utils/functest_utils.py34
8 files changed, 95 insertions, 25 deletions
diff --git a/functest/ci/exec_test.sh b/functest/ci/exec_test.sh
index 109de078f..7c96d69c3 100755
--- a/functest/ci/exec_test.sh
+++ b/functest/ci/exec_test.sh
@@ -47,11 +47,13 @@ function odl_tests(){
neutron_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
odl_ip=${neutron_ip}
odl_port=8080
+ odl_restport=8181
if [ "$INSTALLER_TYPE" == "fuel" ]; then
odl_port=8282
elif [ "$INSTALLER_TYPE" == "apex" ]; then
odl_ip=$SDN_CONTROLLER_IP
- odl_port=8181
+ odl_port=8081
+ odl_restport=8081
elif [ "$INSTALLER_TYPE" == "joid" ]; then
odl_ip=$SDN_CONTROLLER
elif [ "$INSTALLER_TYPE" == "compass" ]; then
@@ -78,10 +80,15 @@ function run_test(){
odl_tests
[[ "$report" == "-r" ]] && args=-p
${FUNCTEST_TEST_DIR}/sdn/odl/odl.py \
- --keystoneip $keystone_ip --neutronip $neutron_ip \
- --osusername ${OS_USERNAME} --ostenantname ${OS_TENANT_NAME} \
+ --keystoneip $keystone_ip \
+ --neutronip $neutron_ip \
+ --odlip $odl_ip \
+ --odlrestconfport $odl_restport \
+ --odlwebport $odl_port \
--ospassword ${OS_PASSWORD} \
- --odlip $odl_ip --odlwebport $odl_port ${args}
+ --ostenantname ${OS_TENANT_NAME} \
+ --osusername ${OS_USERNAME} \
+ ${args}
;;
"vims")
python ${FUNCTEST_TEST_DIR}/vnf/ims/vims.py $clean_flag $report
diff --git a/functest/ci/run_tests.py b/functest/ci/run_tests.py
index 10f1ac9a1..a5f1ab9e8 100755
--- a/functest/ci/run_tests.py
+++ b/functest/ci/run_tests.py
@@ -155,7 +155,7 @@ def run_test(test, tier_name, testcases=None):
result = test_case.run()
if result == testcase_base.TestcaseBase.EX_OK:
if GlobalVariables.REPORT_FLAG:
- test_case.push_to_db()
+ test_case.publish_report()
result = test_case.check_criteria()
except ImportError:
logger.exception("Cannot import module {}".format(
diff --git a/functest/core/testcase_base.py b/functest/core/testcase_base.py
index 838b63983..ec46bc643 100644
--- a/functest/core/testcase_base.py
+++ b/functest/core/testcase_base.py
@@ -9,6 +9,7 @@
import os
+from functest.utils.constants import CONST
import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
@@ -17,7 +18,7 @@ class TestcaseBase(object):
EX_OK = os.EX_OK
EX_RUN_ERROR = os.EX_SOFTWARE
- EX_PUSH_TO_DB_ERROR = os.EX_SOFTWARE - 1
+ EX_PUBLISH_RESULT_FAILED = os.EX_SOFTWARE - 1
EX_TESTCASE_FAILED = os.EX_SOFTWARE - 2
logger = ft_logger.Logger(__name__).getLogger()
@@ -43,21 +44,45 @@ class TestcaseBase(object):
self.logger.error("Run must be implemented")
return TestcaseBase.EX_RUN_ERROR
- def push_to_db(self):
+ def publish_report(self):
+ if "RESULTS_STORE" in os.environ:
+ CONST.results_test_db_url = os.environ['RESULTS_STORE']
+
try:
assert self.project_name
assert self.case_name
assert self.criteria
assert self.start_time
assert self.stop_time
- if ft_utils.push_results_to_db(
- self.project_name, self.case_name, self.start_time,
- self.stop_time, self.criteria, self.details):
- self.logger.info("The results were successfully pushed to DB")
- return TestcaseBase.EX_OK
+ if CONST.results_test_db_url.lower().startswith(
+ ("http://", "https://")):
+ self.push_to_db()
+ elif CONST.results_test_db_url.lower().startswith("file://"):
+ self.write_to_file()
else:
- self.logger.error("The results cannot be pushed to DB")
- return TestcaseBase.EX_PUSH_TO_DB_ERROR
+ self.logger.error("Please check parameter test_db_url and "
+ "OS environ variable RESTULTS_STORE")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED
except Exception:
- self.logger.exception("The results cannot be pushed to DB")
- return TestcaseBase.EX_PUSH_TO_DB_ERROR
+ self.logger.exception("The results cannot be stored")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED
+
+ def write_to_file(self):
+ if ft_utils.write_results_to_file(
+ self.project_name, self.case_name, self.start_time,
+ self.stop_time, self.criteria, self.details):
+ self.logger.info("The results were successfully written to a file")
+ return TestcaseBase.EX_OK
+ else:
+ self.logger.error("write results to a file failed")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED
+
+ def push_to_db(self):
+ if ft_utils.push_results_to_db(
+ self.project_name, self.case_name, self.start_time,
+ self.stop_time, self.criteria, self.details):
+ self.logger.info("The results were successfully pushed to DB")
+ return TestcaseBase.EX_OK
+ else:
+ self.logger.error("The results cannot be pushed to DB")
+ return TestcaseBase.EX_PUBLISH_RESULT_FAILED
diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py
index a5309bd44..8285d93f8 100755
--- a/functest/opnfv_tests/openstack/vping/vping_base.py
+++ b/functest/opnfv_tests/openstack/vping/vping_base.py
@@ -289,6 +289,6 @@ class VPingMain(object):
if result != VPingBase.EX_OK:
return result
if kwargs['report']:
- return self.vping.push_to_db()
+ return self.vping.publish_report()
except Exception:
return VPingBase.EX_RUN_ERROR
diff --git a/functest/opnfv_tests/sdn/odl/odl.py b/functest/opnfv_tests/sdn/odl/odl.py
index 606d59a11..339c305ef 100755
--- a/functest/opnfv_tests/sdn/odl/odl.py
+++ b/functest/opnfv_tests/sdn/odl/odl.py
@@ -162,6 +162,7 @@ class ODLTests(testcase_base.TestcaseBase):
elif installer_type == 'apex':
kwargs['odlip'] = os.environ['SDN_CONTROLLER_IP']
kwargs['odlwebport'] = '8081'
+ kwargs['odlrestconfport'] = '8081'
elif installer_type == 'joid':
kwargs['odlip'] = os.environ['SDN_CONTROLLER']
elif installer_type == 'compass':
@@ -231,6 +232,6 @@ if __name__ == '__main__':
if result != testcase_base.TestcaseBase.EX_OK:
sys.exit(result)
if args['pushtodb']:
- sys.exit(odl.push_to_db())
+ sys.exit(odl.publish_report())
except Exception:
sys.exit(testcase_base.TestcaseBase.EX_RUN_ERROR)
diff --git a/functest/tests/unit/core/test_testcase_base.py b/functest/tests/unit/core/test_testcase_base.py
index b6efa40dc..8df524b0f 100644
--- a/functest/tests/unit/core/test_testcase_base.py
+++ b/functest/tests/unit/core/test_testcase_base.py
@@ -9,9 +9,11 @@
import logging
import mock
+import os
import unittest
mock.patch('logging.FileHandler').start() # noqa
+
from functest.core import testcase_base
@@ -32,11 +34,12 @@ class TestcaseBaseTesting(unittest.TestCase):
self.assertEqual(self.test.run(),
testcase_base.TestcaseBase.EX_RUN_ERROR)
+ @mock.patch.dict(os.environ, {})
@mock.patch('functest.utils.functest_utils.push_results_to_db',
return_value=False)
def _test_missing_attribute(self, mock_function):
- self.assertEqual(self.test.push_to_db(),
- testcase_base.TestcaseBase.EX_PUSH_TO_DB_ERROR)
+ self.assertEqual(self.test.publish_report(),
+ testcase_base.TestcaseBase.EX_PUBLISH_RESULT_FAILED)
mock_function.assert_not_called()
def test_missing_case_name(self):
@@ -69,7 +72,7 @@ class TestcaseBaseTesting(unittest.TestCase):
return_value=False)
def test_push_to_db_failed(self, mock_function):
self.assertEqual(self.test.push_to_db(),
- testcase_base.TestcaseBase.EX_PUSH_TO_DB_ERROR)
+ testcase_base.TestcaseBase.EX_PUBLISH_RESULT_FAILED)
mock_function.assert_called_once_with(
self.test.project, self.test.case_name, self.test.start_time,
self.test.stop_time, self.test.criteria, self.test.details)
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index 8a52a9f63..59ab2c654 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -337,7 +337,8 @@ class ODLTesting(unittest.TestCase):
testcase_base.TestcaseBase.EX_RUN_ERROR)
def _test_run(self, status=testcase_base.TestcaseBase.EX_OK,
- exception=None, odlip="127.0.0.3", odlwebport="8080"):
+ exception=None, odlip="127.0.0.3", odlwebport="8080",
+ odlrestconfport="8181"):
with mock.patch('functest.utils.openstack_utils.get_endpoint',
side_effect=self._fake_url_for):
if exception:
@@ -348,7 +349,7 @@ class ODLTesting(unittest.TestCase):
self.test.main.assert_called_once_with(
keystoneip=self._keystone_ip, neutronip=self._neutron_ip,
odlip=odlip, odlpassword=self._odl_password,
- odlrestconfport=self._odl_restconfport,
+ odlrestconfport=odlrestconfport,
odlusername=self._odl_username, odlwebport=odlwebport,
ospassword=self._os_password, ostenantname=self._os_tenantname,
osusername=self._os_username)
@@ -410,7 +411,8 @@ class ODLTesting(unittest.TestCase):
os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
os.environ["INSTALLER_TYPE"] = "apex"
self._test_run(testcase_base.TestcaseBase.EX_OK,
- odlip=self._sdn_controller_ip, odlwebport='8081')
+ odlip=self._sdn_controller_ip, odlwebport='8081',
+ odlrestconfport='8081')
def test_run_joid_missing_sdn_controller(self):
with mock.patch('functest.utils.openstack_utils.get_endpoint',
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index 1879e6943..2bf87a05c 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -23,8 +23,10 @@ import requests
import yaml
from git import Repo
+from functest.utils.constants import CONST
import functest.utils.functest_logger as ft_logger
+
logger = ft_logger.Logger("functest_utils").getLogger()
@@ -181,13 +183,43 @@ def logger_test_results(project, case_name, status, details):
'd': details})
+def write_results_to_file(project, case_name, start_date,
+ stop_date, criteria, details):
+ file_path = re.split(r'://', CONST.results_test_db_url)[1]
+
+ try:
+ installer = os.environ['INSTALLER_TYPE']
+ scenario = os.environ['DEPLOY_SCENARIO']
+ pod_name = os.environ['NODE_NAME']
+ except KeyError as e:
+ logger.error("Please set env var: " + str(e))
+ return False
+
+ test_start = dt.fromtimestamp(start_date).strftime('%Y-%m-%d %H:%M:%S')
+ test_stop = dt.fromtimestamp(stop_date).strftime('%Y-%m-%d %H:%M:%S')
+
+ params = {"project_name": project, "case_name": case_name,
+ "pod_name": pod_name, "installer": installer,
+ "scenario": scenario, "criteria": criteria,
+ "start_date": test_start, "stop_date": test_stop,
+ "details": details}
+ try:
+ with open(file_path, "a+w") as outfile:
+ json.dump(params, outfile)
+ outfile.write("\n")
+ return True
+ except Exception as e:
+ logger.error("write result data into a file failed: %s" % e)
+ return False
+
+
def push_results_to_db(project, case_name,
start_date, stop_date, criteria, details):
"""
POST results to the Result target DB
"""
# Retrieve params from CI and conf
- url = get_db_url() + "/results"
+ url = CONST.results_test_db_url + "/results"
try:
installer = os.environ['INSTALLER_TYPE']