Use snaps_utils to get credentials in tempest
[functest.git] / functest / tests / unit / openstack / tempest / test_tempest.py
index 8476f9f..292eb75 100644 (file)
@@ -5,6 +5,8 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 
+# pylint: disable=missing-docstring
+
 import logging
 import unittest
 
@@ -15,10 +17,16 @@ from functest.opnfv_tests.openstack.tempest import tempest
 from functest.opnfv_tests.openstack.tempest import conf_utils
 from functest.utils.constants import CONST
 
+from snaps.openstack.os_credentials import OSCreds
+
 
 class OSTempestTesting(unittest.TestCase):
 
     def setUp(self):
+        os_creds = OSCreds(
+            username='user', password='pass',
+            auth_url='http://foo.com:5000/v3', project_name='bar')
+
         with mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
                         'conf_utils.get_verifier_id',
                         return_value='test_deploy_id'), \
@@ -30,14 +38,14 @@ class OSTempestTesting(unittest.TestCase):
                        return_value='test_verifier_repo_dir'), \
             mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
                        'conf_utils.get_verifier_deployment_dir',
-                       return_value='test_verifier_deploy_dir'):
+                       return_value='test_verifier_deploy_dir'), \
+            mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                       'get_credentials',
+                       return_value=os_creds):
             self.tempestcommon = tempest.TempestCommon()
             self.tempestsmoke_serial = tempest.TempestSmokeSerial()
             self.tempestsmoke_parallel = tempest.TempestSmokeParallel()
             self.tempestfull_parallel = tempest.TempestFullParallel()
-            with mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
-                            'conf_utils.install_verifier_ext'):
-                self.tempestmultisite = tempest.TempestMultisite()
             self.tempestcustom = tempest.TempestCustom()
             self.tempestdefcore = tempest.TempestDefcore()
 
@@ -75,8 +83,6 @@ class OSTempestTesting(unittest.TestCase):
         self.tempestcommon.MODE = mode
         if self.tempestcommon.MODE == 'smoke':
             testr_mode = "smoke"
-        elif self.tempestcommon.MODE == 'feature_multisite':
-            testr_mode = "'[Kk]ingbird'"
         elif self.tempestcommon.MODE == 'full':
             testr_mode = ""
         else:
@@ -96,9 +102,6 @@ class OSTempestTesting(unittest.TestCase):
     def test_generate_test_list_smoke_mode(self):
         self._test_generate_test_list_mode_default('smoke')
 
-    def test_generate_test_list_feature_multisite_mode(self):
-        self._test_generate_test_list_mode_default('feature_multisite')
-
     def test_generate_test_list_full_mode(self):
         self._test_generate_test_list_mode_default('full')
 
@@ -112,8 +115,8 @@ class OSTempestTesting(unittest.TestCase):
             mock.patch.object(self.tempestcommon, 'read_file',
                               return_value=['test1', 'test2']):
             conf_utils.TEMPEST_BLACKLIST = Exception
-            CONST.INSTALLER_TYPE = 'installer_type'
-            CONST.DEPLOY_SCENARIO = 'deploy_scenario'
+            CONST.__setattr__('INSTALLER_TYPE', 'installer_type')
+            CONST.__setattr__('DEPLOY_SCENARIO', 'deploy_scenario')
             self.tempestcommon.apply_tempest_blacklist()
             obj = m()
             obj.write.assert_any_call('test1\n')
@@ -128,8 +131,8 @@ class OSTempestTesting(unittest.TestCase):
                               return_value=['test1', 'test2']), \
             mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
                        'yaml.safe_load', return_value=item_dict):
-            CONST.INSTALLER_TYPE = 'installer_type'
-            CONST.DEPLOY_SCENARIO = 'deploy_scenario'
+            CONST.__setattr__('INSTALLER_TYPE', 'installer_type')
+            CONST.__setattr__('DEPLOY_SCENARIO', 'deploy_scenario')
             self.tempestcommon.apply_tempest_blacklist()
             obj = m()
             obj.write.assert_any_call('test1\n')
@@ -149,24 +152,6 @@ class OSTempestTesting(unittest.TestCase):
                 assert_any_call("Starting Tempest test suite: '%s'."
                                 % cmd_line)
 
-    @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.logger.info')
-    def test_parse_verifier_result_default(self, mock_logger_info):
-        self.tempestcommon.VERIFICATION_ID = 'test_uuid'
-        self.tempestcommon.case_name = 'test_case_name'
-        stdout = ['Testscount||2', 'Success||2', 'Skipped||0', 'Failures||0']
-        with mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
-                        'subprocess.Popen') as mock_popen, \
-            mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
-                       'ft_utils.check_success_rate') as mock_method, \
-                mock.patch('__builtin__.open', mock.mock_open()):
-            mock_stdout = mock.Mock()
-            attrs = {'stdout': stdout}
-            mock_stdout.configure_mock(**attrs)
-            mock_popen.return_value = mock_stdout
-
-            self.tempestcommon.parse_verifier_result()
-            mock_method.assert_any_call('test_case_name', 100)
-
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
                 'os.path.exists', return_value=False)
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.os.makedirs',
@@ -179,8 +164,19 @@ class OSTempestTesting(unittest.TestCase):
                 'os.path.exists', return_value=False)
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.os.makedirs')
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
-                'conf_utils.create_tempest_resources', side_effect=Exception)
-    def test_run_create_tempest_resources_ko(self, *args):
+                'TempestResourcesManager.create', side_effect=Exception)
+    def test_run_tempest_create_resources_ko(self, *args):
+        self.assertEqual(self.tempestcommon.run(),
+                         testcase.TestCase.EX_RUN_ERROR)
+
+    @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
+                'os.path.exists', return_value=False)
+    @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.os.makedirs')
+    @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
+                'TempestResourcesManager.create', return_value={})
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                'get_active_compute_cnt', side_effect=Exception)
+    def test_run_get_active_compute_cnt_ko(self, *args):
         self.assertEqual(self.tempestcommon.run(),
                          testcase.TestCase.EX_RUN_ERROR)
 
@@ -188,7 +184,9 @@ class OSTempestTesting(unittest.TestCase):
                 'os.path.exists', return_value=False)
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.os.makedirs')
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
-                'conf_utils.create_tempest_resources', return_value={})
+                'TempestResourcesManager.create', return_value={})
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                'get_active_compute_cnt', return_value=2)
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
                 'conf_utils.configure_tempest', side_effect=Exception)
     def test_run_configure_tempest_ko(self, *args):
@@ -199,7 +197,9 @@ class OSTempestTesting(unittest.TestCase):
                 'os.path.exists', return_value=False)
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.os.makedirs')
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
-                'conf_utils.create_tempest_resources', return_value={})
+                'TempestResourcesManager.create', return_value={})
+    @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+                'get_active_compute_cnt', return_value=2)
     @mock.patch('functest.opnfv_tests.openstack.tempest.tempest.'
                 'conf_utils.configure_tempest')
     def _test_run(self, status, *args):