Merge "Update setuptools version to 30.0.0"
authorJose Lausuch <jose.lausuch@ericsson.com>
Tue, 6 Jun 2017 13:14:51 +0000 (13:14 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Tue, 6 Jun 2017 13:14:52 +0000 (13:14 +0000)
functest/ci/config_aarch64_patch.yaml
functest/ci/config_functest.yaml
functest/ci/config_patch.yaml
functest/ci/prepare_env.py
functest/opnfv_tests/sdn/odl/odl.py
functest/opnfv_tests/sdn/onos/teston/adapters/foundation.py
functest/tests/unit/ci/test_prepare_env.py
functest/tests/unit/utils/test_decorators.py
functest/tests/unit/utils/test_functest_utils.py
functest/utils/functest_utils.py

index cd395ab..80cf4cc 100644 (file)
@@ -16,6 +16,9 @@ os:
     vping:
         image_name: TestVM
 
+    tempest:
+        use_custom_images: False
+
     odl_sfc:
         image_base_url: "http://artifacts.opnfv.org/sfc/demo"
         image_name: sfc_nsh_danube
index 9b79607..5aa5bfd 100644 (file)
@@ -139,7 +139,7 @@ tempest:
     private_subnet_name: tempest-subnet
     private_subnet_cidr: 192.168.150.0/24
     router_name: tempest-router
-    use_custom_images: False
+    use_custom_images: True
     use_custom_flavors: False
     volume_device_name: vdc
 
index d47766b..ad8b088 100644 (file)
@@ -13,16 +13,13 @@ fdio:
         flavor_extra_specs: {'hw:mem_page_size':'large'}
         image_properties: {'hw_mem_page_size':'large'}
     tempest:
-        use_custom_images: True
         use_custom_flavors: True
 ovs:
     general:
         flavor_extra_specs: {'hw:mem_page_size':'large'}
         image_properties: {'hw_mem_page_size':'large'}
     tempest:
-        use_custom_images: True
         use_custom_flavors: True
 multisite:
     tempest:
-        use_custom_images: True
         use_custom_flavors: True
index 8e17a4f..e03bc65 100755 (executable)
@@ -234,12 +234,15 @@ def source_rc_file():
                 CONST.__setattr__('OS_PASSWORD', value)
 
 
-def patch_config_file():
+def update_config_file():
     patch_file(CONFIG_PATCH_PATH)
 
     if pod_arch and pod_arch in arch_filter:
         patch_file(CONFIG_AARCH64_PATCH_PATH)
 
+    if "TEST_DB_URL" in os.environ:
+        update_db_url()
+
 
 def patch_file(patch_file_path):
     logger.debug('Updating file: %s', patch_file_path)
@@ -257,7 +260,15 @@ def patch_file(patch_file_path):
         os.remove(CONFIG_FUNCTEST_PATH)
         with open(CONFIG_FUNCTEST_PATH, "w") as f:
             f.write(yaml.dump(new_functest_yaml, default_style='"'))
-        f.close()
+
+
+def update_db_url():
+    with open(CONFIG_FUNCTEST_PATH) as f:
+        functest_yaml = yaml.safe_load(f)
+
+    with open(CONFIG_FUNCTEST_PATH, "w") as f:
+        functest_yaml["results"]["test_db_url"] = os.environ.get('TEST_DB_URL')
+        f.write(yaml.dump(functest_yaml, default_style='"'))
 
 
 def verify_deployment():
@@ -381,7 +392,7 @@ def main(**kwargs):
             get_deployment_handler()
             create_directories()
             source_rc_file()
-            patch_config_file()
+            update_config_file()
             verify_deployment()
             install_rally()
             install_tempest()
index b2b0b77..fb5dcbc 100755 (executable)
@@ -34,6 +34,7 @@ from six import StringIO
 from six.moves import urllib
 
 from functest.core import testcase
+from functest.utils import constants
 import functest.utils.openstack_utils as op_utils
 
 __author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
@@ -65,14 +66,15 @@ class ODLResultVisitor(robot.api.ResultVisitor):
 class ODLTests(testcase.TestCase):
     """ODL test runner."""
 
-    repos = "/home/opnfv/repos/"
-    odl_test_repo = os.path.join(repos, "odl_test")
+    odl_test_repo = os.path.join(
+        constants.CONST.__getattribute__('dir_repos'), 'odl_test')
     neutron_suite_dir = os.path.join(odl_test_repo,
                                      "csit/suites/openstack/neutron")
     basic_suite_dir = os.path.join(odl_test_repo,
                                    "csit/suites/integration/basic")
     default_suites = [basic_suite_dir, neutron_suite_dir]
-    res_dir = '/home/opnfv/functest/results/odl/'
+    res_dir = os.path.join(
+        constants.CONST.__getattribute__('dir_results'), 'odl')
     __logger = logging.getLogger(__name__)
 
     @classmethod
index f9eee7a..aed98ee 100644 (file)
@@ -18,7 +18,6 @@ import re
 import time
 
 from functest.utils.constants import CONST
-import functest.utils.functest_utils as ft_utils
 
 
 class Foundation(object):
@@ -55,7 +54,7 @@ class Foundation(object):
         """
         Get Default Parameters value
         """
-        self.Result_DB = ft_utils.get_db_url()
+        self.Result_DB = CONST.__getattribute__("results_test_db_url")
         self.masterusername = CONST.__getattribute__('ONOS_onosbench_username')
         self.masterpassword = CONST.__getattribute__('ONOS_onosbench_password')
         self.agentusername = CONST.__getattribute__('ONOS_onoscli_username')
index 513e723..85d1918 100644 (file)
@@ -20,6 +20,7 @@ class PrepareEnvTesting(unittest.TestCase):
 
     def setUp(self):
         self.prepare_envparser = prepare_env.PrepareEnvParser()
+        self.db_url_env = 'http://foo/testdb'
 
     @mock.patch('functest.ci.prepare_env.logger.info')
     def test_print_separator(self, mock_logger_info):
@@ -297,6 +298,22 @@ class PrepareEnvTesting(unittest.TestCase):
             prepare_env.patch_file('test_file')
             self.assertTrue(m.called)
 
+    @mock.patch('functest.ci.prepare_env.ft_utils.get_functest_yaml',
+                return_value={'tkey1': 'tvalue1'})
+    @mock.patch('functest.ci.prepare_env.yaml.safe_load',
+                return_value={'test_scenario': {'tkey': 'tvalue'}})
+    @mock.patch('functest.ci.prepare_env.update_db_url')
+    def test_update_db_url(self, mock_db_url, mock_safe_load,
+                           mock_get_functest_yaml):
+        CONST.__setattr__('DEPLOY_SCENARIO', 'default_scenario')
+        with mock.patch("__builtin__.open", mock.mock_open()), \
+            mock.patch('functest.ci.prepare_env.yaml.dump'), \
+                mock.patch.dict('functest.ci.prepare_env.os.environ',
+                                {'TEST_DB_URL': self.db_url_env},
+                                clear=True):
+            prepare_env.update_config_file()
+            self.assertTrue(mock_db_url.called)
+
     @mock.patch('functest.ci.prepare_env.logger.info')
     def test_verify_deployment_error(self, mock_logger_error):
         mock_popen = mock.Mock()
@@ -418,14 +435,14 @@ class PrepareEnvTesting(unittest.TestCase):
     @mock.patch('functest.ci.prepare_env.install_tempest')
     @mock.patch('functest.ci.prepare_env.install_rally')
     @mock.patch('functest.ci.prepare_env.verify_deployment')
-    @mock.patch('functest.ci.prepare_env.patch_config_file')
+    @mock.patch('functest.ci.prepare_env.update_config_file')
     @mock.patch('functest.ci.prepare_env.source_rc_file')
     @mock.patch('functest.ci.prepare_env.create_directories')
     @mock.patch('functest.ci.prepare_env.get_deployment_handler')
     @mock.patch('functest.ci.prepare_env.check_env_variables')
     @mock.patch('functest.ci.prepare_env.logger.info')
     def test_main_start(self, mock_logger_info, mock_env_var, mock_dep_handler,
-                        mock_create_dir, mock_source_rc, mock_patch_config,
+                        mock_create_dir, mock_source_rc, mock_update_config,
                         mock_verify_depl, mock_install_rally,
                         mock_install_temp, mock_create_flavor,
                         mock_check_env, mock_print_info):
@@ -438,7 +455,7 @@ class PrepareEnvTesting(unittest.TestCase):
             self.assertTrue(mock_dep_handler.called)
             self.assertTrue(mock_create_dir.called)
             self.assertTrue(mock_source_rc.called)
-            self.assertTrue(mock_patch_config.called)
+            self.assertTrue(mock_update_config.called)
             self.assertTrue(mock_verify_depl.called)
             self.assertTrue(mock_install_rally.called)
             self.assertTrue(mock_install_temp.called)
index 44448f2..82291fa 100644 (file)
@@ -20,6 +20,7 @@ import mock
 
 from functest.utils import decorators
 from functest.utils import functest_utils
+from functest.utils.constants import CONST
 
 __author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
 
@@ -65,34 +66,29 @@ class DecoratorsTesting(unittest.TestCase):
                 'details': {}, 'criteria': self._result}
         return json.dumps(data, sort_keys=True)
 
