Fix wrong usage of config option gpfs_images_share_mode

Config option gpfs_images_share_mode with parameter choices=['copy',
'copy_on_write', None], that means any other value will raise
ValueError, the check is done by the configuration parser, so no
invalid value will be accepted and the driver doesn't need to check it
again. For more details when we set method set_override with paramter
enforce_type=True, please see: http://paste.openstack.org/show/523740/

Related-Bug: 1517839

Change-Id: I000ab639e68534e7be111cc3759b6ae1dffd5520
This commit is contained in:
ChangBo Guo(gcb) 2016-06-28 16:49:18 +08:00
parent 366acd02b4
commit ccd8abb7f1
2 changed files with 2 additions and 28 deletions

View File

@ -540,16 +540,6 @@ class GPFSDriverTestCase(test.TestCase):
self.flags(volume_driver=self.driver_name,
gpfs_mount_point_base=org_value)
# fail configuration.gpfs_images_share_mode not in
# ['copy_on_write', 'copy']
org_value = self.driver.configuration.gpfs_images_share_mode
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode='copy_on_read')
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.check_for_setup_error)
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode=org_value)
# fail configuration.gpfs_images_share_mode and
# configuration.gpfs_images_dir is None
org_value_share_mode = self.driver.configuration.gpfs_images_share_mode
@ -1195,26 +1185,17 @@ class GPFSDriverTestCase(test.TestCase):
@mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._is_gpfs_path')
def test_is_cloneable_ok(self, mock_is_gpfs_path):
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode='test')
gpfs_images_share_mode='copy')
CONF.gpfs_images_dir = self.images_dir
mock_is_gpfs_path.return_value = None
self.assertEqual((True, None, os.path.join(CONF.gpfs_images_dir,
'12345')),
self.driver._is_cloneable('12345'))
@mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._is_gpfs_path')
def test_is_cloneable_fail_config(self, mock_is_gpfs_path):
self.flags(volume_driver=self.driver_name, gpfs_images_share_mode='')
CONF.gpfs_images_dir = ''
mock_is_gpfs_path.return_value = None
self.assertNotEqual((True, None, os.path.join(CONF.gpfs_images_dir,
'12345')),
self.driver._is_cloneable('12345'))
@mock.patch('cinder.volume.drivers.ibm.gpfs.GPFSDriver._is_gpfs_path')
def test_is_cloneable_fail_path(self, mock_is_gpfs_path):
self.flags(volume_driver=self.driver_name,
gpfs_images_share_mode='test')
gpfs_images_share_mode='copy')
CONF.gpfs_images_dir = self.images_dir
mock_is_gpfs_path.side_effect = (
processutils.ProcessExecutionError(stdout='test', stderr='test'))

View File

@ -379,13 +379,6 @@ class GPFSDriver(driver.ConsistencyGroupVD, driver.ExtendVD,
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
if (self.configuration.gpfs_images_share_mode and
self.configuration.gpfs_images_share_mode not in ['copy_on_write',
'copy']):
msg = _('Option gpfs_images_share_mode is not set correctly.')
LOG.error(msg)
raise exception.VolumeBackendAPIException(data=msg)
if(self.configuration.gpfs_images_share_mode and
self.configuration.gpfs_images_dir is None):
msg = _('Option gpfs_images_dir is not set correctly.')