VMware: Add volume adapter type extra-spec option
Adding a new volume type extra-spec option 'vmware:adapter_type' to override the default adapter type of volumes. DocImpact The VMDK driver now supports a new extra-spec option 'vmware:adapter_type' to override the default adapter type specified by config option 'vmware_adapter_type'. Change-Id: Ifc641d82e6eecbe12aa0e77242ce8555b7e57b76 Closes-bug: #1691285
This commit is contained in:
parent
fdd49d09a6
commit
8dbf2b7e98
@ -153,8 +153,9 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_disk_type')
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_storage_profile')
|
||||
@mock.patch.object(VMDK_DRIVER, 'ds_sel')
|
||||
def test_verify_volume_creation(self, ds_sel, get_storage_profile,
|
||||
get_disk_type):
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_adapter_type')
|
||||
def test_verify_volume_creation(self, get_adapter_type, ds_sel,
|
||||
get_storage_profile, get_disk_type):
|
||||
profile_name = mock.sentinel.profile_name
|
||||
get_storage_profile.return_value = profile_name
|
||||
|
||||
@ -164,6 +165,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
get_disk_type.assert_called_once_with(volume)
|
||||
get_storage_profile.assert_called_once_with(volume)
|
||||
ds_sel.get_profile_id.assert_called_once_with(profile_name)
|
||||
get_adapter_type.assert_called_once_with(volume)
|
||||
|
||||
@mock.patch.object(VMDK_DRIVER, '_verify_volume_creation')
|
||||
def test_create_volume(self, verify_volume_creation):
|
||||
@ -219,6 +221,33 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
get_extra_spec_disk_type.assert_called_once_with(
|
||||
volume['volume_type_id'])
|
||||
|
||||
@mock.patch('cinder.volume.drivers.vmware.vmdk.'
|
||||
'_get_volume_type_extra_spec')
|
||||
@mock.patch('cinder.volume.drivers.vmware.volumeops.'
|
||||
'VirtualDiskAdapterType.validate')
|
||||
def test_get_extra_spec_adapter_type(
|
||||
self, validate, get_volume_type_extra_spec):
|
||||
adapter_type = mock.sentinel.adapter_type
|
||||
get_volume_type_extra_spec.return_value = adapter_type
|
||||
|
||||
type_id = mock.sentinel.type_id
|
||||
self.assertEqual(adapter_type,
|
||||
self._driver._get_extra_spec_adapter_type(type_id))
|
||||
get_volume_type_extra_spec.assert_called_once_with(
|
||||
type_id, 'adapter_type',
|
||||
default_value=self._driver.configuration.vmware_adapter_type)
|
||||
validate.assert_called_once_with(adapter_type)
|
||||
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_extra_spec_adapter_type')
|
||||
def test_get_adapter_type(self, get_extra_spec_adapter_type):
|
||||
adapter_type = mock.sentinel.adapter_type
|
||||
get_extra_spec_adapter_type.return_value = adapter_type
|
||||
|
||||
volume = self._create_volume_dict()
|
||||
self.assertEqual(adapter_type, self._driver._get_adapter_type(volume))
|
||||
get_extra_spec_adapter_type.assert_called_once_with(
|
||||
volume['volume_type_id'])
|
||||
|
||||
def _create_snapshot_dict(self,
|
||||
volume,
|
||||
snap_id=SNAPSHOT_ID,
|
||||
@ -363,6 +392,8 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
|
||||
@mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
|
||||
'_validate_disk_format')
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_adapter_type',
|
||||
return_value=volumeops.VirtualDiskAdapterType.BUS_LOGIC)
|
||||
@mock.patch('cinder.volume.drivers.vmware.volumeops.'
|
||||
'VirtualDiskAdapterType.validate')
|
||||
@mock.patch('cinder.volume.drivers.vmware.vmdk.ImageDiskType.'
|
||||
@ -380,6 +411,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
create_volume_from_non_stream_opt_image,
|
||||
validate_image_disk_type,
|
||||
validate_image_adapter_type,
|
||||
get_adapter_type,
|
||||
validate_disk_format,
|
||||
vmware_disk_type='streamOptimized',
|
||||
backing_disk_size=VOL_SIZE,
|
||||
@ -1978,9 +2010,10 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_storage_profile_id')
|
||||
@mock.patch.object(VMDK_DRIVER, 'volumeops')
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_disk_type')
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_adapter_type')
|
||||
def _test_create_backing(
|
||||
self, get_disk_type, vops, get_storage_profile_id,
|
||||
select_ds_for_volume, create_params=None):
|
||||
self, get_adapter_type, get_disk_type, vops,
|
||||
get_storage_profile_id, select_ds_for_volume, create_params=None):
|
||||
create_params = create_params or {}
|
||||
|
||||
host = mock.sentinel.host
|
||||
@ -2000,6 +2033,9 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
disk_type = mock.sentinel.disk_type
|
||||
get_disk_type.return_value = disk_type
|
||||
|
||||
adapter_type = mock.sentinel.adapter_type
|
||||
get_adapter_type.return_value = adapter_type
|
||||
|
||||
volume = self._create_volume_dict()
|
||||
ret = self._driver._create_backing(volume, host, create_params)
|
||||
|
||||
@ -2021,12 +2057,13 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
vops.update_backing_disk_uuid.assert_not_called()
|
||||
else:
|
||||
get_disk_type.assert_called_once_with(volume)
|
||||
get_adapter_type.assert_called_once_with(volume)
|
||||
exp_backing_name = (
|
||||
create_params.get(vmdk.CREATE_PARAM_BACKING_NAME) or
|
||||
volume['name'])
|
||||
exp_adapter_type = (
|
||||
create_params.get(vmdk.CREATE_PARAM_ADAPTER_TYPE) or
|
||||
self._driver.configuration.vmware_adapter_type)
|
||||
adapter_type)
|
||||
vops.create_backing.assert_called_once_with(
|
||||
exp_backing_name,
|
||||
volume['size'] * units.Mi,
|
||||
@ -2355,8 +2392,9 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_storage_profile_id')
|
||||
@mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
|
||||
'_get_disk_type')
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_adapter_type')
|
||||
def test_manage_existing(
|
||||
self, get_disk_type, get_storage_profile_id,
|
||||
self, get_adapter_type, get_disk_type, get_storage_profile_id,
|
||||
get_ds_name_folder_path, vops, create_backing, get_existing):
|
||||
|
||||
vm = mock.sentinel.vm
|
||||
@ -2383,6 +2421,9 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
disk_type = mock.sentinel.disk_type
|
||||
get_disk_type.return_value = disk_type
|
||||
|
||||
adapter_type = mock.sentinel.adapter_type
|
||||
get_adapter_type.return_value = adapter_type
|
||||
|
||||
existing_ref = mock.sentinel.existing_ref
|
||||
self._driver.manage_existing(volume, existing_ref)
|
||||
|
||||
@ -2394,10 +2435,10 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
vops.move_vmdk_file.assert_called_once_with(
|
||||
src_dc, src_path, dest_path, dest_dc_ref=dest_dc)
|
||||
get_storage_profile_id.assert_called_once_with(volume)
|
||||
get_adapter_type.assert_called_once_with(volume)
|
||||
vops.attach_disk_to_backing.assert_called_once_with(
|
||||
backing, disk_device.capacityInKB, disk_type,
|
||||
self._driver.configuration.vmware_adapter_type,
|
||||
profile_id, dest_path)
|
||||
adapter_type, profile_id, dest_path)
|
||||
vops.update_backing_disk_uuid.assert_called_once_with(backing,
|
||||
volume['id'])
|
||||
|
||||
|
@ -319,8 +319,11 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
||||
if profile_name:
|
||||
self.ds_sel.get_profile_id(profile_name)
|
||||
|
||||
LOG.debug("Verified disk type and storage profile of volume: %s.",
|
||||
volume.name)
|
||||
# validate adapter type
|
||||
self._get_adapter_type(volume)
|
||||
|
||||
LOG.debug("Verified disk type, adapter type and storage profile "
|
||||
"of volume: %s.", volume.name)
|
||||
|
||||
def create_volume(self, volume):
|
||||
"""Creates a volume.
|
||||
@ -351,6 +354,17 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
||||
"""
|
||||
self._delete_volume(volume)
|
||||
|
||||
def _get_extra_spec_adapter_type(self, type_id):
|
||||
adapter_type = _get_volume_type_extra_spec(
|
||||
type_id,
|
||||
'adapter_type',
|
||||
default_value=self.configuration.vmware_adapter_type)
|
||||
volumeops.VirtualDiskAdapterType.validate(adapter_type)
|
||||
return adapter_type
|
||||
|
||||
def _get_adapter_type(self, volume):
|
||||
return self._get_extra_spec_adapter_type(volume['volume_type_id'])
|
||||
|
||||
def _get_extra_spec_storage_profile(self, type_id):
|
||||
"""Get storage profile name in the given volume type's extra spec.
|
||||
|
||||
@ -446,8 +460,8 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
||||
# create a backing with single disk
|
||||
disk_type = VMwareVcVmdkDriver._get_disk_type(volume)
|
||||
size_kb = volume['size'] * units.Mi
|
||||
adapter_type = create_params.get(
|
||||
CREATE_PARAM_ADAPTER_TYPE, self.configuration.vmware_adapter_type)
|
||||
adapter_type = create_params.get(CREATE_PARAM_ADAPTER_TYPE,
|
||||
self._get_adapter_type(volume))
|
||||
backing = self.volumeops.create_backing(backing_name,
|
||||
size_kb,
|
||||
disk_type,
|
||||
@ -1159,7 +1173,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
||||
|
||||
# Get the disk type, adapter type and size of vmdk image
|
||||
image_disk_type = ImageDiskType.PREALLOCATED
|
||||
image_adapter_type = self.configuration.vmware_adapter_type
|
||||
image_adapter_type = self._get_adapter_type(volume)
|
||||
image_size_in_bytes = metadata['size']
|
||||
properties = metadata['properties']
|
||||
if properties:
|
||||
@ -1568,7 +1582,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
||||
backing,
|
||||
disk.capacityInKB,
|
||||
VMwareVcVmdkDriver._get_disk_type(volume),
|
||||
self.configuration.vmware_adapter_type,
|
||||
self._get_adapter_type(volume),
|
||||
profile_id,
|
||||
dest_path.get_descriptor_ds_file_path())
|
||||
self.volumeops.update_backing_disk_uuid(backing, volume['id'])
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
VMware VMDK driver now supports volume type extra-spec
|
||||
option ``vmware:adapter_type`` to specify the adapter
|
||||
type of volumes in vCenter server.
|
Loading…
Reference in New Issue
Block a user