diff --git a/cinder/tests/unit/test_backup.py b/cinder/tests/unit/test_backup.py index ca93747cd45..ea42c4db186 100644 --- a/cinder/tests/unit/test_backup.py +++ b/cinder/tests/unit/test_backup.py @@ -547,26 +547,6 @@ class BackupTestCase(BaseBackupTest): self.assertEqual(fields.BackupStatus.ERROR, backup['status']) self.assertTrue(mock_run_backup.called) - @mock.patch('cinder.utils.brick_get_connector_properties') - @mock.patch('cinder.utils.temporary_chown') - @mock.patch('six.moves.builtins.open') - def test_create_backup_old_volume_service(self, mock_open, - mock_temporary_chown, - mock_get_backup_device): - """Test error handling when there's too old volume service in env.""" - vol_id = self._create_volume_db_entry(size=1) - backup = self._create_backup_db_entry(volume_id=vol_id) - - with mock.patch.object(self.backup_mgr.volume_rpcapi.client, - 'version_cap', '1.37'): - self.assertRaises(exception.ServiceTooOld, - self.backup_mgr.create_backup, self.ctxt, backup) - vol = db.volume_get(self.ctxt, vol_id) - self.assertEqual('available', vol['status']) - self.assertEqual('error_backing-up', vol['previous_status']) - backup = db.backup_get(self.ctxt, backup.id) - self.assertEqual(fields.BackupStatus.ERROR, backup['status']) - @mock.patch('cinder.utils.brick_get_connector_properties') @mock.patch('cinder.volume.rpcapi.VolumeAPI.get_backup_device') @mock.patch('cinder.utils.temporary_chown') @@ -678,31 +658,6 @@ class BackupTestCase(BaseBackupTest): self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status']) self.assertTrue(mock_run_restore.called) - @mock.patch('cinder.utils.brick_get_connector_properties') - def test_restore_backup_with_old_volume_service(self, mock_get_conn): - """Test error handling when an error occurs during backup restore.""" - vol_id = self._create_volume_db_entry(status='restoring-backup', - size=1) - backup = self._create_backup_db_entry( - status=fields.BackupStatus.RESTORING, volume_id=vol_id) - - # Unmock secure_file_operations_enabled - self.volume_patches['secure_file_operations_enabled'].stop() - - with mock.patch.object(self.backup_mgr.volume_rpcapi.client, - 'version_cap', '1.37'): - self.assertRaises(exception.ServiceTooOld, - self.backup_mgr.restore_backup, - self.ctxt, - backup, - vol_id) - vol = db.volume_get(self.ctxt, vol_id) - self.assertEqual('error_restoring', vol['status']) - backup = db.backup_get(self.ctxt, backup.id) - self.assertEqual(fields.BackupStatus.AVAILABLE, backup['status']) - - self.volume_patches['secure_file_operations_enabled'].start() - def test_restore_backup_with_bad_service(self): """Test error handling. diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index b981aa94d8f..248a57aa017 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -364,9 +364,9 @@ class VolumeTestCase(BaseVolumeTestCase): size=0, host=CONF.host) volume_id = volume['id'] self.volume.init_host() - volume = db.volume_get(context.get_admin_context(), volume_id) - self.assertEqual("error", volume['status']) - self.volume.delete_volume(self.context, volume_id) + volume.refresh() + self.assertEqual("error", volume.status) + self.volume.delete_volume(self.context, volume_id, volume=volume) def test_init_host_clears_uploads_available_volume(self): """init_host will clean an available volume stuck in uploading.""" @@ -430,14 +430,13 @@ class VolumeTestCase(BaseVolumeTestCase): # get_pool method, which in the legacy case is going # to be volume_backend_name or None - vol0 = db.volume_get(context.get_admin_context(), vol0['id']) - self.assertEqual(volutils.append_host(CONF.host, 'LVM'), - vol0['host']) - self.volume.delete_volume(self.context, vol0['id']) - self.volume.delete_volume(self.context, vol1['id']) - self.volume.delete_volume(self.context, vol2['id']) - self.volume.delete_volume(self.context, vol3['id']) - self.volume.delete_volume(self.context, vol4['id']) + vol0.refresh() + self.assertEqual(volutils.append_host(CONF.host, 'LVM'), vol0.host) + self.volume.delete_volume(self.context, vol0.id, volume=vol0) + self.volume.delete_volume(self.context, vol1.id, volume=vol1) + self.volume.delete_volume(self.context, vol2.id, volume=vol2) + self.volume.delete_volume(self.context, vol3.id, volume=vol3) + self.volume.delete_volume(self.context, vol4.id, volume=vol4) @mock.patch.object(driver.BaseVD, "update_provider_info") def test_init_host_sync_provider_info(self, mock_update): @@ -566,9 +565,9 @@ class VolumeTestCase(BaseVolumeTestCase): volume_id = volume['id'] self.volume.init_host() - volume = db.volume_get(context.get_admin_context(), volume_id) - self.assertEqual('error', volume['status']) - self.volume.delete_volume(self.context, volume_id) + volume.refresh() + self.assertEqual('error', volume.status) + self.volume.delete_volume(self.context, volume_id, volume=volume) def test_create_snapshot_fails_with_creating_status(self): """Test init_host in case of snapshot. @@ -590,7 +589,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual('error', snapshot_obj.status) self.volume.delete_snapshot(self.context, snapshot_obj) - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) @mock.patch.object(QUOTAS, 'reserve') @mock.patch.object(QUOTAS, 'commit') @@ -619,7 +618,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.notifier.notifications) self.assertRaises(exception.DriverNotInitialized, self.volume.create_volume, - self.context, volume_id) + self.context, volume_id, volume=volume) volume = db.volume_get(context.get_admin_context(), volume_id) self.assertEqual("error", volume.status) @@ -638,7 +637,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.volume.create_volume, self.context, volume_id, {'volume_properties': self.volume_params}, - {'retry': {'num_attempts': 1, 'host': []}}) + {'retry': {'num_attempts': 1, 'host': []}}, + volume=volume) # NOTE(dulek): Volume should be rescheduled as we passed request_spec # and filter_properties, assert that it wasn't counted in # allocated_capacity tracking. @@ -661,7 +661,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.volume.create_volume, self.context, volume_id, {'volume_properties': params}, - {'retry': {'num_attempts': 1, 'host': []}}) + {'retry': {'num_attempts': 1, 'host': []}}, + volume=volume) # NOTE(dulek): Volume should be rescheduled as we passed request_spec # and filter_properties, assert that it wasn't counted in # allocated_capacity tracking. @@ -695,7 +696,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.notifier.notifications) self.assertRaises(exception.DriverNotInitialized, self.volume.delete_volume, - self.context, volume.id) + self.context, volume.id, volume=volume) volume = objects.Volume.get_by_id(self.context, volume.id) self.assertEqual("error_deleting", volume.status) @@ -714,7 +715,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertIsNone(volume['encryption_key_id']) self.assertEqual(0, len(self.notifier.notifications), self.notifier.notifications) - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) self.assertEqual(2, len(self.notifier.notifications), self.notifier.notifications) msg = self.notifier.notifications[0] @@ -746,7 +747,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual(volume_id, db.volume_get(context.get_admin_context(), volume_id).id) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) vol = db.volume_get(context.get_admin_context(read_deleted='yes'), volume_id) self.assertEqual('deleted', vol['status']) @@ -769,10 +770,10 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, metadata=test_meta, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) self.assertEqual(test_meta, volume.metadata) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.NotFound, db.volume_get, self.context, @@ -875,7 +876,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, metadata=test_meta1, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) volume_api = cinder.volume.api.API() @@ -1163,14 +1164,14 @@ class VolumeTestCase(BaseVolumeTestCase): """Test volume survives deletion if driver reports it as busy.""" volume = tests_utils.create_volume(self.context, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) self.mox.StubOutWithMock(self.volume.driver, 'delete_volume') self.volume.driver.delete_volume( mox.IgnoreArg()).AndRaise(exception.VolumeIsBusy( volume_name='fake')) self.mox.ReplayAll() - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) volume_ref = db.volume_get(context.get_admin_context(), volume_id) self.assertEqual(volume_id, volume_ref.id) self.assertEqual("available", volume_ref.status) @@ -1180,7 +1181,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) another_context = context.RequestContext('another_user_id', 'another_project_id', @@ -1195,7 +1196,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual(volume_id, volume_api.get(self.context, volume_id)['id']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) def test_get_all_limit_bad_value(self): """Test value of 'limit' is numeric and >= 0""" @@ -1244,12 +1245,12 @@ class VolumeTestCase(BaseVolumeTestCase): """Test volume can be deleted in error_extending stats.""" # create a volume volume = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) # delete 'error_extending' volume db.volume_update(self.context, volume['id'], {'status': 'error_extending'}) - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) self.assertRaises(exception.NotFound, db.volume_get, self.context, volume['id']) @@ -1259,7 +1260,8 @@ class VolumeTestCase(BaseVolumeTestCase): def test_delete_volume_not_found(self, mock_get_volume): """Test delete volume moves on if the volume does not exist.""" volume_id = '12345678-1234-5678-1234-567812345678' - self.volume.delete_volume(self.context, volume_id) + volume = objects.Volume(self.context, id=volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertTrue(mock_get_volume.called) @mock.patch('cinder.volume.drivers.lvm.LVMVolumeDriver.' @@ -1268,7 +1270,8 @@ class VolumeTestCase(BaseVolumeTestCase): """Test volume can be created from a snapshot.""" volume_src = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) snapshot_id = create_snapshot(volume_src['id'], size=volume_src['size'])['id'] snapshot_obj = objects.Snapshot.get_by_id(self.context, snapshot_id) @@ -1277,7 +1280,8 @@ class VolumeTestCase(BaseVolumeTestCase): volume_dst = tests_utils.create_volume(self.context, snapshot_id=snapshot_id, **self.volume_params) - self.volume.create_volume(self.context, volume_dst['id']) + self.volume.create_volume(self.context, volume_dst.id, + volume=volume_dst) self.assertEqual(volume_dst['id'], db.volume_get( context.get_admin_context(), @@ -1286,9 +1290,11 @@ class VolumeTestCase(BaseVolumeTestCase): db.volume_get(context.get_admin_context(), volume_dst['id']).snapshot_id) - self.volume.delete_volume(self.context, volume_dst['id']) + self.volume.delete_volume(self.context, volume_dst.id, + volume=volume_dst) self.volume.delete_snapshot(self.context, snapshot_obj) - self.volume.delete_volume(self.context, volume_src['id']) + self.volume.delete_volume(self.context, volume_src.id, + volume=volume_src) @mock.patch('cinder.volume.flows.api.create_volume.get_flow') def test_create_volume_from_snapshot_with_types(self, _get_flow): @@ -1522,7 +1528,8 @@ class VolumeTestCase(BaseVolumeTestCase): def test_create_snapshot_driver_not_initialized(self): volume_src = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) snapshot_id = create_snapshot(volume_src['id'], size=volume_src['size'])['id'] snapshot_obj = objects.Snapshot.get_by_id(self.context, snapshot_id) @@ -1539,7 +1546,8 @@ class VolumeTestCase(BaseVolumeTestCase): # lets cleanup the mess self.volume.driver._initialized = True self.volume.delete_snapshot(self.context, snapshot_obj) - self.volume.delete_volume(self.context, volume_src['id']) + self.volume.delete_volume(self.context, volume_src.id, + volume=volume_src) def _mock_synchronized(self, name, *s_args, **s_kwargs): def inner_sync1(f): @@ -1574,7 +1582,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol_id = src_vol['id'] # no lock - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) snap_id = create_snapshot(src_vol_id, size=src_vol['size'])['id'] @@ -1593,14 +1601,15 @@ class VolumeTestCase(BaseVolumeTestCase): # locked self.volume.create_volume(self.context, volume_id=dst_vol_id, - request_spec={'snapshot_id': snap_id}) + request_spec={'snapshot_id': snap_id}, + volume=dst_vol) self.assertEqual(2, len(self.called)) self.assertEqual(dst_vol_id, db.volume_get(admin_ctxt, dst_vol_id).id) self.assertEqual(snap_id, db.volume_get(admin_ctxt, dst_vol_id).snapshot_id) # locked - self.volume.delete_volume(self.context, dst_vol_id) + self.volume.delete_volume(self.context, dst_vol_id, volume=dst_vol) self.assertEqual(4, len(self.called)) # locked @@ -1608,7 +1617,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual(6, len(self.called)) # locked - self.volume.delete_volume(self.context, src_vol_id) + self.volume.delete_volume(self.context, src_vol_id, volume=src_vol) self.assertEqual(8, len(self.called)) self.assertEqual(['lock-%s' % ('%s-delete_snapshot' % (snap_id)), @@ -1642,7 +1651,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol_id = src_vol['id'] # no lock - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) dst_vol = tests_utils.create_volume(self.context, source_volid=src_vol_id, @@ -1655,18 +1664,19 @@ class VolumeTestCase(BaseVolumeTestCase): # locked self.volume.create_volume(self.context, volume_id=dst_vol_id, - request_spec={'source_volid': src_vol_id}) + request_spec={'source_volid': src_vol_id}, + volume=dst_vol) self.assertEqual(2, len(self.called)) self.assertEqual(dst_vol_id, db.volume_get(admin_ctxt, dst_vol_id).id) self.assertEqual(src_vol_id, db.volume_get(admin_ctxt, dst_vol_id).source_volid) # locked - self.volume.delete_volume(self.context, dst_vol_id) + self.volume.delete_volume(self.context, dst_vol_id, volume=dst_vol) self.assertEqual(4, len(self.called)) # locked - self.volume.delete_volume(self.context, src_vol_id) + self.volume.delete_volume(self.context, src_vol_id, volume=src_vol) self.assertEqual(6, len(self.called)) self.assertEqual(['lock-%s' % ('%s-delete_volume' % (src_vol_id)), @@ -1683,7 +1693,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol_id = src_vol['id'] # no lock - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) dst_vol = tests_utils.create_volume(self.context, source_volid=src_vol_id, @@ -1701,7 +1711,8 @@ class VolumeTestCase(BaseVolumeTestCase): t = eventlet.spawn(self.volume.create_volume, self.context, volume_id=dst_vol.id, - request_spec={'source_volid': src_vol_id}) + request_spec={'source_volid': src_vol_id}, + volume=dst_vol) gthreads.append(t) return orig_elevated(*args, **kwargs) @@ -1711,7 +1722,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.stubs.Set(self.context, 'elevated', mock_elevated) # locked - self.volume.delete_volume(self.context, src_vol_id) + self.volume.delete_volume(self.context, src_vol_id, volume=src_vol) # we expect the volume create to fail with the following err since the # source volume was deleted while the create was locked. Note that the @@ -1747,7 +1758,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol = tests_utils.create_volume(self.context, **self.volume_params) src_vol_id = src_vol['id'] - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) # set bootable flag of volume to True db.volume_update(self.context, src_vol['id'], {'bootable': True}) @@ -1755,8 +1766,7 @@ class VolumeTestCase(BaseVolumeTestCase): dst_vol = tests_utils.create_volume(self.context, source_volid=src_vol_id, **self.volume_params) - self.volume.create_volume(self.context, - dst_vol['id']) + self.volume.create_volume(self.context, dst_vol.id, volume=dst_vol) self.assertRaises(exception.GlanceMetadataNotFound, db.volume_glance_metadata_copy_from_volume_to_volume, @@ -1778,7 +1788,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol = tests_utils.create_volume(self.context, **self.volume_params) src_vol_id = src_vol['id'] - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) # set bootable flag of volume to True db.volume_update(self.context, src_vol['id'], {'bootable': True}) @@ -1788,7 +1798,7 @@ class VolumeTestCase(BaseVolumeTestCase): **self.volume_params) self._raise_metadata_copy_failure( 'volume_glance_metadata_copy_from_volume_to_volume', - dst_vol['id']) + dst_vol.id, volume=dst_vol) # cleanup resource db.volume_destroy(self.context, src_vol_id) @@ -1801,7 +1811,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol = tests_utils.create_volume(self.context, **self.volume_params) src_vol_id = src_vol['id'] - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) # set bootable flag of volume to True db.volume_update(self.context, src_vol['id'], {'bootable': True}) @@ -1818,7 +1828,7 @@ class VolumeTestCase(BaseVolumeTestCase): **self.volume_params) self._raise_metadata_copy_failure( 'volume_glance_metadata_copy_to_volume', - dst_vol['id']) + dst_vol.id, volume=dst_vol) # cleanup resource snapshot_obj.destroy() @@ -1835,7 +1845,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol = tests_utils.create_volume(self.context, **self.volume_params) src_vol_id = src_vol['id'] - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) # set bootable flag of volume to True db.volume_update(self.context, src_vol['id'], {'bootable': True}) @@ -1845,7 +1855,7 @@ class VolumeTestCase(BaseVolumeTestCase): **self.volume_params) self._raise_metadata_copy_failure( 'volume_glance_metadata_copy_from_volume_to_volume', - dst_vol['id']) + dst_vol.id, volume=dst_vol) # cleanup resource db.volume_destroy(self.context, src_vol_id) @@ -1858,7 +1868,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol = tests_utils.create_volume(self.context, **self.volume_params) src_vol_id = src_vol['id'] - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) # set bootable flag of volume to True db.volume_update(self.context, src_vol['id'], {'bootable': True}) @@ -1900,15 +1910,17 @@ class VolumeTestCase(BaseVolumeTestCase): volume_src = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) db.volume_update(self.context, volume_src['id'], {'bootable': True}) volume = db.volume_get(self.context, volume_src['id']) volume_dst = tests_utils.create_volume( self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_dst['id'], - {'source_replicaid': volume['id']}) + self.volume.create_volume(self.context, volume_dst.id, + {'source_replicaid': volume.id}, + volume=volume_dst) self.assertRaises(exception.GlanceMetadataNotFound, db.volume_glance_metadata_copy_from_volume_to_volume, @@ -1929,7 +1941,7 @@ class VolumeTestCase(BaseVolumeTestCase): src_vol_id = src_vol['id'] # no lock - self.volume.create_volume(self.context, src_vol_id) + self.volume.create_volume(self.context, src_vol_id, volume=src_vol) # create snapshot snap_id = create_snapshot(src_vol_id, @@ -1956,7 +1968,8 @@ class VolumeTestCase(BaseVolumeTestCase): # We expect this to block and then fail t = eventlet.spawn(self.volume.create_volume, self.context, volume_id=dst_vol_id, - request_spec={'snapshot_id': snap_id}) + request_spec={'snapshot_id': snap_id}, + volume=dst_vol) gthreads.append(t) return orig_elevated(*args, **kwargs) @@ -1975,7 +1988,7 @@ class VolumeTestCase(BaseVolumeTestCase): with mock.patch('sys.stderr', new=six.StringIO()): self.assertRaises(exception.SnapshotNotFound, gthreads[0].wait) # locked - self.volume.delete_volume(self.context, src_vol_id) + self.volume.delete_volume(self.context, src_vol_id, volume=src_vol) # make sure it is gone self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, src_vol_id) @@ -2124,7 +2137,8 @@ class VolumeTestCase(BaseVolumeTestCase): volume_src = tests_utils.create_volume(self.context, availability_zone='az2', **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) snapshot = create_snapshot(volume_src['id']) self.volume.create_snapshot(self.context, volume_src['id'], @@ -2256,7 +2270,7 @@ class VolumeTestCase(BaseVolumeTestCase): admin_metadata={'readonly': 'True'}, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, instance_uuid, None, mountpoint, 'ro') @@ -2282,12 +2296,13 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.volume.detach_volume(self.context, volume_id, attachment['id']) vol = db.volume_get(self.context, volume_id) self.assertEqual('available', vol['status']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2337,7 +2352,7 @@ class VolumeTestCase(BaseVolumeTestCase): multiattach=True, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, instance_uuid, None, mountpoint, 'ro') @@ -2365,7 +2380,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.assertRaises(exception.InvalidVolume, self.volume.detach_volume, @@ -2388,7 +2404,7 @@ class VolumeTestCase(BaseVolumeTestCase): vol = db.volume_get(self.context, volume_id) self.assertEqual('available', vol['status']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2404,7 +2420,7 @@ class VolumeTestCase(BaseVolumeTestCase): multiattach=True, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, instance_uuid, None, mountpoint, 'ro') @@ -2444,7 +2460,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.volume.detach_volume(self.context, volume_id, attachment['id']) vol = db.volume_get(self.context, volume_id) self.assertEqual('in-use', vol['status']) @@ -2452,13 +2469,14 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.volume.detach_volume(self.context, volume_id, attachment2['id']) vol = db.volume_get(self.context, volume_id) self.assertEqual('available', vol['status']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2474,7 +2492,7 @@ class VolumeTestCase(BaseVolumeTestCase): multiattach=True, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, instance_uuid, None, mountpoint, 'ro') @@ -2509,7 +2527,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) def test_attach_detach_not_multiattach_volume_for_instances(self): """Make sure volume can't be attached to more than one instance.""" @@ -2521,7 +2540,7 @@ class VolumeTestCase(BaseVolumeTestCase): multiattach=False, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, instance_uuid, None, mountpoint, 'ro') @@ -2557,12 +2576,13 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.volume.detach_volume(self.context, volume_id, attachment['id']) vol = db.volume_get(self.context, volume_id) self.assertEqual('available', vol['status']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2576,7 +2596,7 @@ class VolumeTestCase(BaseVolumeTestCase): admin_metadata={'readonly': 'False'}, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, None, 'fake_host', mountpoint, 'rw') vol = db.volume_get(context.get_admin_context(), volume_id) @@ -2602,12 +2622,13 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.volume.detach_volume(self.context, volume_id, attachment['id']) vol = db.volume_get(self.context, volume_id) self.assertEqual("available", vol['status']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2622,7 +2643,7 @@ class VolumeTestCase(BaseVolumeTestCase): multiattach=True, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, None, 'fake_host', mountpoint, 'rw') vol = db.volume_get(context.get_admin_context(), volume_id) @@ -2660,7 +2681,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.volume.detach_volume(self.context, volume_id, attachment['id']) vol = db.volume_get(self.context, volume_id) self.assertEqual("in-use", vol['status']) @@ -2669,7 +2691,7 @@ class VolumeTestCase(BaseVolumeTestCase): vol = db.volume_get(self.context, volume_id) self.assertEqual("available", vol['status']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2684,7 +2706,7 @@ class VolumeTestCase(BaseVolumeTestCase): multiattach=True, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, None, 'fake_host', mountpoint, 'rw') vol = db.volume_get(context.get_admin_context(), volume_id) @@ -2718,7 +2740,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, volume=volume) def test_run_attach_detach_not_multiattach_volume_for_hosts(self): """Make sure volume can't be attached to more than one host.""" @@ -2729,7 +2751,7 @@ class VolumeTestCase(BaseVolumeTestCase): multiattach=False, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) attachment = self.volume.attach_volume(self.context, volume_id, None, 'fake_host', mountpoint, 'rw') vol = db.volume_get(context.get_admin_context(), volume_id) @@ -2772,12 +2794,13 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) self.volume.detach_volume(self.context, volume_id, attachment['id']) vol = db.volume_get(self.context, volume_id) self.assertEqual('available', vol['status']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2857,7 +2880,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual('readonly', admin_metadata[0]['key']) self.assertEqual('True', admin_metadata[0]['value']) - self.volume.delete_volume(self.context, volume_id) + self.volume.delete_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, @@ -2871,7 +2894,7 @@ class VolumeTestCase(BaseVolumeTestCase): admin_metadata={'readonly': 'True'}, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) self.assertRaises(exception.InvalidVolumeAttachMode, self.volume.attach_volume, self.context, @@ -2926,7 +2949,7 @@ class VolumeTestCase(BaseVolumeTestCase): admin_metadata={'readonly': 'True'}, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) volume_api = cinder.volume.api.API() self.assertRaises(exception.InvalidVolumeAttachMode, volume_api.attach, @@ -2972,7 +2995,7 @@ class VolumeTestCase(BaseVolumeTestCase): admin_metadata={'readonly': 'True'}, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) self.volume.attach_volume(self.context, volume_id, instance_uuid, None, mountpoint, 'ro') # Change volume status to 'uploading' @@ -3038,7 +3061,7 @@ class VolumeTestCase(BaseVolumeTestCase): **self.volume_params) self.assertEqual(0, len(self.notifier.notifications), self.notifier.notifications) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) msg = self.notifier.notifications[0] self.assertEqual('volume.create.start', msg['event_type']) self.assertEqual('creating', msg['payload']['status']) @@ -3116,7 +3139,7 @@ class VolumeTestCase(BaseVolumeTestCase): db.snapshot_get, self.context, snapshot_id) - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_create_delete_snapshot_with_metadata(self): """Test snapshot can be created with metadata and deleted.""" @@ -3143,7 +3166,8 @@ class VolumeTestCase(BaseVolumeTestCase): test_volume = tests_utils.create_volume( self.context, **self.volume_params) - self.volume.create_volume(self.context, test_volume['id']) + self.volume.create_volume(self.context, test_volume.id, + volume=test_volume) test_volume['status'] = 'available' volume_api = cinder.volume.api.API() self.assertRaises(exception.InvalidSnapshot, @@ -3158,7 +3182,8 @@ class VolumeTestCase(BaseVolumeTestCase): test_volume = tests_utils.create_volume( self.context, **self.volume_params) - self.volume.create_volume(self.context, test_volume['id']) + self.volume.create_volume(self.context, test_volume.id, + volume=test_volume) test_volume['status'] = 'maintenance' volume_api = cinder.volume.api.API() self.assertRaises(exception.InvalidVolume, @@ -3176,8 +3201,8 @@ class VolumeTestCase(BaseVolumeTestCase): test_volume = tests_utils.create_volume( self.context, **self.volume_params) - self.volume.create_volume(self.context, test_volume['id'], - request_spec={}) + self.volume.create_volume(self.context, test_volume.id, + request_spec={}, volume=test_volume) test_volume['status'] = 'available' volume_api = cinder.volume.api.API() self.assertRaises(exception.QuotaError, @@ -3208,7 +3233,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume) # clean up - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_force_delete_volume(self): """Test volume can be forced to delete.""" @@ -3231,7 +3256,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual('deleting', volume.status) # clean up - self.volume.delete_volume(self.context, volume.id) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_cannot_force_delete_attached_volume(self): """Test volume can't be force delete in attached state.""" @@ -3250,7 +3275,7 @@ class VolumeTestCase(BaseVolumeTestCase): def test_cannot_delete_volume_with_snapshots(self): """Test volume can't be deleted with dependent snapshots.""" volume = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) snapshot = create_snapshot(volume['id'], size=volume['size']) self.volume.create_snapshot(self.context, volume['id'], snapshot) self.assertEqual( @@ -3267,7 +3292,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.context, volume) self.volume.delete_snapshot(self.context, snapshot) - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_can_delete_errored_snapshot(self): """Test snapshot can be created and deleted.""" @@ -3284,7 +3309,7 @@ class VolumeTestCase(BaseVolumeTestCase): self.volume_api.delete_snapshot(self.context, snapshot) self.assertEqual('deleting', snapshot.status) - self.volume.delete_volume(self.context, volume.id) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_create_snapshot_force(self): """Test snapshot in use can be created forcibly.""" @@ -3292,7 +3317,7 @@ class VolumeTestCase(BaseVolumeTestCase): instance_uuid = '12345678-1234-5678-1234-567812345678' # create volume and attach to the instance volume = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) values = {'volume_id': volume['id'], 'instance_uuid': instance_uuid, 'attach_status': 'attaching', } @@ -3315,7 +3340,7 @@ class VolumeTestCase(BaseVolumeTestCase): # create volume and attach to the host volume = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) values = {'volume_id': volume['id'], 'attached_host': 'fake_host', 'attach_status': 'attaching', } @@ -3422,7 +3447,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) # set bootable flag of volume to True db.volume_update(self.context, volume_id, {'bootable': True}) @@ -3449,7 +3474,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) snapshot = create_snapshot(volume_id, size=volume['size']) self.volume.create_snapshot(self.context, volume_id, snapshot) @@ -3476,7 +3501,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, **self.volume_params) volume_id = volume['id'] - self.volume.create_volume(self.context, volume_id) + self.volume.create_volume(self.context, volume_id, volume=volume) snapshot = create_snapshot(volume_id) snapshot_id = snapshot.id self.volume.create_snapshot(self.context, volume_id, snapshot) @@ -3500,7 +3525,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertRaises(exception.VolumeBackendAPIException, self.volume.delete_volume, self.context, - volume_id) + volume_id, + volume=volume) @mock.patch('cinder.volume.drivers.lvm.LVMVolumeDriver.' 'create_cloned_volume') @@ -3545,7 +3571,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = self._create_volume_from_image() self.assertEqual('available', volume['status']) self.assertTrue(volume['bootable']) - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_create_volume_from_image_not_cloned_status_available(self): """Test create volume from image via full copy. @@ -3556,7 +3582,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = self._create_volume_from_image(fakeout_clone_image=True) self.assertEqual('available', volume['status']) self.assertTrue(volume['bootable']) - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_create_volume_from_image_exception(self): """Test create volume from a non-existing image. @@ -3583,7 +3609,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.volume.create_volume, self.context, volume.id, - {'image_id': self.FAKE_UUID}) + {'image_id': self.FAKE_UUID}, + volume=volume) volume = objects.Volume.get_by_id(self.context, volume.id) self.assertEqual("error", volume['status']) self.assertFalse(volume['bootable']) @@ -3645,7 +3672,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume = self._create_volume_from_image(clone_image_volume=True) self.assertEqual('available', volume['status']) self.assertTrue(volume['bootable']) - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_create_volume_from_exact_sized_image(self): """Test create volume from an image of the same size. @@ -3903,8 +3930,8 @@ class VolumeTestCase(BaseVolumeTestCase): # works when new_size > orig_size reserve.return_value = ["RESERVATION"] volume_api.extend(self.context, volume, 3) - volume_db = db.volume_get(context.get_admin_context(), volume['id']) - self.assertEqual('extending', volume_db['status']) + volume.refresh() + self.assertEqual('extending', volume.status) reserve.assert_called_once_with(self.context, gigabytes=1, project_id=volume.project_id) @@ -3926,7 +3953,7 @@ class VolumeTestCase(BaseVolumeTestCase): volume, 3) # clean up - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_extend_volume_driver_not_initialized(self): """Test volume can be extended at API level.""" @@ -3935,21 +3962,21 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, size=2, status='available', host=CONF.host) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) self.volume.driver._initialized = False self.assertRaises(exception.DriverNotInitialized, self.volume.extend_volume, self.context, volume['id'], 3, - fake_reservations) + fake_reservations, volume=volume) - volume = db.volume_get(context.get_admin_context(), volume['id']) + volume.refresh() self.assertEqual('error_extending', volume.status) # lets cleanup the mess. self.volume.driver._initialized = True - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_extend_volume_manager(self): """Test volume can be extended at the manager level.""" @@ -3959,7 +3986,7 @@ class VolumeTestCase(BaseVolumeTestCase): fake_reservations = ['RESERVATION'] volume = tests_utils.create_volume(self.context, size=2, status='creating', host=CONF.host) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) # Test driver exception with mock.patch.object(self.volume.driver, @@ -3968,30 +3995,29 @@ class VolumeTestCase(BaseVolumeTestCase): exception.CinderException('fake exception') volume['status'] = 'extending' self.volume.extend_volume(self.context, volume['id'], '4', - fake_reservations) - volume = db.volume_get(context.get_admin_context(), volume['id']) - self.assertEqual(2, volume['size']) - self.assertEqual('error_extending', volume['status']) + fake_reservations, volume=volume) + volume.refresh() + self.assertEqual(2, volume.size) + self.assertEqual('error_extending', volume.status) # Test driver success with mock.patch.object(self.volume.driver, 'extend_volume') as extend_volume: with mock.patch.object(QUOTAS, 'commit') as quotas_commit: extend_volume.return_value = fake_extend - volume['status'] = 'extending' - self.volume.extend_volume(self.context, volume['id'], '4', - fake_reservations) - volume = db.volume_get(context.get_admin_context(), - volume['id']) - self.assertEqual(4, volume['size']) - self.assertEqual('available', volume['status']) + volume.status = 'extending' + self.volume.extend_volume(self.context, volume.id, '4', + fake_reservations, volume=volume) + volume.refresh() + self.assertEqual(4, volume.size) + self.assertEqual('available', volume.status) quotas_commit.assert_called_with( self.context, ['RESERVATION'], - project_id=volume['project_id']) + project_id=volume.project_id) # clean up - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) @mock.patch('cinder.volume.rpcapi.VolumeAPI.extend_volume') def test_extend_volume_with_volume_type(self, mock_rpc_extend): @@ -4030,18 +4056,22 @@ class VolumeTestCase(BaseVolumeTestCase): volume_src = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) volume_dst = tests_utils.create_volume( self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_dst['id'], - {'source_replicaid': volume_src['id']}) + self.volume.create_volume(self.context, volume_dst.id, + {'source_replicaid': volume_src.id}, + volume=volume_dst) self.assertEqual('available', db.volume_get(context.get_admin_context(), volume_dst['id']).status) self.assertTrue(_create_replica_test.called) - self.volume.delete_volume(self.context, volume_dst['id']) - self.volume.delete_volume(self.context, volume_src['id']) + self.volume.delete_volume(self.context, volume_dst.id, + volume=volume_dst) + self.volume.delete_volume(self.context, volume_src.id, + volume=volume_src) def test_create_volume_from_sourcevol(self): """Test volume can be created from a source volume.""" @@ -4052,16 +4082,19 @@ class VolumeTestCase(BaseVolumeTestCase): fake_create_cloned_volume) volume_src = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) volume_dst = tests_utils.create_volume(self.context, source_volid=volume_src['id'], **self.volume_params) - self.volume.create_volume(self.context, volume_dst['id']) - self.assertEqual('available', - db.volume_get(context.get_admin_context(), - volume_dst['id']).status) - self.volume.delete_volume(self.context, volume_dst['id']) - self.volume.delete_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_dst.id, + volume=volume_dst) + volume_dst.refresh() + self.assertEqual('available', volume_dst.status) + self.volume.delete_volume(self.context, volume_dst.id, + volume=volume_dst) + self.volume.delete_volume(self.context, volume_src.id, + volume=volume_src) @mock.patch('cinder.volume.api.API.list_availability_zones', return_value=({'name': 'nova', 'available': True}, @@ -4073,7 +4106,8 @@ class VolumeTestCase(BaseVolumeTestCase): volume_src = tests_utils.create_volume(self.context, availability_zone='az2', **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) volume_src = db.volume_get(self.context, volume_src['id']) @@ -4101,11 +4135,13 @@ class VolumeTestCase(BaseVolumeTestCase): self.stubs.Set(self.volume.driver, 'create_cloned_volume', fake_create_cloned_volume) volume_src = self._create_volume_from_image() - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) volume_dst = tests_utils.create_volume(self.context, source_volid=volume_src['id'], **self.volume_params) - self.volume.create_volume(self.context, volume_dst['id']) + self.volume.create_volume(self.context, volume_dst.id, + volume=volume_dst) self.assertEqual('available', db.volume_get(context.get_admin_context(), volume_dst['id']).status) @@ -4117,8 +4153,10 @@ class VolumeTestCase(BaseVolumeTestCase): for meta_dst in dst_glancemeta: if meta_dst.key == meta_src.key: self.assertEqual(meta_src.value, meta_dst.value) - self.volume.delete_volume(self.context, volume_src['id']) - self.volume.delete_volume(self.context, volume_dst['id']) + self.volume.delete_volume(self.context, volume_src.id, + volume=volume_src) + self.volume.delete_volume(self.context, volume_dst.id, + volume=volume_dst) def test_create_volume_from_sourcevol_failed_clone(self): """Test src vol status will be restore by error handling code.""" @@ -4130,17 +4168,21 @@ class VolumeTestCase(BaseVolumeTestCase): fake_error_create_cloned_volume) volume_src = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume_src['id']) + self.volume.create_volume(self.context, volume_src.id, + volume=volume_src) volume_dst = tests_utils.create_volume(self.context, source_volid=volume_src['id'], **self.volume_params) self.assertRaises(exception.CinderException, self.volume.create_volume, self.context, - volume_dst['id']) + volume_dst.id, + volume=volume_dst) self.assertEqual('creating', volume_src['status']) - self.volume.delete_volume(self.context, volume_dst['id']) - self.volume.delete_volume(self.context, volume_src['id']) + self.volume.delete_volume(self.context, volume_dst.id, + volume=volume_dst) + self.volume.delete_volume(self.context, volume_src.id, + volume=volume_src) def test_clean_temporary_volume(self): def fake_delete_volume(ctxt, volume): @@ -4223,8 +4265,8 @@ class VolumeTestCase(BaseVolumeTestCase): volume = tests_utils.create_volume(self.context, admin_metadata={'readonly': 'True'}, **self.volume_params) - self.volume.create_volume(self.context, volume['id']) - volume['status'] = 'in-use' + self.volume.create_volume(self.context, volume.id, volume=volume) + volume.status = 'in-use' def sort_func(obj): return obj['name'] @@ -4238,20 +4280,20 @@ class VolumeTestCase(BaseVolumeTestCase): volume, False) - volume['status'] = 'available' + volume.status = 'available' # works when volume in 'available' status volume_api.update_readonly_flag(self.context, volume, False) - volume = db.volume_get(context.get_admin_context(), volume['id']) - self.assertEqual('available', volume['status']) - admin_metadata = volume['volume_admin_metadata'] + volume.refresh() + self.assertEqual('available', volume.status) + admin_metadata = volume.volume_admin_metadata self.assertEqual(1, len(admin_metadata)) self.assertEqual('readonly', admin_metadata[0]['key']) self.assertEqual('False', admin_metadata[0]['value']) # clean up - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume.id, volume=volume) def test_secure_file_operations_enabled(self): """Test secure file operations setting for base driver. @@ -4289,7 +4331,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.volume.create_volume, self.context, test_vol_id, {'volume_properties': self.volume_params}, - {'retry': {'num_attempts': 1, 'host': []}}) + {'retry': {'num_attempts': 1, 'host': []}}, + volume=test_vol) self.assertTrue(mock_reschedule.called) volume = db.volume_get(context.get_admin_context(), test_vol_id) self.assertEqual('creating', volume['status']) @@ -4307,14 +4350,15 @@ class VolumeTestCase(BaseVolumeTestCase): self.volume.create_volume, self.context, test_vol_id, {'volume_properties': self.volume_params}, - {'retry': {'num_attempts': 1, 'host': []}}) + {'retry': {'num_attempts': 1, 'host': []}}, + volume=test_vol) volume = db.volume_get(context.get_admin_context(), test_vol_id) self.assertEqual('error', volume['status']) def test_cascade_delete_volume_with_snapshots(self): """Test volume deletion with dependent snapshots.""" volume = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) snapshot = create_snapshot(volume['id'], size=volume['size']) self.volume.create_snapshot(self.context, volume['id'], snapshot) self.assertEqual( @@ -4333,7 +4377,7 @@ class VolumeTestCase(BaseVolumeTestCase): def test_cascade_delete_volume_with_snapshots_error(self): """Test volume deletion with dependent snapshots.""" volume = tests_utils.create_volume(self.context, **self.volume_params) - self.volume.create_volume(self.context, volume['id']) + self.volume.create_volume(self.context, volume.id, volume=volume) snapshot = create_snapshot(volume['id'], size=volume['size']) self.volume.create_snapshot(self.context, volume['id'], snapshot) self.assertEqual( @@ -4616,7 +4660,8 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): new_volume_obj, remote='dest') migrate_volume_completion.assert_called_with( - self.context, volume.id, new_volume_obj.id, error=False) + self.context, volume.id, new_volume_obj.id, error=False, + volume=volume, new_volume=new_volume_obj) self.assertFalse(update_server_volume.called) @mock.patch('cinder.compute.API') @@ -4867,7 +4912,8 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): def test_migrate_volume_generic_migrate_volume_completion_error(self): def fake_migrate_volume_completion(ctxt, volume_id, new_volume_id, - error=False): + error=False, volume=None, + new_volume=None): db.volume_update(ctxt, volume['id'], {'migration_status': 'completing'}) raise processutils.ProcessExecutionError @@ -4953,8 +4999,12 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): 'update_migrated_volume'),\ mock.patch.object(self.volume.driver, 'attach_volume'): mock_attach_volume.side_effect = self.fake_attach_volume + old_volume_host = old_volume.host + new_volume_host = new_volume.host self.volume.migrate_volume_completion(self.context, old_volume.id, - new_volume.id) + new_volume.id, + volume=old_volume, + new_volume=new_volume) after_new_volume = objects.Volume.get_by_id(self.context, new_volume.id) after_old_volume = objects.Volume.get_by_id(self.context, @@ -4971,8 +5021,11 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): else: self.assertFalse(mock_detach_volume.called) self.assertTrue(mock_delete_volume.called) - self.assertEqual(old_volume.host, after_new_volume.host) - self.assertEqual(new_volume.host, after_old_volume.host) + # NOTE(sborkows): the migrate_volume_completion method alters + # old and new volume objects, so we need to check the equality + # between the former host value and the actual one. + self.assertEqual(old_volume_host, after_new_volume.host) + self.assertEqual(new_volume_host, after_old_volume.host) def test_migrate_volume_completion_retype_available(self): self._test_migrate_volume_completion('available', retyping=True) @@ -5244,7 +5297,7 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): # lets cleanup the mess. self.volume.driver._initialized = True - self.volume.delete_volume(self.context, volume['id']) + self.volume.delete_volume(self.context, volume['id'], volume=volume) def test_delete_source_volume_in_migration(self): """Test deleting a source volume that is in migration.""" @@ -5257,15 +5310,15 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): def _test_delete_volume_in_migration(self, migration_status): """Test deleting a volume that is in migration.""" volume = tests_utils.create_volume(self.context, **self.volume_params) - volume = db.volume_update(self.context, volume['id'], - {'status': 'available', - 'migration_status': migration_status}) - self.volume.delete_volume(self.context, volume['id']) + vol = db.volume_update(self.context, volume.id, + {'status': 'available', + 'migration_status': migration_status}) + self.volume.delete_volume(self.context, vol['id'], volume=volume) # The volume is successfully removed during the volume delete # and won't exist in the database any more. self.assertRaises(exception.VolumeNotFound, db.volume_get, - self.context, volume['id']) + self.context, vol['id']) class ReplicationTestCase(BaseVolumeTestCase): diff --git a/cinder/tests/unit/test_volume_rpcapi.py b/cinder/tests/unit/test_volume_rpcapi.py index 6e335dca591..7db575f4eb1 100644 --- a/cinder/tests/unit/test_volume_rpcapi.py +++ b/cinder/tests/unit/test_volume_rpcapi.py @@ -17,13 +17,11 @@ Unit Tests for cinder.volume.rpcapi """ import copy -import mock from oslo_config import cfg from oslo_serialization import jsonutils from cinder import context from cinder import db -from cinder import exception from cinder import objects from cinder import test from cinder.tests.unit import fake_backup @@ -221,58 +219,29 @@ class VolumeRpcAPITestCase(test.TestCase): else: self.assertEqual(expected_msg[kwarg], value) - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_create_consistencygroup(self, mock_can_send_version): + def test_create_consistencygroup(self): self._test_volume_api('create_consistencygroup', rpc_method='cast', group=self.fake_cg, host='fake_host1', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('create_consistencygroup', rpc_method='cast', - group=self.fake_cg, host='fake_host1', - version='1.26') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_delete_consistencygroup(self, mock_can_send_version): + def test_delete_consistencygroup(self): self._test_volume_api('delete_consistencygroup', rpc_method='cast', group=self.fake_cg, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('delete_consistencygroup', rpc_method='cast', - group=self.fake_cg, version='1.26') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_update_consistencygroup(self, mock_can_send_version): + def test_update_consistencygroup(self): self._test_volume_api('update_consistencygroup', rpc_method='cast', group=self.fake_cg, add_volumes=['vol1'], remove_volumes=['vol2'], version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('update_consistencygroup', rpc_method='cast', - group=self.fake_cg, add_volumes=['vol1'], - remove_volumes=['vol2'], version='1.26') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_create_cgsnapshot(self, mock_can_send_version): + def test_create_cgsnapshot(self): self._test_volume_api('create_cgsnapshot', rpc_method='cast', cgsnapshot=self.fake_cgsnap, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('create_cgsnapshot', rpc_method='cast', - cgsnapshot=self.fake_cgsnap, version='1.31') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_delete_cgsnapshot(self, mock_can_send_version): + def test_delete_cgsnapshot(self): self._test_volume_api('delete_cgsnapshot', rpc_method='cast', cgsnapshot=self.fake_cgsnap, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('delete_cgsnapshot', rpc_method='cast', - cgsnapshot=self.fake_cgsnap, version='1.31') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=True) - def test_create_volume(self, can_send_version): + def test_create_volume(self): self._test_volume_api('create_volume', rpc_method='cast', volume=self.fake_volume_obj, @@ -281,26 +250,8 @@ class VolumeRpcAPITestCase(test.TestCase): filter_properties='fake_properties', allow_reschedule=True, version='2.0') - can_send_version.assert_called_once_with('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=False) - def test_create_volume_old(self, can_send_version): - # Tests backwards compatibility with older clients - self._test_volume_api('create_volume', - rpc_method='cast', - volume=self.fake_volume_obj, - host='fake_host1', - request_spec='fake_request_spec', - filter_properties='fake_properties', - allow_reschedule=True, - version='1.24') - can_send_version.assert_has_calls([mock.call('2.0'), - mock.call('1.32')]) - - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=True) - def test_create_volume_serialization(self, can_send_version): + def test_create_volume_serialization(self): request_spec = {"metadata": self.fake_volume_metadata} self._test_volume_api('create_volume', rpc_method='cast', @@ -310,59 +261,31 @@ class VolumeRpcAPITestCase(test.TestCase): filter_properties='fake_properties', allow_reschedule=True, version='2.0') - can_send_version.assert_called_once_with('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=True) - def test_delete_volume(self, can_send_version): + def test_delete_volume(self): self._test_volume_api('delete_volume', rpc_method='cast', volume=self.fake_volume_obj, unmanage_only=False, cascade=False, version='2.0') - can_send_version.assert_called_once_with('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=False) - def test_delete_volume_old(self, can_send_version): - self._test_volume_api('delete_volume', - rpc_method='cast', - volume=self.fake_volume_obj, - unmanage_only=False, - version='1.15') - can_send_version.assert_has_calls([mock.call('2.0'), - mock.call('1.40'), - mock.call('1.33')]) - - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=True) - def test_delete_volume_cascade(self, can_send_version): + def test_delete_volume_cascade(self): self._test_volume_api('delete_volume', rpc_method='cast', volume=self.fake_volume_obj, unmanage_only=False, cascade=True, version='2.0') - can_send_version.assert_any_call('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_create_snapshot(self, mock_can_send_version): + def test_create_snapshot(self): self._test_volume_api('create_snapshot', rpc_method='cast', volume=self.fake_volume, snapshot=self.fake_snapshot, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('create_snapshot', - rpc_method='cast', - volume=self.fake_volume, - snapshot=self.fake_snapshot, - version='1.20') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_delete_snapshot(self, mock_can_send_version): + def test_delete_snapshot(self): self._test_volume_api('delete_snapshot', rpc_method='cast', snapshot=self.fake_snapshot, @@ -370,16 +293,7 @@ class VolumeRpcAPITestCase(test.TestCase): unmanage_only=False, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('delete_snapshot', - rpc_method='cast', - snapshot=self.fake_snapshot, - host='fake_host', - unmanage_only=False, - version='1.20') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_delete_snapshot_with_unmanage_only(self, mock_can_send_version): + def test_delete_snapshot_with_unmanage_only(self): self._test_volume_api('delete_snapshot', rpc_method='cast', snapshot=self.fake_snapshot, @@ -387,16 +301,7 @@ class VolumeRpcAPITestCase(test.TestCase): unmanage_only=True, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('delete_snapshot', - rpc_method='cast', - snapshot=self.fake_snapshot, - host='fake_host', - unmanage_only=True, - version='1.20') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_attach_volume_to_instance(self, mock_can_send_version): + def test_attach_volume_to_instance(self): self._test_volume_api('attach_volume', rpc_method='call', volume=self.fake_volume, @@ -406,18 +311,7 @@ class VolumeRpcAPITestCase(test.TestCase): mode='ro', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('attach_volume', - rpc_method='call', - volume=self.fake_volume, - instance_uuid='fake_uuid', - host_name=None, - mountpoint='fake_mountpoint', - mode='ro', - version='1.11') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_attach_volume_to_host(self, mock_can_send_version): + def test_attach_volume_to_host(self): self._test_volume_api('attach_volume', rpc_method='call', volume=self.fake_volume, @@ -427,33 +321,14 @@ class VolumeRpcAPITestCase(test.TestCase): mode='rw', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('attach_volume', - rpc_method='call', - volume=self.fake_volume, - instance_uuid=None, - host_name='fake_host', - mountpoint='fake_mountpoint', - mode='rw', - version='1.11') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_detach_volume(self, mock_can_send_version): + def test_detach_volume(self): self._test_volume_api('detach_volume', rpc_method='call', volume=self.fake_volume, attachment_id='fake_uuid', version="2.0") - mock_can_send_version.return_value = False - self._test_volume_api('detach_volume', - rpc_method='call', - volume=self.fake_volume, - attachment_id='fake_uuid', - version="1.20") - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_copy_volume_to_image(self, mock_can_send_version): + def test_copy_volume_to_image(self): self._test_volume_api('copy_volume_to_image', rpc_method='cast', volume=self.fake_volume, @@ -462,32 +337,14 @@ class VolumeRpcAPITestCase(test.TestCase): 'disk_format': 'fake_type'}, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('copy_volume_to_image', - rpc_method='cast', - volume=self.fake_volume, - image_meta={'id': 'fake_image_id', - 'container_format': 'fake_type', - 'disk_format': 'fake_type'}, - version='1.3') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_initialize_connection(self, mock_can_send_version): + def test_initialize_connection(self): self._test_volume_api('initialize_connection', rpc_method='call', volume=self.fake_volume, connector='fake_connector', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('initialize_connection', - rpc_method='call', - volume=self.fake_volume, - connector='fake_connector', - version='1.0') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_terminate_connection(self, mock_can_send_version): + def test_terminate_connection(self): self._test_volume_api('terminate_connection', rpc_method='call', volume=self.fake_volume, @@ -495,16 +352,7 @@ class VolumeRpcAPITestCase(test.TestCase): force=False, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('terminate_connection', - rpc_method='call', - volume=self.fake_volume, - connector='fake_connector', - force=False, - version='1.0') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_accept_transfer(self, mock_can_send_version): + def test_accept_transfer(self): self._test_volume_api('accept_transfer', rpc_method='call', volume=self.fake_volume, @@ -514,42 +362,15 @@ class VolumeRpcAPITestCase(test.TestCase): '-8ffd-0800200c9a66', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('accept_transfer', - rpc_method='call', - volume=self.fake_volume, - new_user='e5565fd0-06c8-11e3-' - '8ffd-0800200c9b77', - new_project='e4465fd0-06c8-11e3' - '-8ffd-0800200c9a66', - version='1.9') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=True) - def test_extend_volume(self, can_send_version): + def test_extend_volume(self): self._test_volume_api('extend_volume', rpc_method='cast', volume=self.fake_volume_obj, new_size=1, reservations=self.fake_reservations, version='2.0') - can_send_version.assert_called_once_with('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=False) - def test_extend_volume_old(self, can_send_version): - self._test_volume_api('extend_volume', - rpc_method='cast', - volume=self.fake_volume_obj, - new_size=1, - reservations=self.fake_reservations, - version='1.14') - can_send_version.assert_has_calls([mock.call('2.0'), - mock.call('1.35')]) - - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=True) - def test_migrate_volume(self, can_send_version): + def test_migrate_volume(self): class FakeHost(object): def __init__(self): self.host = 'host' @@ -561,51 +382,16 @@ class VolumeRpcAPITestCase(test.TestCase): dest_host=dest_host, force_host_copy=True, version='2.0') - can_send_version.assert_called_once_with('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=False) - def test_migrate_volume_old(self, can_send_version): - class FakeHost(object): - def __init__(self): - self.host = 'host' - self.capabilities = {} - dest_host = FakeHost() - self._test_volume_api('migrate_volume', - rpc_method='cast', - volume=self.fake_volume_obj, - dest_host=dest_host, - force_host_copy=True, - version='1.8') - can_send_version.assert_has_calls([mock.call('2.0'), - mock.call('1.36')]) - - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=True) - def test_migrate_volume_completion(self, can_send_version): + def test_migrate_volume_completion(self): self._test_volume_api('migrate_volume_completion', rpc_method='call', volume=self.fake_volume_obj, new_volume=self.fake_volume_obj, error=False, version='2.0') - can_send_version.assert_called_once_with('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - return_value=False) - def test_migrate_volume_completion_old(self, can_send_version): - self._test_volume_api('migrate_volume_completion', - rpc_method='call', - volume=self.fake_volume_obj, - new_volume=self.fake_volume_obj, - error=False, - version='1.10') - can_send_version.assert_has_calls([mock.call('2.0'), - mock.call('1.36')]) - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - @mock.patch('cinder.quota.DbQuotaDriver.rollback') - def test_retype(self, rollback, can_send_version): + def test_retype(self): class FakeHost(object): def __init__(self): self.host = 'host' @@ -620,93 +406,15 @@ class VolumeRpcAPITestCase(test.TestCase): reservations=self.fake_reservations, old_reservations=self.fake_reservations, version='2.0') - rollback.assert_not_called() - can_send_version.assert_called_once_with('2.0') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - side_effect=[False, True]) - @mock.patch('cinder.quota.DbQuotaDriver.rollback') - def test_retype_137(self, rollback, can_send_version): - class FakeHost(object): - def __init__(self): - self.host = 'host' - self.capabilities = {} - dest_host = FakeHost() - self._test_volume_api('retype', - rpc_method='cast', - volume=self.fake_volume_obj, - new_type_id='fake', - dest_host=dest_host, - migration_policy='never', - reservations=self.fake_reservations, - old_reservations=self.fake_reservations, - version='1.37') - rollback.assert_not_called() - can_send_version.assert_any_call('2.0') - can_send_version.assert_any_call('1.37') - - @mock.patch('cinder.quota.DbQuotaDriver.rollback') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - side_effect=[False, False, True]) - def test_retype_version_134(self, can_send_version, rollback): - class FakeHost(object): - def __init__(self): - self.host = 'host' - self.capabilities = {} - dest_host = FakeHost() - self._test_volume_api('retype', - rpc_method='cast', - volume=self.fake_volume_obj, - new_type_id='fake', - dest_host=dest_host, - migration_policy='never', - reservations=self.fake_reservations, - old_reservations=self.fake_reservations, - version='1.34') - self.assertTrue(rollback.called) - can_send_version.assert_any_call('2.0') - can_send_version.assert_any_call('1.37') - can_send_version.assert_any_call('1.34') - - @mock.patch('cinder.quota.DbQuotaDriver.rollback') - @mock.patch('oslo_messaging.RPCClient.can_send_version', - side_effect=[False, False, False]) - def test_retype_version_112(self, can_send_version, rollback): - class FakeHost(object): - def __init__(self): - self.host = 'host' - self.capabilities = {} - dest_host = FakeHost() - self._test_volume_api('retype', - rpc_method='cast', - volume=self.fake_volume_obj, - new_type_id='fake', - dest_host=dest_host, - migration_policy='never', - reservations=self.fake_reservations, - old_reservations=self.fake_reservations, - version='1.12') - self.assertTrue(rollback.called) - can_send_version.assert_any_call('1.37') - can_send_version.assert_any_call('1.34') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_manage_existing(self, mock_can_send_version): + def test_manage_existing(self): self._test_volume_api('manage_existing', rpc_method='cast', volume=self.fake_volume, ref={'lv_name': 'foo'}, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('manage_existing', - rpc_method='cast', - volume=self.fake_volume, - ref={'lv_name': 'foo'}, - version='1.15') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_manage_existing_snapshot(self, mock_can_send_version): + def test_manage_existing_snapshot(self): volume_update = {'host': 'fake_host'} snpshot = { 'id': fake.SNAPSHOT_ID, @@ -727,74 +435,33 @@ class VolumeRpcAPITestCase(test.TestCase): host='fake_host', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('manage_existing_snapshot', - rpc_method='cast', - snapshot=my_fake_snapshot_obj, - ref='foo', - host='fake_host', - version='1.28') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_promote_replica(self, mock_can_send_version): + def test_promote_replica(self): self._test_volume_api('promote_replica', rpc_method='cast', volume=self.fake_volume, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('promote_replica', - rpc_method='cast', - volume=self.fake_volume, - version='1.17') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_reenable_replica(self, mock_can_send_version): + def test_reenable_replica(self): self._test_volume_api('reenable_replication', rpc_method='cast', volume=self.fake_volume, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('reenable_replication', - rpc_method='cast', - volume=self.fake_volume, - version='1.17') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_freeze_host(self, mock_can_send_version): + def test_freeze_host(self): self._test_volume_api('freeze_host', rpc_method='call', host='fake_host', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('freeze_host', rpc_method='call', - host='fake_host', version='1.39') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_thaw_host(self, mock_can_send_version): + def test_thaw_host(self): self._test_volume_api('thaw_host', rpc_method='call', host='fake_host', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('thaw_host', rpc_method='call', host='fake_host', - version='1.39') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_failover_host(self, mock_can_send_version): + def test_failover_host(self): self._test_volume_api('failover_host', rpc_method='cast', host='fake_host', secondary_backend_id='fake_backend', version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('failover_host', rpc_method='cast', - host='fake_host', - secondary_backend_id='fake_backend', - version='1.39') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_create_consistencygroup_from_src_cgsnapshot( - self, mock_can_send_version): + def test_create_consistencygroup_from_src_cgsnapshot(self): self._test_volume_api('create_consistencygroup_from_src', rpc_method='cast', group=self.fake_cg, @@ -802,16 +469,7 @@ class VolumeRpcAPITestCase(test.TestCase): source_cg=None, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('create_consistencygroup_from_src', - rpc_method='cast', - group=self.fake_cg, - cgsnapshot=self.fake_cgsnap, - source_cg=None, - version='1.31') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_create_consistencygroup_from_src_cg(self, mock_can_send_version): + def test_create_consistencygroup_from_src_cg(self): self._test_volume_api('create_consistencygroup_from_src', rpc_method='cast', group=self.fake_cg2, @@ -819,64 +477,28 @@ class VolumeRpcAPITestCase(test.TestCase): source_cg=self.fake_src_cg, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('create_consistencygroup_from_src', - rpc_method='cast', - group=self.fake_cg2, - cgsnapshot=None, - source_cg=self.fake_src_cg, - version='1.31') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_get_capabilities(self, mock_can_send_version): + def test_get_capabilities(self): self._test_volume_api('get_capabilities', rpc_method='call', host='fake_host', discover=True, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('get_capabilities', - rpc_method='call', - host='fake_host', - discover=True, - version='1.29') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_remove_export(self, mock_can_send_version): + def test_remove_export(self): self._test_volume_api('remove_export', rpc_method='cast', volume=self.fake_volume, version='2.0') - mock_can_send_version.return_value = False - self._test_volume_api('remove_export', - rpc_method='cast', - volume=self.fake_volume, - version='1.30') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_get_backup_device(self, mock_can_send_version): + def test_get_backup_device(self): self._test_volume_api('get_backup_device', rpc_method='call', backup=self.fake_backup_obj, volume=self.fake_volume_obj, version='2.0') - mock_can_send_version.return_value = False - self.assertRaises(exception.ServiceTooOld, self._test_volume_api, - 'get_backup_device', rpc_method='call', - backup=self.fake_backup_obj, - volume=self.fake_volume_obj, version='1.38') - - @mock.patch('oslo_messaging.RPCClient.can_send_version', return_value=True) - def test_secure_file_operations_enabled(self, mock_can_send_version): + def test_secure_file_operations_enabled(self): self._test_volume_api('secure_file_operations_enabled', rpc_method='call', volume=self.fake_volume_obj, version='2.0') - - mock_can_send_version.return_value = False - self.assertRaises(exception.ServiceTooOld, self._test_volume_api, - 'secure_file_operations_enabled', rpc_method='call', - volume=self.fake_volume_obj, version='1.38') diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 2c971e10a09..0e65f4b1705 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -236,7 +236,6 @@ class VolumeManager(manager.SchedulerDependentManager): # update_service_capabilities needs service_name to be volume super(VolumeManager, self).__init__(service_name='volume', *args, **kwargs) - self.additional_endpoints.append(_VolumeV1Proxy(self)) self.configuration = config.Configuration(volume_manager_opts, config_group=service_name) self.stats = {} @@ -506,10 +505,10 @@ class VolumeManager(manager.SchedulerDependentManager): # threadpool to prevent the main volume service thread # from being blocked. self._add_to_threadpool(self.delete_volume, ctxt, - volume['id']) + volume['id'], volume=volume) else: # By default, delete volumes sequentially - self.delete_volume(ctxt, volume['id']) + self.delete_volume(ctxt, volume['id'], volume=volume) LOG.info(_LI("Resume volume delete completed successfully."), resource=volume) @@ -562,7 +561,7 @@ class VolumeManager(manager.SchedulerDependentManager): filter_properties=None, allow_reschedule=True, volume=None): """Creates the volume.""" - # FIXME(thangp): Remove this in v2.0 of RPC API. + # FIXME(dulek): Remove this in v3.0 of RPC API. if volume is None: # For older clients, mimic the old behavior and look up the volume # by its volume_id. @@ -678,7 +677,7 @@ class VolumeManager(manager.SchedulerDependentManager): context = context.elevated() try: - # FIXME(thangp): Remove this in v2.0 of RPC API. + # FIXME(dulek): Remove this in v3.0 of RPC API. if volume is None: volume = objects.Volume.get_by_id(context, volume_id) else: @@ -686,8 +685,7 @@ class VolumeManager(manager.SchedulerDependentManager): except exception.VolumeNotFound: # NOTE(thingee): It could be possible for a volume to # be deleted when resuming deletes from init_host(). - LOG.debug("Attempted delete of non-existent volume: %s", - volume_id) + LOG.debug("Attempted delete of non-existent volume: %s", volume_id) return if context.project_id != volume.project_id: @@ -1213,7 +1211,7 @@ class VolumeManager(manager.SchedulerDependentManager): try: self.create_volume(ctx, image_volume.id, - allow_reschedule=False) + allow_reschedule=False, volume=image_volume) image_volume = self.db.volume_get(ctx, image_volume.id) if image_volume.status != 'available': raise exception.InvalidVolume(_('Volume is not available.')) @@ -1729,7 +1727,9 @@ class VolumeManager(manager.SchedulerDependentManager): # The above call is synchronous so we complete the migration self.migrate_volume_completion(ctxt, volume.id, new_volume.id, - error=False) + error=False, + volume=volume, + new_volume=new_volume) else: nova_api = compute.API() # This is an async call to Nova, which will call the completion @@ -1788,7 +1788,7 @@ class VolumeManager(manager.SchedulerDependentManager): def migrate_volume_completion(self, ctxt, volume_id, new_volume_id, error=False, volume=None, new_volume=None): - # FIXME(thangp): Remove this in v2.0 of RPC API. + # FIXME(dulek): Remove this in v3.0 of RPC API. if volume is None or new_volume is None: # For older clients, mimic the old behavior and look up the volume # by its volume_id. @@ -1879,7 +1879,7 @@ class VolumeManager(manager.SchedulerDependentManager): def migrate_volume(self, ctxt, volume_id, host, force_host_copy=False, new_type_id=None, volume=None): """Migrate the volume to the specified host (called on source host).""" - # FIXME(thangp): Remove this in v2.0 of RPC API. + # FIXME(dulek): Remove this in v3.0 of RPC API. if volume is None: # For older clients, mimic the old behavior and look up the volume # by its volume_id. @@ -2060,7 +2060,7 @@ class VolumeManager(manager.SchedulerDependentManager): def extend_volume(self, context, volume_id, new_size, reservations, volume=None): - # FIXME(thangp): Remove this in v2.0 of RPC API. + # FIXME(dulek): Remove this in v3.0 of RPC API. if volume is None: # For older clients, mimic the old behavior and look up the volume # by its volume_id. @@ -2131,7 +2131,7 @@ class VolumeManager(manager.SchedulerDependentManager): context = ctxt.elevated() - # FIXME(thangp): Remove this in v2.0 of RPC API. + # FIXME(dulek): Remove this in v3.0 of RPC API. if volume is None: # For older clients, mimic the old behavior and look up the volume # by its volume_id. @@ -3172,15 +3172,8 @@ class VolumeManager(manager.SchedulerDependentManager): self._notify_about_cgsnapshot_usage(context, cgsnapshot, "delete.end", snapshots) - def update_migrated_volume(self, ctxt, volume, new_volume, - volume_status): + def update_migrated_volume(self, ctxt, volume, new_volume, volume_status): """Finalize migration process on backend device.""" - # FIXME(thangp): Remove this in v2.0 of RPC API. - if (not isinstance(volume, objects.Volume) or - not isinstance(new_volume, objects.Volume)): - volume = objects.Volume.get_by_id(ctxt, volume['id']) - new_volume = objects.Volume.get_by_id(ctxt, new_volume['id']) - model_update = None model_update_default = {'_name_id': new_volume.name_id, 'provider_location': @@ -3434,148 +3427,3 @@ class VolumeManager(manager.SchedulerDependentManager): def secure_file_operations_enabled(self, ctxt, volume): secure_enabled = self.driver.secure_file_operations_enabled() return secure_enabled - - -# TODO(dulek): This goes away immediately in Newton and is just present in -# Mitaka so that we can receive v1.x and v2.0 messages -class _VolumeV1Proxy(object): - - target = messaging.Target(version='1.40') - - def __init__(self, manager): - self.manager = manager - - def create_volume(self, context, volume_id, request_spec=None, - filter_properties=None, allow_reschedule=True, - volume=None): - return self.manager.create_volume( - context, volume_id, request_spec=request_spec, - filter_properties=filter_properties, - allow_reschedule=allow_reschedule, volume=volume) - - def delete_volume(self, context, volume_id, unmanage_only=False, - volume=None, cascade=False): - return self.manager.delete_volume( - context, volume_id, unmanage_only=unmanage_only, volume=volume, - cascade=cascade) - - def create_snapshot(self, context, volume_id, snapshot): - return self.manager.create_snapshot(context, volume_id, snapshot) - - def delete_snapshot(self, context, snapshot, unmanage_only=False): - return self.manager.delete_snapshot(context, snapshot, - unmanage_only=unmanage_only) - - def attach_volume(self, context, volume_id, instance_uuid, host_name, - mountpoint, mode): - return self.manager.attach_volume(context, volume_id, instance_uuid, - host_name, mountpoint, mode) - - def detach_volume(self, context, volume_id, attachment_id=None): - return self.manager.detach_volume(context, volume_id, - attachment_id=attachment_id) - - def copy_volume_to_image(self, context, volume_id, image_meta): - return self.manager.copy_volume_to_image(context, volume_id, - image_meta) - - def initialize_connection(self, context, volume_id, connector): - return self.manager.initialize_connection(context, volume_id, - connector) - - def terminate_connection(self, context, volume_id, connector, force=False): - return self.manager.terminate_connection(context, volume_id, connector, - force=force) - - def remove_export(self, context, volume_id): - return self.manager.remove_export(context, volume_id) - - def accept_transfer(self, context, volume_id, new_user, new_project): - return self.manager.accept_transfer(context, volume_id, new_user, - new_project) - - def migrate_volume_completion(self, ctxt, volume_id, new_volume_id, - error=False, volume=None, new_volume=None): - return self.manager.migrate_volume_completion( - ctxt, volume_id, new_volume_id, error=error, volume=volume, - new_volume=new_volume) - - def migrate_volume(self, ctxt, volume_id, host, force_host_copy=False, - new_type_id=None, volume=None): - return self.manager.migrate_volume( - ctxt, volume_id, host, force_host_copy=force_host_copy, - new_type_id=new_type_id, volume=volume) - - def publish_service_capabilities(self, context): - return self.manager.publish_service_capabilities(context) - - def extend_volume(self, context, volume_id, new_size, reservations, - volume=None): - return self.manager.extend_volume(context, volume_id, new_size, - reservations, volume=volume) - - def retype(self, ctxt, volume_id, new_type_id, host, - migration_policy='never', reservations=None, - volume=None, old_reservations=None): - return self.manager.retype(ctxt, volume_id, new_type_id, host, - migration_policy=migration_policy, - reservations=reservations, volume=volume, - old_reservations=old_reservations) - - def manage_existing(self, ctxt, volume_id, ref=None): - return self.manager.manage_existing(ctxt, volume_id, ref=ref) - - def promote_replica(self, ctxt, volume_id): - return self.manager.promote_replica(ctxt, volume_id) - - def reenable_replication(self, ctxt, volume_id): - return self.manager.reenable_replication(ctxt, volume_id) - - def create_consistencygroup(self, context, group): - return self.manager.create_consistencygroup(context, group) - - def create_consistencygroup_from_src(self, context, group, - cgsnapshot=None, source_cg=None): - return self.manager.create_consistencygroup_from_src( - context, group, cgsnapshot=cgsnapshot, source_cg=source_cg) - - def delete_consistencygroup(self, context, group): - return self.manager.delete_consistencygroup(context, group) - - def update_consistencygroup(self, context, group, add_volumes=None, - remove_volumes=None): - return self.manager.update_consistencygroup( - context, group, add_volumes=add_volumes, - remove_volumes=remove_volumes) - - def create_cgsnapshot(self, context, cgsnapshot): - return self.manager.create_cgsnapshot(context, cgsnapshot) - - def delete_cgsnapshot(self, context, cgsnapshot): - return self.manager.delete_cgsnapshot(context, cgsnapshot) - - def update_migrated_volume(self, ctxt, volume, new_volume, volume_status): - return self.manager.update_migrated_volume(ctxt, volume, new_volume, - volume_status) - - def failover_host(self, context, secondary_backend_id=None): - return self.manager.failover_host( - context, secondary_backend_id=secondary_backend_id) - - def freeze_host(self, context): - return self.manager.freeze_host(context) - - def thaw_host(self, context): - return self.manager.thaw_host(context) - - def manage_existing_snapshot(self, ctxt, snapshot, ref=None): - return self.manager.manage_exisiting_snapshot(ctxt, snapshot, ref=ref) - - def get_capabilities(self, context, discover): - return self.manager.get_capabilities(context, discover) - - def get_backup_device(self, ctxt, backup): - return self.manager.get_backup_device(ctxt, backup) - - def secure_file_operations_enabled(self, ctxt, volume): - return self.manager.secure_file_operations_enabled(ctxt, volume) diff --git a/cinder/volume/rpcapi.py b/cinder/volume/rpcapi.py index 742bf01d378..f90027a31e6 100644 --- a/cinder/volume/rpcapi.py +++ b/cinder/volume/rpcapi.py @@ -19,8 +19,6 @@ Client side of the volume RPC API. from oslo_config import cfg from oslo_serialization import jsonutils -from cinder import exception -from cinder.i18n import _ from cinder import quota from cinder import rpc from cinder.volume import utils @@ -103,36 +101,27 @@ class VolumeAPI(rpc.RPCAPI): 2.0 - Remove 1.x compatibility """ - RPC_API_VERSION = '1.40' + RPC_API_VERSION = '2.0' TOPIC = CONF.volume_topic BINARY = 'cinder-volume' - def _compat_ver(self, current, legacy): - if self.client.can_send_version(current): - return current - else: - return legacy - def _get_cctxt(self, host, version): new_host = utils.get_volume_rpc_host(host) return self.client.prepare(server=new_host, version=version) def create_consistencygroup(self, ctxt, group, host): - version = self._compat_ver('2.0', '1.26') - cctxt = self._get_cctxt(host, version) + cctxt = self._get_cctxt(host, '2.0') cctxt.cast(ctxt, 'create_consistencygroup', group=group) def delete_consistencygroup(self, ctxt, group): - version = self._compat_ver('2.0', '1.26') - cctxt = self._get_cctxt(group.host, version) + cctxt = self._get_cctxt(group.host, '2.0') cctxt.cast(ctxt, 'delete_consistencygroup', group=group) def update_consistencygroup(self, ctxt, group, add_volumes=None, remove_volumes=None): - version = self._compat_ver('2.0', '1.26') - cctxt = self._get_cctxt(group.host, version) + cctxt = self._get_cctxt(group.host, '2.0') cctxt.cast(ctxt, 'update_consistencygroup', group=group, add_volumes=add_volumes, @@ -140,83 +129,47 @@ class VolumeAPI(rpc.RPCAPI): def create_consistencygroup_from_src(self, ctxt, group, cgsnapshot=None, source_cg=None): - version = self._compat_ver('2.0', '1.31') - cctxt = self._get_cctxt(group.host, version) + cctxt = self._get_cctxt(group.host, '2.0') cctxt.cast(ctxt, 'create_consistencygroup_from_src', group=group, cgsnapshot=cgsnapshot, source_cg=source_cg) def create_cgsnapshot(self, ctxt, cgsnapshot): - version = self._compat_ver('2.0', '1.31') - cctxt = self._get_cctxt(cgsnapshot.consistencygroup.host, version) + cctxt = self._get_cctxt(cgsnapshot.consistencygroup.host, '2.0') cctxt.cast(ctxt, 'create_cgsnapshot', cgsnapshot=cgsnapshot) def delete_cgsnapshot(self, ctxt, cgsnapshot): - version = self._compat_ver('2.0', '1.31') - cctxt = self._get_cctxt(cgsnapshot.consistencygroup.host, version) + cctxt = self._get_cctxt(cgsnapshot.consistencygroup.host, '2.0') cctxt.cast(ctxt, 'delete_cgsnapshot', cgsnapshot=cgsnapshot) def create_volume(self, ctxt, volume, host, request_spec, filter_properties, allow_reschedule=True): request_spec_p = jsonutils.to_primitive(request_spec) - msg_args = {'volume_id': volume.id, 'request_spec': request_spec_p, - 'filter_properties': filter_properties, - 'allow_reschedule': allow_reschedule} - if self.client.can_send_version('2.0'): - version = '2.0' - msg_args['volume'] = volume - elif self.client.can_send_version('1.32'): - version = '1.32' - msg_args['volume'] = volume - else: - version = '1.24' - - cctxt = self._get_cctxt(host, version) - request_spec_p = jsonutils.to_primitive(request_spec) - cctxt.cast(ctxt, 'create_volume', **msg_args) + cctxt = self._get_cctxt(host, '2.0') + cctxt.cast(ctxt, 'create_volume', volume_id=volume.id, + request_spec=request_spec_p, + filter_properties=filter_properties, + allow_reschedule=allow_reschedule, volume=volume) def delete_volume(self, ctxt, volume, unmanage_only=False, cascade=False): - msg_args = {'volume_id': volume.id, 'unmanage_only': unmanage_only} - - version = '1.15' - - if self.client.can_send_version('2.0'): - version = '2.0' - msg_args['volume'] = volume - if cascade: - msg_args['cascade'] = cascade - elif self.client.can_send_version('1.40'): - version = '1.40' - msg_args['volume'] = volume - if cascade: - msg_args['cascade'] = cascade - elif cascade: - msg = _('Cascade option is not supported.') - raise exception.Invalid(reason=msg) - elif self.client.can_send_version('1.33'): - version = '1.33' - msg_args['volume'] = volume - - cctxt = self._get_cctxt(volume.host, version) - cctxt.cast(ctxt, 'delete_volume', **msg_args) + cctxt = self._get_cctxt(volume.host, '2.0') + cctxt.cast(ctxt, 'delete_volume', volume_id=volume.id, + unmanage_only=unmanage_only, volume=volume, cascade=cascade) def create_snapshot(self, ctxt, volume, snapshot): - version = self._compat_ver('2.0', '1.20') - cctxt = self._get_cctxt(volume['host'], version=version) + cctxt = self._get_cctxt(volume['host'], '2.0') cctxt.cast(ctxt, 'create_snapshot', volume_id=volume['id'], snapshot=snapshot) def delete_snapshot(self, ctxt, snapshot, host, unmanage_only=False): - version = self._compat_ver('2.0', '1.20') - cctxt = self._get_cctxt(host, version=version) + cctxt = self._get_cctxt(host, '2.0') cctxt.cast(ctxt, 'delete_snapshot', snapshot=snapshot, unmanage_only=unmanage_only) def attach_volume(self, ctxt, volume, instance_uuid, host_name, mountpoint, mode): - version = self._compat_ver('2.0', '1.11') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') return cctxt.call(ctxt, 'attach_volume', volume_id=volume['id'], instance_uuid=instance_uuid, @@ -225,143 +178,84 @@ class VolumeAPI(rpc.RPCAPI): mode=mode) def detach_volume(self, ctxt, volume, attachment_id): - version = self._compat_ver('2.0', '1.20') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') return cctxt.call(ctxt, 'detach_volume', volume_id=volume['id'], attachment_id=attachment_id) def copy_volume_to_image(self, ctxt, volume, image_meta): - version = self._compat_ver('2.0', '1.3') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') cctxt.cast(ctxt, 'copy_volume_to_image', volume_id=volume['id'], image_meta=image_meta) def initialize_connection(self, ctxt, volume, connector): - version = self._compat_ver('2.0', '1.0') - cctxt = self._get_cctxt(volume['host'], version=version) + cctxt = self._get_cctxt(volume['host'], '2.0') return cctxt.call(ctxt, 'initialize_connection', volume_id=volume['id'], connector=connector) def terminate_connection(self, ctxt, volume, connector, force=False): - version = self._compat_ver('2.0', '1.0') - cctxt = self._get_cctxt(volume['host'], version=version) + cctxt = self._get_cctxt(volume['host'], '2.0') return cctxt.call(ctxt, 'terminate_connection', volume_id=volume['id'], connector=connector, force=force) def remove_export(self, ctxt, volume): - version = self._compat_ver('2.0', '1.30') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') cctxt.cast(ctxt, 'remove_export', volume_id=volume['id']) def publish_service_capabilities(self, ctxt): - version = self._compat_ver('2.0', '1.2') - cctxt = self.client.prepare(fanout=True, version=version) + cctxt = self.client.prepare(fanout=True, version='2.0') cctxt.cast(ctxt, 'publish_service_capabilities') def accept_transfer(self, ctxt, volume, new_user, new_project): - version = self._compat_ver('2.0', '1.9') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') return cctxt.call(ctxt, 'accept_transfer', volume_id=volume['id'], new_user=new_user, new_project=new_project) def extend_volume(self, ctxt, volume, new_size, reservations): - msg_args = {'volume_id': volume.id, 'new_size': new_size, - 'reservations': reservations} - if self.client.can_send_version('2.0'): - version = '2.0' - msg_args['volume'] = volume - elif self.client.can_send_version('1.35'): - version = '1.35' - msg_args['volume'] = volume - else: - version = '1.14' - - cctxt = self._get_cctxt(volume.host, version) - cctxt.cast(ctxt, 'extend_volume', **msg_args) + cctxt = self._get_cctxt(volume.host, '2.0') + cctxt.cast(ctxt, 'extend_volume', volume_id=volume.id, + new_size=new_size, reservations=reservations, volume=volume) def migrate_volume(self, ctxt, volume, dest_host, force_host_copy): host_p = {'host': dest_host.host, 'capabilities': dest_host.capabilities} - - msg_args = {'volume_id': volume.id, 'host': host_p, - 'force_host_copy': force_host_copy} - if self.client.can_send_version('2.0'): - version = '2.0' - msg_args['volume'] = volume - elif self.client.can_send_version('1.36'): - version = '1.36' - msg_args['volume'] = volume - else: - version = '1.8' - - cctxt = self._get_cctxt(volume.host, version) - cctxt.cast(ctxt, 'migrate_volume', **msg_args) + cctxt = self._get_cctxt(volume.host, '2.0') + cctxt.cast(ctxt, 'migrate_volume', volume_id=volume.id, host=host_p, + force_host_copy=force_host_copy, volume=volume) def migrate_volume_completion(self, ctxt, volume, new_volume, error): - - msg_args = {'volume_id': volume.id, 'new_volume_id': new_volume.id, - 'error': error} - if self.client.can_send_version('2.0'): - version = '2.0' - msg_args['volume'] = volume - msg_args['new_volume'] = new_volume - elif self.client.can_send_version('1.36'): - version = '1.36' - msg_args['volume'] = volume - msg_args['new_volume'] = new_volume - else: - version = '1.10' - - cctxt = self._get_cctxt(volume.host, version) - return cctxt.call(ctxt, 'migrate_volume_completion', **msg_args) + cctxt = self._get_cctxt(volume.host, '2.0') + return cctxt.call(ctxt, 'migrate_volume_completion', + volume_id=volume.id, new_volume_id=new_volume.id, + error=error, volume=volume, new_volume=new_volume) def retype(self, ctxt, volume, new_type_id, dest_host, migration_policy='never', reservations=None, old_reservations=None): host_p = {'host': dest_host.host, 'capabilities': dest_host.capabilities} - msg_args = {'volume_id': volume.id, 'new_type_id': new_type_id, - 'host': host_p, 'migration_policy': migration_policy, - 'reservations': reservations} - if self.client.can_send_version('2.0'): - version = '2.0' - msg_args.update(volume=volume, old_reservations=old_reservations) - elif self.client.can_send_version('1.37'): - version = '1.37' - msg_args.update(volume=volume, old_reservations=old_reservations) - elif self.client.can_send_version('1.34'): - if old_reservations is not None: - QUOTAS.rollback(ctxt, old_reservations) - version = '1.34' - msg_args['volume'] = volume - else: - if old_reservations is not None: - QUOTAS.rollback(ctxt, old_reservations) - version = '1.12' - - cctxt = self._get_cctxt(volume.host, version) - cctxt.cast(ctxt, 'retype', **msg_args) + cctxt = self._get_cctxt(volume.host, '2.0') + cctxt.cast(ctxt, 'retype', volume_id=volume.id, + new_type_id=new_type_id, host=host_p, + migration_policy=migration_policy, + reservations=reservations, volume=volume, + old_reservations=old_reservations) def manage_existing(self, ctxt, volume, ref): - version = self._compat_ver('2.0', '1.15') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') cctxt.cast(ctxt, 'manage_existing', volume_id=volume['id'], ref=ref) def promote_replica(self, ctxt, volume): - version = self._compat_ver('2.0', '1.17') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') cctxt.cast(ctxt, 'promote_replica', volume_id=volume['id']) def reenable_replication(self, ctxt, volume): - version = self._compat_ver('2.0', '1.17') - cctxt = self._get_cctxt(volume['host'], version) + cctxt = self._get_cctxt(volume['host'], '2.0') cctxt.cast(ctxt, 'reenable_replication', volume_id=volume['id']) def update_migrated_volume(self, ctxt, volume, new_volume, original_volume_status): - version = self._compat_ver('2.0', '1.36') - cctxt = self._get_cctxt(new_volume['host'], version) + cctxt = self._get_cctxt(new_volume['host'], '2.0') cctxt.call(ctxt, 'update_migrated_volume', volume=volume, @@ -370,56 +264,35 @@ class VolumeAPI(rpc.RPCAPI): def freeze_host(self, ctxt, host): """Set backend host to frozen.""" - version = self._compat_ver('2.0', '1.39') - cctxt = self._get_cctxt(host, version) + cctxt = self._get_cctxt(host, '2.0') return cctxt.call(ctxt, 'freeze_host') def thaw_host(self, ctxt, host): """Clear the frozen setting on a backend host.""" - version = self._compat_ver('2.0', '1.39') - cctxt = self._get_cctxt(host, version) + cctxt = self._get_cctxt(host, '2.0') return cctxt.call(ctxt, 'thaw_host') - def failover_host(self, ctxt, host, - secondary_backend_id=None): + def failover_host(self, ctxt, host, secondary_backend_id=None): """Failover host to the specified backend_id (secondary). """ - version = self._compat_ver('2.0', '1.39') - cctxt = self._get_cctxt(host, version) + cctxt = self._get_cctxt(host, '2.0') cctxt.cast(ctxt, 'failover_host', secondary_backend_id=secondary_backend_id) def manage_existing_snapshot(self, ctxt, snapshot, ref, host): - version = self._compat_ver('2.0', '1.28') - cctxt = self._get_cctxt(host, version) + cctxt = self._get_cctxt(host, '2.0') cctxt.cast(ctxt, 'manage_existing_snapshot', snapshot=snapshot, ref=ref) def get_capabilities(self, ctxt, host, discover): - version = self._compat_ver('2.0', '1.29') - cctxt = self._get_cctxt(host, version) + cctxt = self._get_cctxt(host, '2.0') return cctxt.call(ctxt, 'get_capabilities', discover=discover) def get_backup_device(self, ctxt, backup, volume): - if (not self.client.can_send_version('1.38') and - not self.client.can_send_version('2.0')): - msg = _('One of cinder-volume services is too old to accept such ' - 'request. Are you running mixed Liberty-Mitaka ' - 'cinder-volumes?') - raise exception.ServiceTooOld(msg) - version = self._compat_ver('2.0', '1.38') - cctxt = self._get_cctxt(volume.host, version) - return cctxt.call(ctxt, 'get_backup_device', - backup=backup) + cctxt = self._get_cctxt(volume.host, '2.0') + return cctxt.call(ctxt, 'get_backup_device', backup=backup) def secure_file_operations_enabled(self, ctxt, volume): - if (not self.client.can_send_version('1.38') and - not self.client.can_send_version('2.0')): - msg = _('One of cinder-volume services is too old to accept such ' - 'request. Are you running mixed Liberty-Mitaka ' - 'cinder-volumes?') - raise exception.ServiceTooOld(msg) - version = self._compat_ver('2.0', '1.38') - cctxt = self._get_cctxt(volume.host, version) + cctxt = self._get_cctxt(volume.host, '2.0') return cctxt.call(ctxt, 'secure_file_operations_enabled', volume=volume)