Merge "VMware: Fix re-attach volume error for VC 5.1"

This commit is contained in:
Jenkins 2015-09-08 20:06:58 +00:00 committed by Gerrit Code Review
commit bcc7ce05cb
2 changed files with 46 additions and 5 deletions

View File

@ -2760,6 +2760,7 @@ class VMwareVcVmdkDriverTestCase(VMwareEsxVmdkDriverTestCase):
@mock.patch.object(VMDK_DRIVER, 'volumeops')
@mock.patch.object(VMDK_DRIVER, 'ds_sel')
def test_relocate_backing_nop(self, ds_sel, vops):
self._driver._storage_policy_enabled = True
volume = {'name': 'vol-1', 'size': 1}
datastore = mock.sentinel.datastore
@ -2784,6 +2785,7 @@ class VMwareVcVmdkDriverTestCase(VMwareEsxVmdkDriverTestCase):
@mock.patch.object(VMDK_DRIVER, 'ds_sel')
def test_relocate_backing_with_no_datastore(
self, ds_sel, vops):
self._driver._storage_policy_enabled = True
volume = {'name': 'vol-1', 'size': 1}
profile = mock.sentinel.profile
@ -2838,6 +2840,40 @@ class VMwareVcVmdkDriverTestCase(VMwareEsxVmdkDriverTestCase):
vops.move_backing_to_folder.assert_called_once_with(backing,
folder)
@mock.patch.object(VMDK_DRIVER, 'volumeops')
@mock.patch.object(VMDK_DRIVER, '_get_volume_group_folder')
@mock.patch.object(VMDK_DRIVER, 'ds_sel')
def test_relocate_backing_with_pbm_disabled(
self, ds_sel, get_volume_group_folder, vops):
self._driver._storage_policy_enabled = False
volume = {'name': 'vol-1', 'size': 1, 'project_id': 'abc'}
vops.is_datastore_accessible.return_value = False
backing = mock.sentinel.backing
host = mock.sentinel.host
rp = mock.sentinel.rp
datastore = mock.sentinel.datastore
summary = mock.Mock(datastore=datastore)
ds_sel.select_datastore.return_value = (host, rp, summary)
folder = mock.sentinel.folder
get_volume_group_folder.return_value = folder
self._driver._relocate_backing(volume, backing, host)
self.assertFalse(vops.get_profile.called)
vops.relocate_backing.assert_called_once_with(backing,
datastore,
rp,
host)
vops.move_backing_to_folder.assert_called_once_with(backing,
folder)
ds_sel.select_datastore.assert_called_once_with(
{hub.DatastoreSelector.SIZE_BYTES: volume['size'] * units.Gi,
hub.DatastoreSelector.PROFILE_NAME: None}, hosts=[host])
@mock.patch('oslo_vmware.api.VMwareAPISession')
def test_session(self, apiSession):
self._session = None

View File

@ -1948,17 +1948,22 @@ class VMwareVcVmdkDriver(VMwareEsxVmdkDriver):
# Check if the current datastore is visible to the host managing
# the instance and compliant with the storage profile.
datastore = self.volumeops.get_datastore(backing)
backing_profile = self.volumeops.get_profile(backing)
backing_profile = None
if self._storage_policy_enabled:
backing_profile = self.volumeops.get_profile(backing)
if (self.volumeops.is_datastore_accessible(datastore, host) and
self.ds_sel.is_datastore_compliant(datastore,
backing_profile)):
LOG.debug("Datastore: %(datastore)s of backing: %(backing)s is "
"already accessible to instance's host: %(host)s and "
"compliant with storage profile: %(profile)s.",
"already accessible to instance's host: %(host)s.",
{'backing': backing,
'datastore': datastore,
'host': host,
'profile': backing_profile})
'host': host})
if backing_profile:
LOG.debug("Backing: %(backing)s is compliant with "
"storage profile: %(profile)s.",
{'backing': backing,
'profile': backing_profile})
return
# We need to relocate the backing to an accessible and profile