diff options
author | Takashi Natsume <takanattie@gmail.com> | 2022-09-11 19:54:08 +0900 |
---|---|---|
committer | Takashi Natsume <takanattie@gmail.com> | 2023-04-07 00:20:10 +0900 |
commit | dfef52f3a6e6ba6fde0e985621673064c8c86356 (patch) | |
tree | 4dbd7d3fce04f405fce9121b2a7382c9c612e5ba | |
parent | 42ef47ba26ab15c526afa7eec7f243bd1c97f770 (diff) | |
download | cinder-dfef52f3a6e6ba6fde0e985621673064c8c86356.tar.gz |
Fix wrong assertion methods
Change-Id: I0e1ce867c76fcf4fb5784550c1f1f051498176a4
Closes-Bug: 1989280
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
8 files changed, 45 insertions, 32 deletions
diff --git a/cinder/tests/unit/attachments/test_attachments_manager.py b/cinder/tests/unit/attachments/test_attachments_manager.py index 6e5def3d3..ab722e1bf 100644 --- a/cinder/tests/unit/attachments/test_attachments_manager.py +++ b/cinder/tests/unit/attachments/test_attachments_manager.py @@ -17,7 +17,6 @@ from oslo_utils import importutils from cinder import context from cinder import db -from cinder.db.sqlalchemy import api as sqla_db from cinder.objects import fields from cinder.objects import volume_attachment from cinder.tests.unit.api.v2 import fakes as v2_fakes @@ -186,13 +185,12 @@ class AttachmentManagerTestCase(test.TestCase): @mock.patch('cinder.objects.VolumeAttachment.get_by_id', side_effect=[attachment1, attachment2]) - @mock.patch.object(sqla_db, 'volume_admin_metadata_delete') - @mock.patch.object(sqla_db, 'volume_detached') @mock.patch.object(self.context, 'elevated') + @mock.patch.object(self.manager, '_notify_about_volume_usage') @mock.patch.object(self.manager, '_connection_terminate') @mock.patch.object(self.manager.driver, 'remove_export') - def _test(mock_rm_export, mock_con_term, mock_elevated, - mock_db_detached, mock_db_meta_delete, mock_get_attachment): + def _test(mock_rm_export, mock_con_term, mock_notify, mock_elevated, + mock_get_attachment): mock_elevated.return_value = self.context mock_con_term.return_value = False @@ -202,8 +200,11 @@ class AttachmentManagerTestCase(test.TestCase): self.manager.attachment_delete(self.context, attachment1.id, vref) - mock_db_detached.assert_not_called() - mock_db_meta_delete.assert_not_called() + mock_elevated.assert_called_once_with() + mock_notify.assert_called_once_with(self.context, vref, + "detach.start") + mock_con_term.assert_called_once_with(self.context, vref, + attachment1) mock_rm_export.assert_called_once_with(self.context, vref) # test more than 1 attachment. This should skip @@ -211,15 +212,20 @@ class AttachmentManagerTestCase(test.TestCase): mock_con_term.return_value = True vref.volume_attachment.objects.append(attachment2) + mock_elevated.reset_mock() + mock_notify.reset_mock() + mock_con_term.reset_mock() mock_rm_export.reset_mock() - mock_db_detached.reset_mock() - mock_db_meta_delete.reset_mock() self.manager.attachment_delete(self.context, attachment2.id, vref) + mock_elevated.assert_not_called() + mock_notify.assert_called_once_with(self.context, vref, + "detach.start") + mock_con_term.assert_called_once_with(self.context, vref, + attachment2) mock_rm_export.assert_not_called() - mock_db_detached.assert_not_called() - mock_db_meta_delete.assert_not_called() + _test() def test_connection_terminate_no_connector_force_false(self): diff --git a/cinder/tests/unit/backup/drivers/test_backup_glusterfs.py b/cinder/tests/unit/backup/drivers/test_backup_glusterfs.py index dca01aa98..d002a4b73 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_glusterfs.py +++ b/cinder/tests/unit/backup/drivers/test_backup_glusterfs.py @@ -83,7 +83,7 @@ class BackupGlusterfsShareTestCase(test.TestCase): path = driver._init_backup_repo_path() self.assertEqual(FAKE_BACKUP_PATH, path) - utils.get_root_helper.called_once() + utils.get_root_helper.assert_called_once_with() mock_remotefsclient.mount.assert_called_once_with(FAKE_BACKUP_SHARE) mock_remotefsclient.get_mount_point.assert_called_once_with( FAKE_BACKUP_SHARE) diff --git a/cinder/tests/unit/backup/test_backup.py b/cinder/tests/unit/backup/test_backup.py index 4e0c7b91d..a85cd905d 100644 --- a/cinder/tests/unit/backup/test_backup.py +++ b/cinder/tests/unit/backup/test_backup.py @@ -916,8 +916,8 @@ class BackupTestCase(BaseBackupTest): mock_open.assert_not_called() backup_service.backup.assert_called_once_with( backup, device_path) - mock_finish.called_once_with(self.ctxt, backup, volume, - mock.sentinel.backup_update) + mock_finish.assert_called_once_with(self.ctxt, backup, volume, + mock.sentinel.backup_update) @mock.patch('cinder.backup.manager.BackupManager._start_backup') @ddt.data((fields.SnapshotStatus.BACKING_UP, 'available'), diff --git a/cinder/tests/unit/test_coordination.py b/cinder/tests/unit/test_coordination.py index e291c84fd..db725c498 100644 --- a/cinder/tests/unit/test_coordination.py +++ b/cinder/tests/unit/test_coordination.py @@ -139,7 +139,7 @@ class CoordinatorTestCase(test.TestCase): mock_glob.assert_called_once_with( '/data/cinder-attachment_update-UUID-*') self.assertEqual(2, mock_remove.call_count) - mock_remove.has_calls( + mock_remove.assert_has_calls( [mock.call('/data/cinder-attachment_update-UUID-1'), mock.call('/data/cinder-attachment_update-UUID-2')]) @@ -157,7 +157,7 @@ class CoordinatorTestCase(test.TestCase): mock_glob.assert_called_once_with( '/data/cinder-attachment_update-UUID-*') self.assertEqual(2, mock_remove.call_count) - mock_remove.has_calls( + mock_remove.assert_has_calls( [mock.call('/data/cinder-attachment_update-UUID-1'), mock.call('/data/cinder-attachment_update-UUID-2')]) mock_log.assert_not_called() @@ -177,7 +177,7 @@ class CoordinatorTestCase(test.TestCase): mock_glob.assert_called_once_with( '/data/cinder-attachment_update-UUID-*') self.assertEqual(2, mock_remove.call_count) - mock_remove.has_calls( + mock_remove.assert_has_calls( [mock.call('/data/cinder-attachment_update-UUID-1'), mock.call('/data/cinder-attachment_update-UUID-2')]) self.assertEqual(1, mock_log.call_count) diff --git a/cinder/tests/unit/volume/drivers/netapp/dataontap/utils/test_data_motion.py b/cinder/tests/unit/volume/drivers/netapp/dataontap/utils/test_data_motion.py index 910005b90..0ba8a2fe9 100644 --- a/cinder/tests/unit/volume/drivers/netapp/dataontap/utils/test_data_motion.py +++ b/cinder/tests/unit/volume/drivers/netapp/dataontap/utils/test_data_motion.py @@ -1128,7 +1128,7 @@ class NetAppCDOTDataMotionMixinTestCase(test.TestCase): utils.get_backend_configuration.assert_called_once_with( dataontap_fakes.DEST_BACKEND_NAME) - utils.get_client_for_backend.has_calls( + utils.get_client_for_backend.assert_has_calls( [mock.call(dataontap_fakes.DEST_BACKEND_NAME), mock.call(dataontap_fakes.BACKEND_NAME)]) self.mock_src_client.get_cluster_name.assert_called() @@ -1190,7 +1190,7 @@ class NetAppCDOTDataMotionMixinTestCase(test.TestCase): utils.get_backend_configuration.assert_called_once_with( dataontap_fakes.DEST_BACKEND_NAME) - utils.get_client_for_backend.has_calls( + utils.get_client_for_backend.assert_has_calls( [mock.call(dataontap_fakes.DEST_BACKEND_NAME), mock.call(dataontap_fakes.BACKEND_NAME)]) self.mock_src_client.get_cluster_name.assert_called() @@ -1240,7 +1240,7 @@ class NetAppCDOTDataMotionMixinTestCase(test.TestCase): else: utils.get_backend_configuration.assert_called_once_with( dest_backend_name) - utils.get_client_for_backend.has_calls( + utils.get_client_for_backend.assert_has_calls( [mock.call(dest_backend_name), mock.call(dataontap_fakes.BACKEND_NAME)]) self.mock_src_client.get_cluster_name.assert_called() @@ -1281,7 +1281,7 @@ class NetAppCDOTDataMotionMixinTestCase(test.TestCase): utils.get_backend_configuration.assert_called_once_with( dataontap_fakes.DEST_BACKEND_NAME) - utils.get_client_for_backend.has_calls( + utils.get_client_for_backend.assert_has_calls( [mock.call(dataontap_fakes.DEST_BACKEND_NAME), mock.call(dataontap_fakes.BACKEND_NAME)]) self.mock_src_client.get_cluster_name.assert_called() diff --git a/cinder/tests/unit/volume/drivers/test_remotefs.py b/cinder/tests/unit/volume/drivers/test_remotefs.py index 812550868..db2971fa2 100644 --- a/cinder/tests/unit/volume/drivers/test_remotefs.py +++ b/cinder/tests/unit/volume/drivers/test_remotefs.py @@ -770,6 +770,7 @@ class RemoteFsSnapDriverTestCase(test.TestCase): src_encryption_key_id=None, new_encryption_key_id=None) mock_delete_snapshot.assert_called_once_with( mock_obj_snap.return_value) + mock_obj_snap.return_value.destroy.assert_called_once_with() else: self.assertFalse(mock_create_snapshot.called) diff --git a/cinder/tests/unit/volume/flows/test_create_volume_flow.py b/cinder/tests/unit/volume/flows/test_create_volume_flow.py index 5b4ddb35f..d2dca5a56 100644 --- a/cinder/tests/unit/volume/flows/test_create_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_create_volume_flow.py @@ -1771,6 +1771,8 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase): image_location = 'someImageLocationStr' image_id = fakes.IMAGE_ID image_meta = mock.MagicMock() + volume_id = str(uuid.uuid4()) + self.mock_cache.get_entry.return_value = {'volume_id': volume_id} volume = fake_volume.fake_volume_obj(self.ctxt, size=1, host='foo@bar#pool') self.mock_driver.clone_image.return_value = (None, False) @@ -1794,6 +1796,7 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase): image_id, image_meta, self.mock_image_service) + mock_handle_bootable.assert_not_called() else: mock_create_from_src.side_effect = NotImplementedError( 'Driver does not support clone') @@ -1807,16 +1810,13 @@ class CreateVolumeFlowManagerImageCacheTestCase(test.TestCase): mock_create_from_img_dl.assert_called_once() self.assertEqual(mock_create_from_img_dl.return_value, model_update) + mock_handle_bootable.assert_called_once_with(self.ctxt, volume, + image_id=image_id, + image_meta=image_meta) # Ensure cloning was attempted and that it failed - mock_create_from_src.assert_called_once() - with mock.patch( - 'cinder.volume.flows.manager.create_volume.' - 'CreateVolumeFromSpecTask') as volume_manager: - (volume_manager.CreateVolumeFromSpecTask. - _create_from_image_cache_or_download.called_once()) - (volume_manager.CreateVolumeFromSpecTask. - _create_from_image_cache.called_once()) + mock_create_from_src.assert_called_once_with(self.ctxt, volume, + volume_id) @mock.patch('cinder.volume.flows.manager.create_volume.' 'CreateVolumeFromSpecTask.' diff --git a/cinder/tests/unit/volume/test_volume.py b/cinder/tests/unit/volume/test_volume.py index fa0f1da04..471b3391c 100644 --- a/cinder/tests/unit/volume/test_volume.py +++ b/cinder/tests/unit/volume/test_volume.py @@ -2910,8 +2910,8 @@ class VolumeTestCase(base.BaseVolumeTestCase): self.volume.detach_volume(self.context, volume.id, attachment.id) self.volume.delete_volume(self.context, volume) - @mock.patch('cinder.volume.rpcapi.VolumeAPI.extend_volume') - def test_extend_volume_with_volume_type(self, mock_rpc_extend): + @mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.extend_volume') + def test_extend_volume_with_volume_type(self, mock_scheduler_extend): elevated = context.get_admin_context() project_id = self.context.project_id db.volume_type_create(elevated, {'name': 'type', 'extra_specs': {}}) @@ -2929,7 +2929,13 @@ class VolumeTestCase(base.BaseVolumeTestCase): db.volume_update(self.context, volume.id, {'status': 'available'}) volume_api._extend(self.context, volume, 200) - mock_rpc_extend.called_once_with(self.context, volume, 200, mock.ANY) + mock_scheduler_extend.assert_called_once_with( + self.context, volume, 200, mock.ANY, + { + 'volume_properties': volume, + 'volume_type': vol_type, + 'volume_id': volume.id + }) try: usage = db.quota_usage_get(elevated, project_id, 'gigabytes_type') |