diff options
Diffstat (limited to 'functest/tests/unit/utils')
-rw-r--r-- | functest/tests/unit/utils/test_openstack_clean.py | 37 | ||||
-rw-r--r-- | functest/tests/unit/utils/test_openstack_snapshot.py | 2 | ||||
-rw-r--r-- | functest/tests/unit/utils/test_openstack_utils.py | 5 |
3 files changed, 29 insertions, 15 deletions
diff --git a/functest/tests/unit/utils/test_openstack_clean.py b/functest/tests/unit/utils/test_openstack_clean.py index 6ae7faa4..afd9120a 100644 --- a/functest/tests/unit/utils/test_openstack_clean.py +++ b/functest/tests/unit/utils/test_openstack_clean.py @@ -73,8 +73,9 @@ class OSCleanTesting(unittest.TestCase): "-----------------" "---------") + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.logger.debug') - def test_remove_instances(self, mock_logger_debug): + def test_remove_instances(self, mock_logger_debug, *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_instances', return_value=self.test_list): openstack_clean.remove_instances(self.client, self.update_list) @@ -83,16 +84,19 @@ class OSCleanTesting(unittest.TestCase): "instance and will " "NOT be deleted.") + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.logger.debug') - def test_remove_instances_missing_instances(self, mock_logger_debug): + def test_remove_instances_missing_instances(self, mock_logger_debug, + *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_instances', return_value=[]): openstack_clean.remove_instances(self.client, self.update_list) mock_logger_debug.assert_any_call("Removing Nova instances...") mock_logger_debug.assert_any_call("No instances found.") + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.logger.debug') - def test_remove_instances_delete_success(self, mock_logger_debug): + def test_remove_instances_delete_success(self, mock_logger_debug, *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_instances', return_value=self.test_list), \ mock.patch('functest.utils.openstack_clean.os_utils' @@ -105,8 +109,10 @@ class OSCleanTesting(unittest.TestCase): " '\s*\S+'" " ...")) + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.logger.debug') - def test_remove_instances_pending_delete_success(self, mock_logger_debug): + def test_remove_instances_pending_delete_success(self, mock_logger_debug, + *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_instances', return_value=self.deleted_list), \ mock.patch('functest.utils.openstack_clean.os_utils' @@ -118,8 +124,10 @@ class OSCleanTesting(unittest.TestCase): " '\s*\S+'" " ...").assert_not_called() + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.logger.debug') - def test_remove_instances_other_delete_success(self, mock_logger_debug): + def test_remove_instances_other_delete_success(self, mock_logger_debug, + *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_instances', return_value=self.other_list), \ mock.patch('functest.utils.openstack_clean.os_utils' @@ -132,10 +140,11 @@ class OSCleanTesting(unittest.TestCase): " '\s*\S+'" " ...")) + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.logger.error') @mock.patch('functest.utils.openstack_clean.logger.debug') def test_remove_instances_delete_failed(self, mock_logger_debug, - mock_logger_error): + mock_logger_error, *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_instances', return_value=self.test_list), \ mock.patch('functest.utils.openstack_clean.os_utils' @@ -276,7 +285,7 @@ class OSCleanTesting(unittest.TestCase): def test_remove_floatingips_delete_success(self, mock_logger_debug): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_floating_ips', - return_value=self.floatingips_list), \ + side_effect=[self.floatingips_list, None]), \ mock.patch('functest.utils.openstack_clean.os_utils' '.delete_floating_ip', return_value=True): openstack_clean.remove_floatingips(self.client, self.remove_list) @@ -306,12 +315,13 @@ class OSCleanTesting(unittest.TestCase): RegexMatch("Removing floating " "IP \s*\S+ ...")) + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.remove_routers') @mock.patch('functest.utils.openstack_clean.remove_ports') @mock.patch('functest.utils.openstack_clean.logger.debug') def test_remove_networks(self, mock_logger_debug, mock_remove_ports, - mock_remove_routers): + mock_remove_routers, *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_network_list', return_value=self.test_dict_list), \ @@ -331,12 +341,13 @@ class OSCleanTesting(unittest.TestCase): self.routers, self.update_list) + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.remove_routers') @mock.patch('functest.utils.openstack_clean.remove_ports') @mock.patch('functest.utils.openstack_clean.logger.debug') def test_remove_networks_missing_networks(self, mock_logger_debug, mock_remove_ports, - mock_remove_routers): + mock_remove_routers, *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_network_list', return_value=None), \ mock.patch('functest.utils.openstack_clean.os_utils' @@ -354,12 +365,13 @@ class OSCleanTesting(unittest.TestCase): self.routers, self.update_list) + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.remove_routers') @mock.patch('functest.utils.openstack_clean.remove_ports') @mock.patch('functest.utils.openstack_clean.logger.debug') def test_remove_networks_delete_success(self, mock_logger_debug, mock_remove_ports, - mock_remove_routers): + mock_remove_routers, *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_network_list', @@ -385,6 +397,7 @@ class OSCleanTesting(unittest.TestCase): self.routers, self.remove_list) + @mock.patch('time.sleep') @mock.patch('functest.utils.openstack_clean.remove_routers') @mock.patch('functest.utils.openstack_clean.remove_ports') @mock.patch('functest.utils.openstack_clean.logger.error') @@ -392,7 +405,7 @@ class OSCleanTesting(unittest.TestCase): def test_remove_networks_delete_failed(self, mock_logger_debug, mock_logger_error, mock_remove_ports, - mock_remove_routers): + mock_remove_routers, *args): with mock.patch('functest.utils.openstack_clean.os_utils' '.get_network_list', return_value=self.test_dict_list), \ @@ -711,7 +724,7 @@ class OSCleanTesting(unittest.TestCase): as mock_remove_tenants, \ mock.patch('functest.utils.openstack_clean.yaml.safe_load', return_value=mock.Mock()), \ - mock.patch('__builtin__.open', mock.mock_open()) as m: + mock.patch('six.moves.builtins.open', mock.mock_open()) as m: openstack_clean.main() self.assertTrue(mock_remove_instances) self.assertTrue(mock_remove_images) diff --git a/functest/tests/unit/utils/test_openstack_snapshot.py b/functest/tests/unit/utils/test_openstack_snapshot.py index 33e74609..919b28c6 100644 --- a/functest/tests/unit/utils/test_openstack_snapshot.py +++ b/functest/tests/unit/utils/test_openstack_snapshot.py @@ -222,7 +222,7 @@ class OSSnapshotTesting(unittest.TestCase): return_value=self.update_list), \ mock.patch('functest.utils.openstack_snapshot.get_tenants', return_value=self.update_list), \ - mock.patch('__builtin__.open', mock.mock_open()) as m: + mock.patch('six.moves.builtins.open', mock.mock_open()) as m: openstack_snapshot.main() mock_logger_info.assert_called_once_with("Generating OpenStack " "snapshot...") diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py index 307cbe37..01085bb7 100644 --- a/functest/tests/unit/utils/test_openstack_utils.py +++ b/functest/tests/unit/utils/test_openstack_utils.py @@ -365,7 +365,8 @@ class OSUtilsTesting(unittest.TestCase): except: pass f = 'rc_file' - with mock.patch('__builtin__.open', mock.mock_open(read_data=msg), + with mock.patch('six.moves.builtins.open', + mock.mock_open(read_data=msg), create=True) as m: m.return_value.__iter__ = lambda self: iter(self.readline, '') openstack_utils.source_credentials(f) @@ -1460,7 +1461,7 @@ class OSUtilsTesting(unittest.TestCase): return_value=True), \ mock.patch('functest.utils.openstack_utils.get_image_id', return_value=''), \ - mock.patch('__builtin__.open', + mock.patch('six.moves.builtins.open', mock.mock_open(read_data='1')) as m: self.assertEqual(openstack_utils. create_glance_image(self.glance_client, |