diff --git a/nova/tests/unit/virt/test_block_device.py b/nova/tests/unit/virt/test_block_device.py index 06b16a0c427b..032ee9337b0f 100644 --- a/nova/tests/unit/virt/test_block_device.py +++ b/nova/tests/unit/virt/test_block_device.py @@ -903,8 +903,8 @@ class TestDriverBlockDevice(test.NoDBTestCase): self.volume_api.get_snapshot.assert_called_once_with( self.context, 'fake-snapshot-id-1') self.volume_api.create.assert_called_once_with( - self.context, 3, '', '', snapshot, availability_zone=None, - volume_type=None) + self.context, 3, '', '', availability_zone=None, + snapshot=snapshot, volume_type=None) wait_func.assert_called_once_with(self.context, 'fake-volume-id-2') def test_snapshot_attach_no_volume_cinder_cross_az_attach_false(self): @@ -936,8 +936,8 @@ class TestDriverBlockDevice(test.NoDBTestCase): self.volume_api.get_snapshot.assert_called_once_with( self.context, 'fake-snapshot-id-1') self.volume_api.create.assert_called_once_with( - self.context, 3, '', '', snapshot, availability_zone='test-az', - volume_type=None) + self.context, 3, '', '', availability_zone='test-az', + snapshot=snapshot, volume_type=None) wait_func.assert_called_once_with(self.context, 'fake-volume-id-2') def test_snapshot_attach_fail_volume(self): @@ -976,8 +976,8 @@ class TestDriverBlockDevice(test.NoDBTestCase): vol_get_snap.assert_called_once_with( self.context, 'fake-snapshot-id-1') vol_create.assert_called_once_with( - self.context, 3, '', '', snapshot, availability_zone=None, - volume_type=None) + self.context, 3, '', '', availability_zone=None, + snapshot=snapshot, volume_type=None) vol_delete.assert_called_once_with(self.context, volume['id']) def test_snapshot_attach_volume(self): @@ -1486,8 +1486,9 @@ class TestDriverBlockDevice(test.NoDBTestCase): self.virt_driver) vol_create.assert_called_once_with( - self.context, test_bdm.volume_size, '', '', snapshot, - volume_type=expected_volume_type, availability_zone='test-az') + self.context, test_bdm.volume_size, '', '', + availability_zone='test-az', snapshot=snapshot, + volume_type=expected_volume_type) vol_attach.assert_called_once_with( self.context, instance, self.volume_api, self.virt_driver) self.assertEqual('fake-volume-id-2', test_bdm.volume_id) diff --git a/nova/virt/block_device.py b/nova/virt/block_device.py index 608cac0c5c89..4354b1fc4fd8 100644 --- a/nova/virt/block_device.py +++ b/nova/virt/block_device.py @@ -354,6 +354,20 @@ class DriverVolumeBlockDevice(DriverBlockDevice): except exception.CinderAPIVersionNotAvailable: return volume_api.get(context, volume_id) + def _create_volume(self, context, instance, volume_api, size, + wait_func=None, **create_kwargs): + av_zone = _get_volume_create_az_value(instance) + name = create_kwargs.pop('name', '') + description = create_kwargs.pop('description', '') + vol = volume_api.create( + context, size, name, description, volume_type=self.volume_type, + availability_zone=av_zone, **create_kwargs) + + if wait_func: + self._call_wait_func(context, wait_func, volume_api, vol['id']) + + return vol + def _do_detach(self, context, instance, volume_api, virt_driver, attachment_id=None, destroy_bdm=False): """Private method that actually does the detach. @@ -719,14 +733,11 @@ class DriverVolSnapshotBlockDevice(DriverVolumeBlockDevice): virt_driver, wait_func=None): if not self.volume_id: - av_zone = _get_volume_create_az_value(instance) snapshot = volume_api.get_snapshot(context, self.snapshot_id) - vol = volume_api.create(context, self.volume_size, '', '', - snapshot, volume_type=self.volume_type, - availability_zone=av_zone) - if wait_func: - self._call_wait_func(context, wait_func, volume_api, vol['id']) + vol = self._create_volume( + context, instance, volume_api, self.volume_size, + wait_func=wait_func, snapshot=snapshot) self.volume_id = vol['id'] @@ -746,13 +757,9 @@ class DriverVolImageBlockDevice(DriverVolumeBlockDevice): def attach(self, context, instance, volume_api, virt_driver, wait_func=None): if not self.volume_id: - av_zone = _get_volume_create_az_value(instance) - vol = volume_api.create(context, self.volume_size, - '', '', image_id=self.image_id, - volume_type=self.volume_type, - availability_zone=av_zone) - if wait_func: - self._call_wait_func(context, wait_func, volume_api, vol['id']) + vol = self._create_volume( + context, instance, volume_api, self.volume_size, + wait_func=wait_func, image_id=self.image_id) self.volume_id = vol['id'] @@ -772,12 +779,9 @@ class DriverVolBlankBlockDevice(DriverVolumeBlockDevice): virt_driver, wait_func=None): if not self.volume_id: vol_name = instance.uuid + '-blank-vol' - av_zone = _get_volume_create_az_value(instance) - vol = volume_api.create(context, self.volume_size, vol_name, '', - volume_type=self.volume_type, - availability_zone=av_zone) - if wait_func: - self._call_wait_func(context, wait_func, volume_api, vol['id']) + vol = self._create_volume( + context, instance, volume_api, self.volume_size, + wait_func=wait_func, name=vol_name) self.volume_id = vol['id']