create_disk_from_sparse_image.return_value = path
create_disk_from_preallocated_image.return_value = path
+ clone = mock.sentinel.clone
+ vops.clone_backing.return_value = clone
+
volume_size = 2
vops.get_disk_size.return_value = volume_size * units.Gi
volume['name'], backing, None, volumeops.FULL_CLONE_TYPE,
summary.datastore, disk_type, mock.sentinel.host, mock.sentinel.rp)
vops.delete_backing.assert_called_once_with(backing)
+ vops.update_backing_disk_uuid.assert_called_once_with(clone,
+ volume['id'])
self.assertFalse(extend_disk.called)
vops.get_disk_size.return_value = 1 * units.Gi
create_backing.reset_mock()
vops.attach_disk_to_backing.reset_mock()
vops.delete_backing.reset_mock()
+ vops.update_backing_disk_uuid.reset_mock()
image_meta['properties']['vmware_disktype'] = 'preallocated'
self._driver.copy_image_to_volume(
vops.attach_disk_to_backing.assert_called_once_with(
backing, image_size_in_bytes / units.Ki, disk_type,
adapter_type, path.get_descriptor_ds_file_path())
+ vops.update_backing_disk_uuid.assert_called_once_with(backing,
+ volume['id'])
extend_disk.assert_called_once_with(volume['name'], volume['size'])
extend_disk.reset_mock()
volumeops.get_disk_size.return_value = size
+ backing = mock.sentinel.backing
+ download_image.return_value = backing
+
self._driver.copy_image_to_volume(fake_context, fake_volume,
image_service, fake_image_id)
vm_folder=fake_folder,
vm_import_spec=vm_import_spec,
image_size=size)
+ volumeops.update_backing_disk_uuid.assert_called_once_with(
+ backing, fake_volume['id'])
_extend_virtual_disk.assert_called_once_with(fake_volume['name'],
fake_volume_size)
# Test with in-use volume.
vol = {'size': 1, 'status': 'retyping', 'name': 'vol-1',
+ 'id': 'd11a82de-ddaa-448d-b50a-a255a7e61a1e',
'volume_type_id': 'def'}
vol['volume_attachment'] = [mock.sentinel.volume_attachment]
self.assertFalse(self._driver.retype(context, vol, new_type, diff,
vops.clone_backing.assert_called_once_with(
vol['name'], backing, None, volumeops.FULL_CLONE_TYPE,
datastore, vmdk.THIN_VMDK_TYPE, host, rp)
+ vops.update_backing_disk_uuid.assert_called_once_with(clone, vol['id'])
delete_temp_backing.assert_called_once_with(backing)
vops.change_backing_profile.assert_called_once_with(clone,
profile_id)
vops.clone_backing.side_effect = exceptions.VimException('error')
+ vops.update_backing_disk_uuid.reset_mock()
vops.rename_backing.reset_mock()
vops.change_backing_profile.reset_mock()
self.assertRaises(
exceptions.VimException, self._driver.retype, context, vol,
new_type, diff, host)
+ self.assertFalse(vops.update_backing_disk_uuid.called)
exp_rename_calls = [mock.call(backing, uuid),
mock.call(backing, vol['name'])]
self.assertEqual(exp_rename_calls, vops.rename_backing.call_args_list)
disk_type = vmdk.THIN_VMDK_TYPE
get_disk_type.return_value = disk_type
+ dest = mock.sentinel.dest
+ vops.clone_backing.return_value = dest
+
context = mock.sentinel.context
- volume = {'name': 'vol-1', 'id': 1, 'size': 1}
+ volume = {'name': 'vol-1',
+ 'id': 'bd45dfe5-d411-435d-85ac-2605fe7d5d8f', 'size': 1}
backing = None
tmp_file_path = mock.sentinel.tmp_file_path
backup_size = units.Gi
vops.clone_backing.assert_called_once_with(
volume['name'], src, None, volumeops.FULL_CLONE_TYPE,
summary.datastore, disk_type, mock.sentinel.host, mock.sentinel.rp)
+ vops.update_backing_disk_uuid.assert_called_once_with(dest,
+ volume['id'])
delete_temp_backing.assert_called_once_with(src)
create_backing.reset_mock()
vops.clone_backing.reset_mock()
+ vops.update_backing_disk_uuid.reset_mock()
delete_temp_backing.reset_mock()
dest_uuid = "de4b0708-f947-4abe-98f8-75e52ce03b7b"
tmp_uuid = "82c2a4f0-9064-4d95-bd88-6567a36018fa"
generate_uuid.side_effect = [src_uuid, dest_uuid, tmp_uuid]
- dest = mock.sentinel.dest
- vops.clone_backing.return_value = dest
-
backing = mock.sentinel.backing
self._driver._restore_backing(
context, volume, backing, tmp_file_path, backup_size)
vops.clone_backing.assert_called_once_with(
dest_uuid, src, None, volumeops.FULL_CLONE_TYPE,
summary.datastore, disk_type, mock.sentinel.host, mock.sentinel.rp)
+ vops.update_backing_disk_uuid.assert_called_once_with(dest,
+ volume['id'])
exp_rename_calls = [mock.call(backing, tmp_uuid),
mock.call(dest, volume['name'])]
self.assertEqual(exp_rename_calls, vops.rename_backing.call_args_list)
@mock.patch.object(VMDK_DRIVER, 'volumeops')
def test_clone_backing_linked(self, volume_ops, _extend_vmdk_virtual_disk):
"""Test _clone_backing with clone type - linked."""
+ clone = mock.sentinel.clone
+ volume_ops.clone_backing.return_value = clone
+
fake_size = 3
fake_volume = {'volume_type_id': None, 'name': 'fake_name',
'id': '51e47214-8e3c-475d-b44b-aea6cd3eef53',
self._driver._clone_backing(fake_volume, fake_backing, fake_snapshot,
volumeops.LINKED_CLONE_TYPE,
fake_snapshot['volume_size'])
+
extra_config = {vmdk.EXTRA_CONFIG_VOLUME_ID_KEY: fake_volume['id']}
volume_ops.clone_backing.assert_called_with(fake_volume['name'],
fake_backing,
host=None,
resource_pool=None,
extra_config=extra_config)
+ volume_ops.update_backing_disk_uuid.assert_called_once_with(
+ clone, fake_volume['id'])
+
# If the volume size is greater than the original snapshot size,
# _extend_vmdk_virtual_disk will be called.
_extend_vmdk_virtual_disk.assert_called_with(fake_volume['name'],
_extend_vmdk_virtual_disk):
"""Test _clone_backing with clone type - full."""
fake_host = mock.sentinel.host
- fake_backing = mock.sentinel.backing
fake_folder = mock.sentinel.folder
fake_datastore = mock.sentinel.datastore
fake_resource_pool = mock.sentinel.resourcePool
fake_summary = mock.Mock(spec=object)
fake_summary.datastore = fake_datastore
fake_size = 3
+ _select_ds_for_volume.return_value = (fake_host,
+ fake_resource_pool,
+ fake_folder, fake_summary)
+
+ clone = mock.sentinel.clone
+ volume_ops.clone_backing.return_value = clone
+
+ fake_backing = mock.sentinel.backing
fake_volume = {'volume_type_id': None, 'name': 'fake_name',
'id': '51e47214-8e3c-475d-b44b-aea6cd3eef53',
'size': fake_size}
fake_snapshot = {'volume_name': 'volume_name', 'name': 'snapshot_name',
'volume_size': 2}
- _select_ds_for_volume.return_value = (fake_host,
- fake_resource_pool,
- fake_folder, fake_summary)
self._driver._clone_backing(fake_volume, fake_backing, fake_snapshot,
volumeops.FULL_CLONE_TYPE,
fake_snapshot['volume_size'])
+
_select_ds_for_volume.assert_called_with(fake_volume)
extra_config = {vmdk.EXTRA_CONFIG_VOLUME_ID_KEY: fake_volume['id']}
volume_ops.clone_backing.assert_called_with(fake_volume['name'],
resource_pool=
fake_resource_pool,
extra_config=extra_config)
+ volume_ops.update_backing_disk_uuid.assert_called_once_with(
+ clone, fake_volume['id'])
+
# If the volume size is greater than the original snapshot size,
# _extend_vmdk_virtual_disk will be called.
_extend_vmdk_virtual_disk.assert_called_with(fake_volume['name'],
summary = mock.sentinel.summary
select_ds_for_volume.return_value = (host, resource_pool, folder,
summary)
+ backing = mock.sentinel.backing
+ vops.create_backing_disk_less.return_value = backing
volume = {'name': 'vol-1', 'volume_type_id': None, 'size': 1,
'id': 'd11a82de-ddaa-448d-b50a-a255a7e61a1e'}
create_params = {vmdk.CREATE_PARAM_DISK_LESS: True}
- self._driver._create_backing(volume, host, create_params)
+ ret = self._driver._create_backing(volume, host, create_params)
+ self.assertEqual(backing, ret)
extra_config = {vmdk.EXTRA_CONFIG_VOLUME_ID_KEY: volume['id']}
vops.create_backing_disk_less.assert_called_once_with(
'vol-1',
summary.name,
profileId=None,
extra_config=extra_config)
+ self.assertFalse(vops.update_backing_disk_uuid.called)
+ vops.create_backing.return_value = backing
create_params = {vmdk.CREATE_PARAM_ADAPTER_TYPE: 'ide'}
- self._driver._create_backing(volume, host, create_params)
+ ret = self._driver._create_backing(volume, host, create_params)
+ self.assertEqual(backing, ret)
vops.create_backing.assert_called_once_with('vol-1',
units.Mi,
vmdk.THIN_VMDK_TYPE,
profileId=None,
adapter_type='ide',
extra_config=extra_config)
+ vops.update_backing_disk_uuid.assert_called_once_with(backing,
+ volume['id'])
vops.create_backing.reset_mock()
+ vops.update_backing_disk_uuid.reset_mock()
backing_name = "temp-vol"
create_params = {vmdk.CREATE_PARAM_BACKING_NAME: backing_name}
- self._driver._create_backing(volume, host, create_params)
+ ret = self._driver._create_backing(volume, host, create_params)
+ self.assertEqual(backing, ret)
vops.create_backing.assert_called_once_with(backing_name,
units.Mi,
vmdk.THIN_VMDK_TYPE,
profileId=None,
adapter_type='lsiLogic',
extra_config=extra_config)
+ vops.update_backing_disk_uuid.assert_called_once_with(backing,
+ volume['id'])
@mock.patch('cinder.openstack.common.fileutils.ensure_tree')
@mock.patch('cinder.openstack.common.fileutils.delete_if_exists')
size_kb = volume['size'] * units.Mi
adapter_type = create_params.get(CREATE_PARAM_ADAPTER_TYPE,
'lsiLogic')
- return self.volumeops.create_backing(backing_name,
- size_kb,
- disk_type,
- folder,
- resource_pool,
- host_ref,
- summary.name,
- profileId=profile_id,
- adapter_type=adapter_type,
- extra_config=extra_config)
+ backing = self.volumeops.create_backing(backing_name,
+ size_kb,
+ disk_type,
+ folder,
+ resource_pool,
+ host_ref,
+ summary.name,
+ profileId=profile_id,
+ adapter_type=adapter_type,
+ extra_config=extra_config)
+
+ self.volumeops.update_backing_disk_uuid(backing, volume['id'])
+ return backing
def _relocate_backing(self, volume, backing, host):
pass
datastore = summary.datastore
LOG.debug("Cloning temporary backing: %s for disk type "
"conversion.", backing)
- self.volumeops.clone_backing(volume['name'],
- backing,
- None,
- volumeops.FULL_CLONE_TYPE,
- datastore,
- disk_type,
- host,
- rp)
+ clone = self.volumeops.clone_backing(volume['name'],
+ backing,
+ None,
+ volumeops.FULL_CLONE_TYPE,
+ datastore,
+ disk_type,
+ host,
+ rp)
self._delete_temp_backing(backing)
+ backing = clone
+ self.volumeops.update_backing_disk_uuid(backing, volume['id'])
except Exception:
# Delete backing and virtual disk created from image.
with excutils.save_and_reraise_exception():
host_ip = self.configuration.vmware_host_ip
LOG.debug("Fetching glance image: %(id)s to server: %(host)s.",
{'id': image_id, 'host': host_ip})
- image_transfer.download_stream_optimized_image(
+ backing = image_transfer.download_stream_optimized_image(
context,
timeout,
image_service,
vm_folder=folder,
vm_import_spec=vm_import_spec,
image_size=image_size)
+ self.volumeops.update_backing_disk_uuid(backing, volume['id'])
except (exceptions.VimException,
exceptions.VMwareDriverException):
with excutils.save_and_reraise_exception():
volume['name'], backing, None,
volumeops.FULL_CLONE_TYPE, datastore, new_disk_type,
host, rp)
+ self.volumeops.update_backing_disk_uuid(new_backing,
+ volume['id'])
self._delete_temp_backing(backing)
backing = new_backing
except exceptions.VimException:
dest = self.volumeops.clone_backing(dest_name, src, None,
volumeops.FULL_CLONE_TYPE,
datastore, disk_type, host, rp)
+ self.volumeops.update_backing_disk_uuid(dest, volume['id'])
if new_backing:
LOG.debug("Created new backing: %s for restoring backup.",
dest_name)
snapshot, clone_type, datastore,
host=host, resource_pool=rp,
extra_config=extra_config)
+ self.volumeops.update_backing_disk_uuid(clone, volume['id'])
# If the volume size specified by the user is greater than
# the size of the source volume, the newly created volume will
# allocate the capacity to the size of the source volume in the backend