VMware: Use storage profile name in extra-spec

Currently we query vCenter for the storage profile name associated
with the volume. We should use the volume type extra-spec 'vmware:
storage_profile' as the source of truth because vCenter may associate
a default storage profile with the volume even if we do not specify
a storage profile (based on the value of vmware:storage_profile)
during volume creation.

Change-Id: Ib9f553a69262234e5329d79d20ef8a997758a89f
Closes-bug: #1660644
This commit is contained in:
Vipin Balachandran 2017-01-31 20:19:35 +05:30
parent 25a37650c6
commit f1267fe3c3
4 changed files with 9 additions and 46 deletions

View File

@ -2512,8 +2512,9 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
self.assertFalse(ds_sel.called)
@mock.patch.object(VMDK_DRIVER, 'volumeops')
@mock.patch.object(VMDK_DRIVER, '_get_storage_profile')
@mock.patch.object(VMDK_DRIVER, 'ds_sel')
def test_relocate_backing_nop(self, ds_sel, vops):
def test_relocate_backing_nop(self, ds_sel, get_profile, vops):
self._driver._storage_policy_enabled = True
volume = {'name': 'vol-1', 'size': 1}
@ -2521,7 +2522,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
vops.get_datastore.return_value = datastore
profile = mock.sentinel.profile
vops.get_profile.return_value = profile
get_profile.return_value = profile
vops.is_datastore_accessible.return_value = True
ds_sel.is_datastore_compliant.return_value = True
@ -2530,20 +2531,22 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
host = mock.sentinel.host
self._driver._relocate_backing(volume, backing, host)
get_profile.assert_called_once_with(volume)
vops.is_datastore_accessible.assert_called_once_with(datastore, host)
ds_sel.is_datastore_compliant.assert_called_once_with(datastore,
profile)
self.assertFalse(vops.relocate_backing.called)
@mock.patch.object(VMDK_DRIVER, 'volumeops')
@mock.patch.object(VMDK_DRIVER, '_get_storage_profile')
@mock.patch.object(VMDK_DRIVER, 'ds_sel')
def test_relocate_backing_with_no_datastore(
self, ds_sel, vops):
self, ds_sel, get_profile, vops):
self._driver._storage_policy_enabled = True
volume = {'name': 'vol-1', 'size': 1}
profile = mock.sentinel.profile
vops.get_profile.return_value = profile
get_profile.return_value = profile
vops.is_datastore_accessible.return_value = True
ds_sel.is_datastore_compliant.return_value = False
@ -2558,6 +2561,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
volume,
backing,
host)
get_profile.assert_called_once_with(volume)
ds_sel.select_datastore.assert_called_once_with(
{hub.DatastoreSelector.SIZE_BYTES: volume['size'] * units.Gi,
hub.DatastoreSelector.PROFILE_NAME: profile}, hosts=[host])

View File

@ -1525,36 +1525,6 @@ class VolumeOpsTestCase(test.TestCase):
datacenter=dc_ref)
self.session.wait_for_task.assert_called_once_with(task)
@mock.patch('oslo_vmware.pbm.get_profiles_by_ids')
@mock.patch('oslo_vmware.pbm.get_profiles')
def test_get_profile(self, get_profiles, get_profiles_by_ids):
profile_ids = [mock.sentinel.profile_id]
get_profiles.return_value = profile_ids
profile_name = mock.sentinel.profile_name
profile = mock.Mock()
profile.name = profile_name
get_profiles_by_ids.return_value = [profile]
backing = mock.sentinel.backing
self.assertEqual(profile_name, self.vops.get_profile(backing))
get_profiles.assert_called_once_with(self.session, backing)
get_profiles_by_ids.assert_called_once_with(self.session, profile_ids)
@mock.patch('oslo_vmware.pbm.get_profiles_by_ids')
@mock.patch('oslo_vmware.pbm.get_profiles')
def test_get_profile_with_no_profile(self, get_profiles,
get_profiles_by_ids):
get_profiles.return_value = []
backing = mock.sentinel.backing
self.assertIsNone(self.vops.get_profile(backing))
get_profiles.assert_called_once_with(self.session, backing)
self.assertFalse(get_profiles_by_ids.called)
def test_extend_virtual_disk(self):
"""Test volumeops.extend_virtual_disk."""
task = mock.sentinel.task

View File

@ -1951,7 +1951,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
datastore = self.volumeops.get_datastore(backing)
backing_profile = None
if self._storage_policy_enabled:
backing_profile = self.volumeops.get_profile(backing)
backing_profile = self._get_storage_profile(volume)
if (self.volumeops.is_datastore_accessible(datastore, host) and
self.ds_sel.is_datastore_compliant(datastore,
backing_profile)):

View File

@ -21,7 +21,6 @@ Implements operations on volumes residing on VMware datastores.
from oslo_log import log as logging
from oslo_utils import units
from oslo_vmware import exceptions
from oslo_vmware import pbm
from oslo_vmware import vim_util
from six.moves import urllib
@ -1521,16 +1520,6 @@ class VMwareVolumeOps(object):
self._session.wait_for_task(task)
LOG.info(_LI("Deleted vmdk file: %s."), vmdk_file_path)
def get_profile(self, backing):
"""Query storage profile associated with the given backing.
:param backing: backing reference
:return: profile name
"""
profile_ids = pbm.get_profiles(self._session, backing)
if profile_ids:
return pbm.get_profiles_by_ids(self._session, profile_ids)[0].name
def _get_all_clusters(self):
clusters = {}
retrieve_result = self._session.invoke_api(vim_util, 'get_objects',