From: Eric Harney Date: Tue, 6 Oct 2015 18:14:00 +0000 (-0400) Subject: test_backup_swift: Set volume id per test X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=284eb741995e76ff18e4a1ef8a1a3ce99a9afcfd;p=openstack-build%2Fcinder-build.git test_backup_swift: Set volume id per test Since some of these tests trigger operations (such as progress reporting) that can happen as an asyncronous task, set a different ID for each test so it's possible to identify where notifications are coming from. Related-Bug: #1501745 Change-Id: I255941ecb813e47ac02c9b8ca09e41d99d12d218 --- diff --git a/cinder/tests/unit/test_backup_swift.py b/cinder/tests/unit/test_backup_swift.py index c5d639923..69a65c695 100644 --- a/cinder/tests/unit/test_backup_swift.py +++ b/cinder/tests/unit/test_backup_swift.py @@ -55,19 +55,29 @@ def fake_md5(arg): class BackupSwiftTestCase(test.TestCase): """Test Case for swift.""" - def _create_volume_db_entry(self): - vol = {'id': '1234-5678-1234-8888', + _DEFAULT_VOLUME_ID = 'c7eb81f4-bec6-4730-a60f-8888885874df' + + def _create_volume_db_entry(self, volume_id=_DEFAULT_VOLUME_ID): + vol = {'id': volume_id, 'size': 1, 'status': 'available'} return db.volume_create(self.ctxt, vol)['id'] - def _create_backup_db_entry(self, container='test-container', + def _create_backup_db_entry(self, + volume_id=_DEFAULT_VOLUME_ID, + container='test-container', backup_id=123, parent_id=None, service_metadata=None): + + try: + db.volume_get(self.ctxt, volume_id) + except exception.NotFound: + self._create_volume_db_entry(volume_id=volume_id) + backup = {'id': backup_id, 'size': 1, 'container': container, - 'volume_id': '1234-5678-1234-8888', + 'volume_id': volume_id, 'parent_id': parent_id, 'user_id': 'user-id', 'project_id': 'project-id', @@ -87,7 +97,6 @@ class BackupSwiftTestCase(test.TestCase): fake_swift_client.FakeSwiftClient.Connection) self.stubs.Set(hashlib, 'md5', fake_md5) - self._create_volume_db_entry() self.volume_file = tempfile.NamedTemporaryFile() self.temp_dir = tempfile.mkdtemp() self.addCleanup(self.volume_file.close) @@ -126,7 +135,8 @@ class BackupSwiftTestCase(test.TestCase): self.ctxt) def test_backup_uncompressed(self): - self._create_backup_db_entry() + volume_id = '2b9f10a3-42b4-4fdf-b316-000000ceb039' + self._create_backup_db_entry(volume_id=volume_id) self.flags(backup_compression_algorithm='none') service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) @@ -134,7 +144,8 @@ class BackupSwiftTestCase(test.TestCase): service.backup(backup, self.volume_file) def test_backup_bz2(self): - self._create_backup_db_entry() + volume_id = 'dc0fee35-b44e-4f13-80d6-000000e1b50c' + self._create_backup_db_entry(volume_id=volume_id) self.flags(backup_compression_algorithm='bz2') service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) @@ -142,7 +153,8 @@ class BackupSwiftTestCase(test.TestCase): service.backup(backup, self.volume_file) def test_backup_zlib(self): - self._create_backup_db_entry() + volume_id = '5cea0535-b6fb-4531-9a38-000000bea094' + self._create_backup_db_entry(volume_id=volume_id) self.flags(backup_compression_algorithm='zlib') service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) @@ -150,7 +162,9 @@ class BackupSwiftTestCase(test.TestCase): service.backup(backup, self.volume_file) def test_backup_default_container(self): - self._create_backup_db_entry(container=None) + volume_id = '9552017f-c8b9-4e4e-a876-00000053349c' + self._create_backup_db_entry(volume_id=volume_id, + container=None) service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) backup = objects.Backup.get_by_id(self.ctxt, 123) @@ -164,7 +178,9 @@ class BackupSwiftTestCase(test.TestCase): '_send_progress_notification') def test_backup_default_container_notify(self, _send_progress, _send_progress_end): - self._create_backup_db_entry(container=None) + volume_id = '87dd0eed-2598-4ebd-8ebb-000000ac578a' + self._create_backup_db_entry(volume_id=volume_id, + container=None) # If the backup_object_number_per_notification is set to 1, # the _send_progress method will be called for sure. CONF.set_override("backup_object_number_per_notification", 1) @@ -202,8 +218,10 @@ class BackupSwiftTestCase(test.TestCase): self.assertTrue(_send_progress_end.called) def test_backup_custom_container(self): + volume_id = '1da9859e-77e5-4731-bd58-000000ca119e' container_name = 'fake99' - self._create_backup_db_entry(container=container_name) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name) service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) backup = objects.Backup.get_by_id(self.ctxt, 123) @@ -212,6 +230,7 @@ class BackupSwiftTestCase(test.TestCase): self.assertEqual(container_name, backup['container']) def test_backup_shafile(self): + volume_id = '6465dad4-22af-48f7-8a1a-000000218907' def _fake_generate_object_name_prefix(self, backup): az = 'az_fake' @@ -227,7 +246,8 @@ class BackupSwiftTestCase(test.TestCase): container_name = self.temp_dir.replace(tempfile.gettempdir() + '/', '', 1) - self._create_backup_db_entry(container=container_name) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) service = swift_dr.SwiftBackupDriver(self.ctxt) @@ -243,6 +263,7 @@ class BackupSwiftTestCase(test.TestCase): len(content1['sha256s'])) def test_backup_cmp_shafiles(self): + volume_id = '1a99ac67-c534-4fe3-b472-0000001785e2' def _fake_generate_object_name_prefix(self, backup): az = 'az_fake' @@ -258,7 +279,9 @@ class BackupSwiftTestCase(test.TestCase): container_name = self.temp_dir.replace(tempfile.gettempdir() + '/', '', 1) - self._create_backup_db_entry(container=container_name, backup_id=123) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=123) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) service = swift_dr.SwiftBackupDriver(self.ctxt) @@ -269,7 +292,9 @@ class BackupSwiftTestCase(test.TestCase): self.assertEqual(container_name, backup['container']) # Create incremental backup with no change to contents - self._create_backup_db_entry(container=container_name, backup_id=124, + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=124, parent_id=123) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) @@ -288,6 +313,7 @@ class BackupSwiftTestCase(test.TestCase): self.assertEqual(set(content1['sha256s']), set(content2['sha256s'])) def test_backup_delta_two_objects_change(self): + volume_id = '30dab288-265a-4583-9abe-000000d42c67' def _fake_generate_object_name_prefix(self, backup): az = 'az_fake' @@ -306,7 +332,9 @@ class BackupSwiftTestCase(test.TestCase): container_name = self.temp_dir.replace(tempfile.gettempdir() + '/', '', 1) - self._create_backup_db_entry(container=container_name, backup_id=123) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=123) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) service = swift_dr.SwiftBackupDriver(self.ctxt) @@ -322,7 +350,9 @@ class BackupSwiftTestCase(test.TestCase): self.volume_file.seek(4 * 8 * 1024) self.volume_file.write(os.urandom(1024)) - self._create_backup_db_entry(container=container_name, backup_id=124, + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=124, parent_id=123) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) @@ -341,6 +371,7 @@ class BackupSwiftTestCase(test.TestCase): self.assertNotEqual(content1['sha256s'][32], content2['sha256s'][32]) def test_backup_delta_two_blocks_in_object_change(self): + volume_id = 'b943e84f-aa67-4331-9ab2-000000cf19ba' def _fake_generate_object_name_prefix(self, backup): az = 'az_fake' @@ -359,7 +390,9 @@ class BackupSwiftTestCase(test.TestCase): container_name = self.temp_dir.replace(tempfile.gettempdir() + '/', '', 1) - self._create_backup_db_entry(container=container_name, backup_id=123) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=123) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) service = swift_dr.SwiftBackupDriver(self.ctxt) @@ -375,7 +408,9 @@ class BackupSwiftTestCase(test.TestCase): self.volume_file.seek(20 * 1024) self.volume_file.write(os.urandom(1024)) - self._create_backup_db_entry(container=container_name, backup_id=124, + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=124, parent_id=123) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) @@ -393,8 +428,10 @@ class BackupSwiftTestCase(test.TestCase): self.assertNotEqual(content1['sha256s'][20], content2['sha256s'][20]) def test_create_backup_put_object_wraps_socket_error(self): + volume_id = 'b09b1ad4-5f0e-4d3f-8b9e-0000004f5ec2' container_name = 'socket_error_on_put' - self._create_backup_db_entry(container=container_name) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name) service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) backup = objects.Backup.get_by_id(self.ctxt, 123) @@ -409,7 +446,9 @@ class BackupSwiftTestCase(test.TestCase): self._backup_metadata(), we want to check the process of an exception handler. """ - self._create_backup_db_entry() + volume_id = '020d9142-339c-4876-a445-000000f1520c' + + self._create_backup_db_entry(volume_id=volume_id) self.flags(backup_compression_algorithm='none') service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) @@ -434,7 +473,9 @@ class BackupSwiftTestCase(test.TestCase): self._backup_metadata(), we want to check the process when the second exception occurs in self.delete(). """ - self._create_backup_db_entry() + volume_id = '2164421d-f181-4db7-b9bd-000000eeb628' + + self._create_backup_db_entry(volume_id=volume_id) self.flags(backup_compression_algorithm='none') service = swift_dr.SwiftBackupDriver(self.ctxt) self.volume_file.seek(0) @@ -459,14 +500,16 @@ class BackupSwiftTestCase(test.TestCase): backup, self.volume_file) def test_restore(self): - self._create_backup_db_entry() + volume_id = 'c2a81f09-f480-4325-8424-00000071685b' + self._create_backup_db_entry(volume_id=volume_id) service = swift_dr.SwiftBackupDriver(self.ctxt) with tempfile.NamedTemporaryFile() as volume_file: backup = objects.Backup.get_by_id(self.ctxt, 123) - service.restore(backup, '1234-5678-1234-8888', volume_file) + service.restore(backup, volume_id, volume_file) def test_restore_delta(self): + volume_id = '04d83506-bcf7-4ff5-9c65-00000051bd2e' def _fake_generate_object_name_prefix(self, backup): az = 'az_fake' @@ -485,7 +528,9 @@ class BackupSwiftTestCase(test.TestCase): container_name = self.temp_dir.replace(tempfile.gettempdir() + '/', '', 1) - self._create_backup_db_entry(container=container_name, backup_id=123) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=123) self.stubs.Set(swift, 'Connection', fake_swift_client2.FakeSwiftClient2.Connection) service = swift_dr.SwiftBackupDriver(self.ctxt) @@ -499,7 +544,9 @@ class BackupSwiftTestCase(test.TestCase): self.volume_file.seek(20 * 1024) self.volume_file.write(os.urandom(1024)) - self._create_backup_db_entry(container=container_name, backup_id=124, + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, + backup_id=124, parent_id=123) self.volume_file.seek(0) deltabackup = objects.Backup.get_by_id(self.ctxt, 124) @@ -508,44 +555,52 @@ class BackupSwiftTestCase(test.TestCase): with tempfile.NamedTemporaryFile() as restored_file: backup = objects.Backup.get_by_id(self.ctxt, 124) - service.restore(backup, '1234-5678-1234-8888', + service.restore(backup, volume_id, restored_file) self.assertTrue(filecmp.cmp(self.volume_file.name, restored_file.name)) def test_restore_wraps_socket_error(self): + volume_id = 'c1160de7-2774-4f20-bf14-0000001ac139' container_name = 'socket_error_on_get' - self._create_backup_db_entry(container=container_name) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name) service = swift_dr.SwiftBackupDriver(self.ctxt) with tempfile.NamedTemporaryFile() as volume_file: backup = objects.Backup.get_by_id(self.ctxt, 123) self.assertRaises(exception.SwiftConnectionFailed, service.restore, - backup, '1234-5678-1234-8888', volume_file) + backup, volume_id, volume_file) def test_restore_unsupported_version(self): + volume_id = '390db8c1-32d3-42ca-82c9-00000010c703' container_name = 'unsupported_version' - self._create_backup_db_entry(container=container_name) + self._create_backup_db_entry(volume_id=volume_id, + container=container_name) service = swift_dr.SwiftBackupDriver(self.ctxt) with tempfile.NamedTemporaryFile() as volume_file: backup = objects.Backup.get_by_id(self.ctxt, 123) self.assertRaises(exception.InvalidBackup, service.restore, - backup, '1234-5678-1234-8888', volume_file) + backup, volume_id, volume_file) def test_delete(self): + volume_id = '9ab256c8-3175-4ad8-baa1-0000007f9d31' object_prefix = 'test_prefix' - self._create_backup_db_entry(service_metadata=object_prefix) + self._create_backup_db_entry(volume_id=volume_id, + service_metadata=object_prefix) service = swift_dr.SwiftBackupDriver(self.ctxt) backup = objects.Backup.get_by_id(self.ctxt, 123) service.delete(backup) def test_delete_wraps_socket_error(self): + volume_id = 'f74cb6fa-2900-40df-87ac-0000000f72ea' container_name = 'socket_error_on_delete' object_prefix = 'test_prefix' - self._create_backup_db_entry(container=container_name, + self._create_backup_db_entry(volume_id=volume_id, + container=container_name, service_metadata=object_prefix) service = swift_dr.SwiftBackupDriver(self.ctxt) backup = objects.Backup.get_by_id(self.ctxt, 123) @@ -554,6 +609,7 @@ class BackupSwiftTestCase(test.TestCase): backup) def test_delete_without_object_prefix(self): + volume_id = 'ee30d649-72a6-49a5-b78d-000000edb6b1' def _fake_delete_object(self, container, object_name): raise AssertionError('delete_object method should not be called.') @@ -562,7 +618,7 @@ class BackupSwiftTestCase(test.TestCase): 'delete_object', _fake_delete_object) - self._create_backup_db_entry() + self._create_backup_db_entry(volume_id=volume_id) service = swift_dr.SwiftBackupDriver(self.ctxt) backup = objects.Backup.get_by_id(self.ctxt, 123) service.delete(backup)