-    @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
-                return_value='http://127.0.0.1')
     @mock.patch('{}.get_version'.format(functest_utils.__name__),
                 return_value=VERSION)
     @mock.patch('requests.post')
     def test_http_shema(self, *args):
+        CONST.__setattr__('results_test_db_url', 'http://127.0.0.1')
         self.assertTrue(functest_utils.push_results_to_db(
             self._project_name, self._case_name, self._start_time,
             self._stop_time, self._result, {}))
         args[1].assert_called_once_with()
-        args[2].assert_called_once_with()
         args[0].assert_called_once_with(
             'http://127.0.0.1', data=self._get_json(),
             headers={'Content-Type': 'application/json'})
 
-    @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
-                return_value="/dev/null")
-    def test_wrong_shema(self, mock_method=None):
+    def test_wrong_shema(self):
+        CONST.__setattr__('results_test_db_url', '/dev/null')
         self.assertFalse(functest_utils.push_results_to_db(
             self._project_name, self._case_name, self._start_time,
             self._stop_time, self._result, {}))
-        mock_method.assert_called_once_with()
 
     @mock.patch('{}.get_version'.format(functest_utils.__name__),
                 return_value=VERSION)
-    @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
-                return_value=URL)
     def _test_dump(self, *args):
+        CONST.__setattr__('results_test_db_url', URL)
         with mock.patch.object(decorators, 'open', mock.mock_open(),
                                create=True) as mock_open:
             self.assertTrue(functest_utils.push_results_to_db(
@@ -104,7 +100,6 @@ class DecoratorsTesting(unittest.TestCase):
         self.assertIn('POST', call_args[0])
         self.assertIn(self._get_json(), call_args[0])
         args[0].assert_called_once_with()
-        args[1].assert_called_once_with()
 
     @mock.patch('os.makedirs')
     def test_default_dump(self, mock_method=None):
@@ -116,16 +111,14 @@ class DecoratorsTesting(unittest.TestCase):
         self._test_dump()
         mock_method.assert_called_once_with(DIR)
 
-    @mock.patch('{}.get_db_url'.format(functest_utils.__name__),
-                return_value=URL)
     @mock.patch('os.makedirs', side_effect=OSError)
     def test_makedirs_exc(self, *args):
+        CONST.__setattr__('results_test_db_url', URL)
         self.assertFalse(
             functest_utils.push_results_to_db(
                 self._project_name, self._case_name, self._start_time,
                 self._stop_time, self._result, {}))
         args[0].assert_called_once_with(DIR)
-        args[1].assert_called_once_with()
 
 
 if __name__ == "__main__":
index 12604c1..d84a320 100644 (file)
@@ -19,6 +19,7 @@ from six.moves import urllib
 
 from functest.tests.unit import test_utils
 from functest.utils import functest_utils
+from functest.utils.constants import CONST
 
 
 class FunctestUtilsTesting(unittest.TestCase):
@@ -58,6 +59,7 @@ class FunctestUtilsTesting(unittest.TestCase):
         self.config_yaml = os.path.normpath(os.path.join(os.path.dirname(
             os.path.abspath(__file__)), '../../../ci/config_functest.yaml'))
         self.db_url_env = 'http://foo/testdb'
+        self.testcases_yaml = "test_testcases_yaml"
         self.file_yaml = {'general': {'openstack': {'image_name':
                                                     'test_image_name'}}}
 
@@ -208,23 +210,9 @@ class FunctestUtilsTesting(unittest.TestCase):
             self.assertEqual(functest_utils.get_build_tag(),
                              self.build_tag)
 
-    def test_get_db_url_env_var(self):
-        with mock.patch.dict(os.environ,
-                             {'TEST_DB_URL': self.db_url_env,
-                              'CONFIG_FUNCTEST_YAML':
-                              "./functest/ci/config_functest.yaml"},
-                             clear=True):
-            self.assertEqual(functest_utils.get_db_url(),
-                             self.db_url_env)
-
-    @mock.patch('functest.utils.functest_utils.get_functest_config')
-    def test_get_db_url_default(self, mock_get_functest_config):
-        mock_get_functest_config.return_value = self.db_url
-        self.assertEqual(functest_utils.get_db_url(), self.db_url)
-        mock_get_functest_config.assert_called_once_with('results.test_db_url')
-
     @mock.patch('functest.utils.functest_utils.logger.info')
     def test_logger_test_results(self, mock_logger_info):
+        CONST.__setattr__('results_test_db_url', self.db_url)
         with mock.patch('functest.utils.functest_utils.get_pod_name',
                         return_value=self.node_name), \
                 mock.patch('functest.utils.functest_utils.get_scenario',
@@ -232,9 +220,7 @@ class FunctestUtilsTesting(unittest.TestCase):
                 mock.patch('functest.utils.functest_utils.get_version',
                            return_value=self.version), \
                 mock.patch('functest.utils.functest_utils.get_build_tag',
-                           return_value=self.build_tag), \
-                mock.patch('functest.utils.functest_utils.get_db_url',
-                           return_value=self.db_url):
+                           return_value=self.build_tag):
             functest_utils.logger_test_results(self.project, self.case_name,
                                                self.status, self.details)
             mock_logger_info.assert_called_once_with(
@@ -251,7 +237,7 @@ class FunctestUtilsTesting(unittest.TestCase):
                 "details:\t%(d)s\n"
                 % {'p': self.project,
                     'n': self.case_name,
-                    'db': self.db_url,
+                    'db': CONST.__getattribute__('results_test_db_url'),
                     'pod': self.node_name,
                     'v': self.version,
                     's': self.scenario,
@@ -269,11 +255,10 @@ class FunctestUtilsTesting(unittest.TestCase):
 
     def _test_push_results_to_db_missing_env(self, env_var):
         dic = self._get_env_dict(env_var)
-        with mock.patch('functest.utils.functest_utils.get_db_url',
-                        return_value=self.db_url), \
-                mock.patch.dict(os.environ,
-                                dic,
-                                clear=True), \
+        CONST.__setattr__('results_test_db_url', self.db_url)
+        with mock.patch.dict(os.environ,
+                             dic,
+                             clear=True), \
                 mock.patch('functest.utils.functest_utils.logger.error') \
                 as mock_logger_error:
             functest_utils.push_results_to_db(self.project, self.case_name,
@@ -297,11 +282,10 @@ class FunctestUtilsTesting(unittest.TestCase):
 
     def test_push_results_to_db_request_post_failed(self):
         dic = self._get_env_dict(None)
-        with mock.patch('functest.utils.functest_utils.get_db_url',
-                        return_value=self.db_url), \
-                mock.patch.dict(os.environ,
-                                dic,
-                                clear=True), \
+        CONST.__setattr__('results_test_db_url', self.db_url)
+        with mock.patch.dict(os.environ,
+                             dic,
+                             clear=True), \
                 mock.patch('functest.utils.functest_utils.logger.error') \
                 as mock_logger_error, \
                 mock.patch('functest.utils.functest_utils.requests.post',
@@ -320,11 +304,10 @@ class FunctestUtilsTesting(unittest.TestCase):
 
     def test_push_results_to_db_request_post_exception(self):
         dic = self._get_env_dict(None)
-        with mock.patch('functest.utils.functest_utils.get_db_url',
-                        return_value=self.db_url), \
-                mock.patch.dict(os.environ,
-                                dic,
-                                clear=True), \
+        CONST.__setattr__('results_test_db_url', self.db_url)
+        with mock.patch.dict(os.environ,
+                             dic,
+                             clear=True), \
                 mock.patch('functest.utils.functest_utils.logger.error') \
                 as mock_logger_error, \
                 mock.patch('functest.utils.functest_utils.requests.post',
@@ -338,11 +321,10 @@ class FunctestUtilsTesting(unittest.TestCase):
 
     def test_push_results_to_db_default(self):
         dic = self._get_env_dict(None)
-        with mock.patch('functest.utils.functest_utils.get_db_url',
-                        return_value=self.db_url), \
-                mock.patch.dict(os.environ,
-                                dic,
-                                clear=True), \
+        CONST.__setattr__('results_test_db_url', self.db_url)
+        with mock.patch.dict(os.environ,
+                             dic,
+                             clear=True), \
                 mock.patch('functest.utils.functest_utils.requests.post'):
             self.assertTrue(functest_utils.
                             push_results_to_db(self.project, self.case_name,
@@ -562,11 +544,13 @@ class FunctestUtilsTesting(unittest.TestCase):
 
     # TODO: merge_dicts
 
-    def test_get_testcases_file_dir(self):
+    @mock.patch('functest.utils.functest_utils.get_functest_config')
+    def test_get_testcases_file_dir(self, mock_get_functest_config):
+        mock_get_functest_config.return_value = self.testcases_yaml
         resp = functest_utils.get_testcases_file_dir()
-        self.assertEqual(resp,
-                         "/home/opnfv/repos/functest/"
-                         "functest/ci/testcases.yaml")
+        self.assertEqual(resp, self.testcases_yaml)
+        mock_get_functest_config.assert_called_once_with(
+            'general.functest.testcases_yaml')
 
     def test_get_functest_yaml(self):
         with mock.patch('six.moves.builtins.open', mock.mock_open()), \
index dc20eea..995d94f 100644 (file)
@@ -26,6 +26,7 @@ from git import Repo
 
 from functest.utils import constants
 from functest.utils import decorators
+from functest.utils.constants import CONST
 
 logger = logging.getLogger(__name__)
 
@@ -149,24 +150,15 @@ def get_build_tag():
     return build_tag
 
 
-def get_db_url():
+def logger_test_results(project, case_name, status, details):
     """
-    Returns DB URL
+    Format test case results for the logger
     """
-    # TODO use CONST mechanism
-    try:
-        # if TEST_DB_URL declared in env variable, use it!
-        db_url = os.environ['TEST_DB_URL']
-    except KeyError:
-        db_url = get_functest_config('results.test_db_url')
-    return db_url
-
-
-def logger_test_results(project, case_name, status, details):
     pod_name = get_pod_name()
     scenario = get_scenario()
     version = get_version()
     build_tag = get_build_tag()
+    db_url = CONST.__getattribute__("results_test_db_url")
 
     logger.info(
         "\n"
@@ -182,7 +174,7 @@ def logger_test_results(project, case_name, status, details):
         "details:\t%(d)s\n"
         % {'p': project,
             'n': case_name,
-            'db': get_db_url(),
+            'db': db_url,
             'pod': pod_name,
             'v': version,
             's': scenario,
@@ -198,7 +190,7 @@ def push_results_to_db(project, case_name,
     POST results to the Result target DB
     """
     # Retrieve params from CI and conf
-    url = get_db_url()
+    url = CONST.__getattribute__("results_test_db_url")
 
     try:
         installer = os.environ['INSTALLER_TYPE']