"""Test class for VMwareVcVmdkDriver."""
VMDK_DRIVER = vmdk.VMwareVcVmdkDriver
- DEFAULT_PROFILE = 'fakeProfile'
DEFAULT_VC_VERSION = '5.5'
def setUp(self):
super(VMwareVcVmdkDriverTestCase, self).setUp()
- self._config.pbm_default_policy = self.DEFAULT_PROFILE
self._config.vmware_host_version = self.DEFAULT_VC_VERSION
self._driver = vmdk.VMwareVcVmdkDriver(configuration=self._config)
'_get_vc_version')
@mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
'session', new_callable=mock.PropertyMock)
- @mock.patch('cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver.'
- 'volumeops', new_callable=mock.PropertyMock)
- def test_do_setup(self, vol_ops, session, _get_vc_version,
- _get_pbm_wsdl_location):
- vol_ops = vol_ops.return_value
+ def test_do_setup(self, session, _get_vc_version, _get_pbm_wsdl_location):
session = session.return_value
- # pbm is enabled and pbm_default_policy is used
- _get_vc_version.return_value = LooseVersion('5.5')
- _get_pbm_wsdl_location.return_value = 'fake_pbm_location'
- self._driver.do_setup(mock.ANY)
- default = self.DEFAULT_PROFILE
- vol_ops.retrieve_profile_id.assert_called_once_with(default)
- self.assertTrue(self._driver._storage_policy_enabled)
-
- # pbm is enabled and pbm_default_policy is wrong
- self._driver._storage_policy_enabled = False
- vol_ops.retrieve_profile_id.reset_mock()
- vol_ops.retrieve_profile_id.return_value = None
- self.assertRaises(error_util.PbmDefaultPolicyDoesNotExist,
- self._driver.do_setup, mock.ANY)
- vol_ops.retrieve_profile_id.assert_called_once_with(default)
# pbm is disabled
- self._driver._storage_policy_enabled = False
- vol_ops.retrieve_profile_id.reset_mock()
- _get_vc_version.return_value = LooseVersion('5.0')
+ vc_version = LooseVersion('5.0')
+ _get_vc_version.return_value = vc_version
self._driver.do_setup(mock.ANY)
self.assertFalse(self._driver._storage_policy_enabled)
- self.assertFalse(vol_ops.retrieve_profile_id.called)
+ _get_vc_version.assert_called_once_with()
+
+ # pbm is enabled and invalid pbm wsdl location
+ vc_version = LooseVersion('5.5')
+ _get_vc_version.reset_mock()
+ _get_vc_version.return_value = vc_version
+ _get_pbm_wsdl_location.return_value = None
+ self.assertRaises(error_util.VMwareDriverException,
+ self._driver.do_setup,
+ mock.ANY)
+ self.assertFalse(self._driver._storage_policy_enabled)
+ _get_vc_version.assert_called_once_with()
+ _get_pbm_wsdl_location.assert_called_once_with(vc_version)
+
+ # pbm is enabled and valid pbm wsdl location
+ vc_version = LooseVersion('5.5')
+ _get_vc_version.reset_mock()
+ _get_vc_version.return_value = vc_version
+ _get_pbm_wsdl_location.reset_mock()
+ _get_pbm_wsdl_location.return_value = 'fake_pbm_location'
+ self._driver.do_setup(mock.ANY)
+ self.assertTrue(self._driver._storage_policy_enabled)
+ _get_vc_version.assert_called_once_with()
+ _get_pbm_wsdl_location.assert_called_once_with(vc_version)
@mock.patch.object(VMDK_DRIVER, '_extend_volumeops_virtual_disk')
@mock.patch.object(VMDK_DRIVER, '_create_backing_in_inventory')
spec_key = 'vmware:storage_profile'
get_volume_type_extra_specs.assert_called_once_with(fake_id, spec_key)
- # default profile should be returned when no storage profile is
+ # None should be returned when no storage profile is
# associated with the volume type
get_volume_type_extra_specs.return_value = False
profile = self._driver._get_storage_profile(volume)
- self.assertEqual(self.DEFAULT_PROFILE, profile)
+ self.assertIsNone(profile)
@mock.patch('cinder.volume.drivers.vmware.vim_util.'
'convert_datastores_to_hubs')
'override the VC server version.'),
]
-spbm_opts = [
- cfg.StrOpt('pbm_default_policy',
- help='The PBM default policy. If using VC server version 5.5 '
- 'or above and there is no defined storage policy for the '
- 'specific request then this policy will be used.'),
-]
-
CONF = cfg.CONF
CONF.register_opts(vmdk_opts)
-CONF.register_opts(spbm_opts)
def _get_volume_type_extra_spec(type_id, spec_key, possible_values=None,
return best_summary
def _get_storage_profile(self, volume):
- """Get storage profile associated with this volume's volume_type.
+ """Get storage profile associated with the given volume's volume_type.
- :param volume: volume whose storage profile should be queried
- :return: string value of storage profile if volume type is associated,
- default global profile if configured in pbm_default_profile,
- None otherwise
+ :param volume: Volume whose storage profile should be queried
+ :return: String value of storage profile if volume type is associated
+ and contains storage_profile extra_spec option; None otherwise
"""
type_id = volume['volume_type_id']
- if not type_id:
- return
- default_policy = self.configuration.pbm_default_policy
- return _get_volume_type_extra_spec(type_id, 'storage_profile',
- default_value=default_policy)
+ if type_id is None:
+ return None
+ return _get_volume_type_extra_spec(type_id, 'storage_profile')
def _filter_ds_by_profile(self, datastores, storage_profile):
"""Filter out datastores that do not match given storage profile.
def __init__(self, *args, **kwargs):
super(VMwareVcVmdkDriver, self).__init__(*args, **kwargs)
- self.configuration.append_config_values(spbm_opts)
self._session = None
@property
max_objects = self.configuration.vmware_max_objects_retrieval
self._volumeops = volumeops.VMwareVolumeOps(self.session, max_objects)
- # if default policy is configured verify it exists in VC
- default_policy = self.configuration.pbm_default_policy
- if default_policy:
- if not self._storage_policy_enabled:
- LOG.warn(_("Ignoring default policy '%(policy)s' since "
- "Storage Policy Based Management is not "
- "enabled on VC version %(ver)s") %
- {'policy': default_policy, 'ver': vc_version})
- else:
- if not self.volumeops.retrieve_profile_id(default_policy):
- msg = _("The configured default PBM policy '%s' is not "
- "defined on vCenter Server.") % default_policy
- raise error_util.PbmDefaultPolicyDoesNotExist(message=msg)
- LOG.info(_("Successfully verified existence of "
- "pbm_default_policy: %s."), default_policy)
-
LOG.info(_("Successfully setup driver: %(driver)s for server: "
"%(ip)s.") % {'driver': self.__class__.__name__,
'ip': self.configuration.vmware_host_ip})