Merge "VMware: Apply policy at vmdk level during retype"
This commit is contained in:
commit
8425b714cf
@ -1201,49 +1201,61 @@ class VolumeOpsTestCase(test.TestCase):
|
|||||||
self.assertEqual(mock.sentinel.uuid, reconfig_spec.instanceUuid)
|
self.assertEqual(mock.sentinel.uuid, reconfig_spec.instanceUuid)
|
||||||
reconfigure_backing.assert_called_once_with(backing, reconfig_spec)
|
reconfigure_backing.assert_called_once_with(backing, reconfig_spec)
|
||||||
|
|
||||||
def test_change_backing_profile(self):
|
@mock.patch('cinder.volume.drivers.vmware.volumeops.VMwareVolumeOps.'
|
||||||
# Test change to empty profile.
|
'_get_disk_device')
|
||||||
|
@mock.patch('cinder.volume.drivers.vmware.volumeops.VMwareVolumeOps.'
|
||||||
|
'_reconfigure_backing')
|
||||||
|
def test_change_backing_profile_to_empty_profile(
|
||||||
|
self, reconfigure_backing, get_disk_device):
|
||||||
reconfig_spec = mock.Mock()
|
reconfig_spec = mock.Mock()
|
||||||
empty_profile_spec = mock.sentinel.empty_profile_spec
|
empty_profile_spec = mock.sentinel.empty_profile_spec
|
||||||
|
disk_spec = mock.Mock()
|
||||||
self.session.vim.client.factory.create.side_effect = [
|
self.session.vim.client.factory.create.side_effect = [
|
||||||
reconfig_spec, empty_profile_spec]
|
empty_profile_spec, reconfig_spec, disk_spec]
|
||||||
|
|
||||||
task = mock.sentinel.task
|
disk_device = mock.sentinel.disk_device
|
||||||
self.session.invoke_api.return_value = task
|
get_disk_device.return_value = disk_device
|
||||||
|
|
||||||
backing = mock.sentinel.backing
|
backing = mock.sentinel.backing
|
||||||
unique_profile_id = mock.sentinel.unique_profile_id
|
self.vops.change_backing_profile(backing, None)
|
||||||
profile_id = mock.Mock(uniqueId=unique_profile_id)
|
|
||||||
self.vops.change_backing_profile(backing, profile_id)
|
|
||||||
|
|
||||||
|
self.assertEqual('profile', empty_profile_spec.dynamicType)
|
||||||
self.assertEqual([empty_profile_spec], reconfig_spec.vmProfile)
|
self.assertEqual([empty_profile_spec], reconfig_spec.vmProfile)
|
||||||
self.session.invoke_api.assert_called_once_with(self.session.vim,
|
get_disk_device.assert_called_once_with(backing)
|
||||||
"ReconfigVM_Task",
|
self.assertEqual(disk_device, disk_spec.device)
|
||||||
backing,
|
self.assertEqual('edit', disk_spec.operation)
|
||||||
spec=reconfig_spec)
|
self.assertEqual([empty_profile_spec], disk_spec.profile)
|
||||||
self.session.wait_for_task.assert_called_once_with(task)
|
self.assertEqual([disk_spec], reconfig_spec.deviceChange)
|
||||||
|
reconfigure_backing.assert_called_once_with(backing, reconfig_spec)
|
||||||
|
|
||||||
# Test change to non-empty profile.
|
@mock.patch('cinder.volume.drivers.vmware.volumeops.VMwareVolumeOps.'
|
||||||
|
'_get_disk_device')
|
||||||
|
@mock.patch('cinder.volume.drivers.vmware.volumeops.VMwareVolumeOps.'
|
||||||
|
'_reconfigure_backing')
|
||||||
|
def test_change_backing_profile(
|
||||||
|
self, reconfigure_backing, get_disk_device):
|
||||||
|
reconfig_spec = mock.Mock()
|
||||||
profile_spec = mock.Mock()
|
profile_spec = mock.Mock()
|
||||||
|
disk_spec = mock.Mock()
|
||||||
self.session.vim.client.factory.create.side_effect = [
|
self.session.vim.client.factory.create.side_effect = [
|
||||||
reconfig_spec, profile_spec]
|
profile_spec, reconfig_spec, disk_spec]
|
||||||
|
|
||||||
self.session.invoke_api.reset_mock()
|
disk_device = mock.sentinel.disk_device
|
||||||
self.session.wait_for_task.reset_mock()
|
get_disk_device.return_value = disk_device
|
||||||
|
|
||||||
|
backing = mock.sentinel.backing
|
||||||
|
unique_id = mock.sentinel.unique_id
|
||||||
|
profile_id = mock.Mock(uniqueId=unique_id)
|
||||||
self.vops.change_backing_profile(backing, profile_id)
|
self.vops.change_backing_profile(backing, profile_id)
|
||||||
|
|
||||||
|
self.assertEqual(unique_id, profile_spec.profileId)
|
||||||
self.assertEqual([profile_spec], reconfig_spec.vmProfile)
|
self.assertEqual([profile_spec], reconfig_spec.vmProfile)
|
||||||
self.assertEqual(unique_profile_id,
|
get_disk_device.assert_called_once_with(backing)
|
||||||
reconfig_spec.vmProfile[0].profileId)
|
self.assertEqual(disk_device, disk_spec.device)
|
||||||
self.session.invoke_api.assert_called_once_with(self.session.vim,
|
self.assertEqual('edit', disk_spec.operation)
|
||||||
"ReconfigVM_Task",
|
self.assertEqual([profile_spec], disk_spec.profile)
|
||||||
backing,
|
self.assertEqual([disk_spec], reconfig_spec.deviceChange)
|
||||||
spec=reconfig_spec)
|
reconfigure_backing.assert_called_once_with(backing, reconfig_spec)
|
||||||
self.session.wait_for_task.assert_called_once_with(task)
|
|
||||||
|
|
||||||
# Clear side effects.
|
|
||||||
self.session.vim.client.factory.create.side_effect = None
|
|
||||||
|
|
||||||
def test_delete_file(self):
|
def test_delete_file(self):
|
||||||
file_mgr = mock.sentinel.file_manager
|
file_mgr = mock.sentinel.file_manager
|
||||||
|
@ -1217,7 +1217,6 @@ class VMwareVolumeOps(object):
|
|||||||
{'backing': backing,
|
{'backing': backing,
|
||||||
'profile': profile_id})
|
'profile': profile_id})
|
||||||
cf = self._session.vim.client.factory
|
cf = self._session.vim.client.factory
|
||||||
reconfig_spec = cf.create('ns0:VirtualMachineConfigSpec')
|
|
||||||
|
|
||||||
if profile_id is None:
|
if profile_id is None:
|
||||||
vm_profile = cf.create('ns0:VirtualMachineEmptyProfileSpec')
|
vm_profile = cf.create('ns0:VirtualMachineEmptyProfileSpec')
|
||||||
@ -1226,7 +1225,16 @@ class VMwareVolumeOps(object):
|
|||||||
vm_profile = cf.create('ns0:VirtualMachineDefinedProfileSpec')
|
vm_profile = cf.create('ns0:VirtualMachineDefinedProfileSpec')
|
||||||
vm_profile.profileId = profile_id.uniqueId
|
vm_profile.profileId = profile_id.uniqueId
|
||||||
|
|
||||||
|
reconfig_spec = cf.create('ns0:VirtualMachineConfigSpec')
|
||||||
reconfig_spec.vmProfile = [vm_profile]
|
reconfig_spec.vmProfile = [vm_profile]
|
||||||
|
|
||||||
|
disk_device = self._get_disk_device(backing)
|
||||||
|
disk_spec = cf.create('ns0:VirtualDeviceConfigSpec')
|
||||||
|
disk_spec.device = disk_device
|
||||||
|
disk_spec.operation = 'edit'
|
||||||
|
disk_spec.profile = [vm_profile]
|
||||||
|
reconfig_spec.deviceChange = [disk_spec]
|
||||||
|
|
||||||
self._reconfigure_backing(backing, reconfig_spec)
|
self._reconfigure_backing(backing, reconfig_spec)
|
||||||
LOG.debug("Backing VM: %(backing)s reconfigured with new profile: "
|
LOG.debug("Backing VM: %(backing)s reconfigured with new profile: "
|
||||||
"%(profile)s.",
|
"%(profile)s.",
|
||||||
|
Loading…
Reference in New Issue
Block a user