Test: make enforce_type=True in CONF.set_override
Each config option has limitation for type and value. If we use method CONF.set_override without parameter enforce_type=True, we may pass wrong type to config option. This commit makes sure calling method CONF.set_override with enforce_type=True. Change-Id: I700dcd21941c6399c51e11bef2282e1e4565e85a Closes-Bug: #1517839
This commit is contained in:
parent
fc518706c0
commit
c8ff803531
@ -173,7 +173,7 @@ class TestCase(base_test.BaseTestCase):
|
|||||||
def flags(self, **kw):
|
def flags(self, **kw):
|
||||||
"""Override flag variables for a test."""
|
"""Override flag variables for a test."""
|
||||||
for k, v in kw.items():
|
for k, v in kw.items():
|
||||||
CONF.set_override(k, v)
|
CONF.set_override(k, v, enforce_type=True)
|
||||||
|
|
||||||
def start_service(self, name, host=None, **kwargs):
|
def start_service(self, name, host=None, **kwargs):
|
||||||
host = host and host or uuid.uuid4().hex
|
host = host and host or uuid.uuid4().hex
|
||||||
|
@ -260,7 +260,7 @@ class ManilaCmdManageTestCase(test.TestCase):
|
|||||||
@mock.patch('six.moves.builtins.open')
|
@mock.patch('six.moves.builtins.open')
|
||||||
@mock.patch('os.listdir')
|
@mock.patch('os.listdir')
|
||||||
def test_get_log_commands_errors(self, listdir, open):
|
def test_get_log_commands_errors(self, listdir, open):
|
||||||
CONF.set_override('log_dir', 'fake-dir')
|
CONF.set_override('log_dir', 'fake-dir', enforce_type=True)
|
||||||
listdir.return_value = ['fake-error.log']
|
listdir.return_value = ['fake-error.log']
|
||||||
|
|
||||||
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
|
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
|
||||||
|
@ -39,8 +39,9 @@ class ManilaCmdShareTestCase(test.TestCase):
|
|||||||
self.mock_object(self.launcher, 'wait')
|
self.mock_object(self.launcher, 'wait')
|
||||||
self.server = manila_share.service.Service.create.return_value
|
self.server = manila_share.service.Service.create.return_value
|
||||||
fake_host = 'fake_host'
|
fake_host = 'fake_host'
|
||||||
CONF.set_override('enabled_share_backends', backends)
|
CONF.set_override('enabled_share_backends', backends,
|
||||||
CONF.set_override('host', fake_host)
|
enforce_type=True)
|
||||||
|
CONF.set_override('host', fake_host, enforce_type=True)
|
||||||
sys.argv = ['manila-share']
|
sys.argv = ['manila-share']
|
||||||
|
|
||||||
manila_share.main()
|
manila_share.main()
|
||||||
|
@ -351,7 +351,8 @@ class CephFSNativeDriverTestCase(test.TestCase):
|
|||||||
def test_connect_noevict(self):
|
def test_connect_noevict(self):
|
||||||
# When acting as "admin", driver should skip evicting
|
# When acting as "admin", driver should skip evicting
|
||||||
self._driver.configuration.local_conf.set_override('cephfs_auth_id',
|
self._driver.configuration.local_conf.set_override('cephfs_auth_id',
|
||||||
"admin")
|
"admin",
|
||||||
|
enforce_type=True)
|
||||||
|
|
||||||
self._driver.create_share(self._context,
|
self._driver.create_share(self._context,
|
||||||
self._share)
|
self._share)
|
||||||
|
@ -53,17 +53,17 @@ class NetAppCDOTDataMotionTestCase(test.TestCase):
|
|||||||
self.config.append_config_values(na_opts.netapp_provisioning_opts)
|
self.config.append_config_values(na_opts.netapp_provisioning_opts)
|
||||||
self.config.append_config_values(na_opts.netapp_replication_opts)
|
self.config.append_config_values(na_opts.netapp_replication_opts)
|
||||||
CONF.set_override("share_backend_name", self.backend,
|
CONF.set_override("share_backend_name", self.backend,
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
CONF.set_override("netapp_transport_type", "https",
|
CONF.set_override("netapp_transport_type", "https",
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
CONF.set_override("netapp_login", "fake_user",
|
CONF.set_override("netapp_login", "fake_user",
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
CONF.set_override("netapp_password", "fake_password",
|
CONF.set_override("netapp_password", "fake_password",
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
CONF.set_override("netapp_server_hostname", "fake_hostname",
|
CONF.set_override("netapp_server_hostname", "fake_hostname",
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
CONF.set_override("netapp_server_port", 8866,
|
CONF.set_override("netapp_server_port", 8866,
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
|
|
||||||
def test_get_client_for_backend(self):
|
def test_get_client_for_backend(self):
|
||||||
self.mock_object(data_motion, "get_backend_configuration",
|
self.mock_object(data_motion, "get_backend_configuration",
|
||||||
@ -81,7 +81,7 @@ class NetAppCDOTDataMotionTestCase(test.TestCase):
|
|||||||
mock.Mock(return_value=self.config))
|
mock.Mock(return_value=self.config))
|
||||||
|
|
||||||
CONF.set_override("netapp_vserver", 'fake_vserver',
|
CONF.set_override("netapp_vserver", 'fake_vserver',
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
|
|
||||||
data_motion.get_client_for_backend(self.backend)
|
data_motion.get_client_for_backend(self.backend)
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ class NetAppCDOTDataMotionTestCase(test.TestCase):
|
|||||||
def test_get_config_for_backend(self):
|
def test_get_config_for_backend(self):
|
||||||
self.mock_object(data_motion, "CONF")
|
self.mock_object(data_motion, "CONF")
|
||||||
CONF.set_override("netapp_vserver", 'fake_vserver',
|
CONF.set_override("netapp_vserver", 'fake_vserver',
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
data_motion.CONF.list_all_sections.return_value = [self.backend]
|
data_motion.CONF.list_all_sections.return_value = [self.backend]
|
||||||
|
|
||||||
config = data_motion.get_backend_configuration(self.backend)
|
config = data_motion.get_backend_configuration(self.backend)
|
||||||
@ -103,9 +103,9 @@ class NetAppCDOTDataMotionTestCase(test.TestCase):
|
|||||||
def test_get_config_for_backend_different_backend_name(self):
|
def test_get_config_for_backend_different_backend_name(self):
|
||||||
self.mock_object(data_motion, "CONF")
|
self.mock_object(data_motion, "CONF")
|
||||||
CONF.set_override("netapp_vserver", 'fake_vserver',
|
CONF.set_override("netapp_vserver", 'fake_vserver',
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
CONF.set_override("share_backend_name", "fake_backend_name",
|
CONF.set_override("share_backend_name", "fake_backend_name",
|
||||||
group=self.backend)
|
group=self.backend, enforce_type=True)
|
||||||
data_motion.CONF.list_all_sections.return_value = [self.backend]
|
data_motion.CONF.list_all_sections.return_value = [self.backend]
|
||||||
|
|
||||||
config = data_motion.get_backend_configuration(self.backend)
|
config = data_motion.get_backend_configuration(self.backend)
|
||||||
|
@ -567,7 +567,8 @@ SSC_DISK_TYPES = {
|
|||||||
|
|
||||||
def get_config_cmode():
|
def get_config_cmode():
|
||||||
config = na_fakes.create_configuration_cmode()
|
config = na_fakes.create_configuration_cmode()
|
||||||
config.local_conf.set_override('share_backend_name', BACKEND_NAME)
|
config.local_conf.set_override('share_backend_name', BACKEND_NAME,
|
||||||
|
enforce_type=True)
|
||||||
config.reserved_share_percentage = 5
|
config.reserved_share_percentage = 5
|
||||||
config.netapp_login = CLIENT_KWARGS['username']
|
config.netapp_login = CLIENT_KWARGS['username']
|
||||||
config.netapp_password = CLIENT_KWARGS['password']
|
config.netapp_password = CLIENT_KWARGS['password']
|
||||||
|
@ -120,7 +120,8 @@ class NetAppDriverFactoryTestCase(test.TestCase):
|
|||||||
|
|
||||||
config = na_fakes.create_configuration()
|
config = na_fakes.create_configuration()
|
||||||
config.local_conf.set_override('driver_handles_share_servers',
|
config.local_conf.set_override('driver_handles_share_servers',
|
||||||
mode == na_common.MULTI_SVM)
|
mode == na_common.MULTI_SVM,
|
||||||
|
enforce_type=True)
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'configuration': config,
|
'configuration': config,
|
||||||
'private_storage': mock.Mock(),
|
'private_storage': mock.Mock(),
|
||||||
@ -135,7 +136,8 @@ class NetAppDriverFactoryTestCase(test.TestCase):
|
|||||||
def test_create_driver_case_insensitive(self):
|
def test_create_driver_case_insensitive(self):
|
||||||
|
|
||||||
config = na_fakes.create_configuration()
|
config = na_fakes.create_configuration()
|
||||||
config.local_conf.set_override('driver_handles_share_servers', True)
|
config.local_conf.set_override('driver_handles_share_servers', True,
|
||||||
|
enforce_type=True)
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'configuration': config,
|
'configuration': config,
|
||||||
|
@ -82,7 +82,7 @@ class WindowsServiceInstanceManagerTestCase(test.TestCase):
|
|||||||
|
|
||||||
if not use_cert_auth:
|
if not use_cert_auth:
|
||||||
mock_check_complexity.assert_called_once_with(
|
mock_check_complexity.assert_called_once_with(
|
||||||
mock.sentinel.password)
|
str(mock.sentinel.password))
|
||||||
|
|
||||||
@ddt.data(False, True)
|
@ddt.data(False, True)
|
||||||
def test_get_auth_info(self, use_cert_auth):
|
def test_get_auth_info(self, use_cert_auth):
|
||||||
@ -165,7 +165,7 @@ class WindowsServiceInstanceManagerTestCase(test.TestCase):
|
|||||||
expected_kwargs = dict(user_data=mock_cert_data)
|
expected_kwargs = dict(user_data=mock_cert_data)
|
||||||
else:
|
else:
|
||||||
expected_kwargs = dict(
|
expected_kwargs = dict(
|
||||||
meta=dict(admin_pass=mock.sentinel.admin_pass))
|
meta=dict(admin_pass=str(mock.sentinel.admin_pass)))
|
||||||
|
|
||||||
create_kwargs = self._mgr._get_service_instance_create_kwargs()
|
create_kwargs = self._mgr._get_service_instance_create_kwargs()
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class ConfigTestCase(test.TestCase):
|
|||||||
self.assertEqual(42, CONF.answer)
|
self.assertEqual(42, CONF.answer)
|
||||||
|
|
||||||
# Make sure we don't overwrite anything
|
# Make sure we don't overwrite anything
|
||||||
CONF.set_override('answer', 256)
|
CONF.set_override('answer', 256, enforce_type=True)
|
||||||
self.assertEqual(256, CONF.answer)
|
self.assertEqual(256, CONF.answer)
|
||||||
CONF.import_opt('answer', 'manila.tests.declare_conf')
|
CONF.import_opt('answer', 'manila.tests.declare_conf')
|
||||||
self.assertEqual(256, CONF.answer)
|
self.assertEqual(256, CONF.answer)
|
||||||
|
@ -41,7 +41,8 @@ class PolicyFileTestCase(test.TestCase):
|
|||||||
def test_modified_policy_reloads(self):
|
def test_modified_policy_reloads(self):
|
||||||
with utils.tempdir() as tmpdir:
|
with utils.tempdir() as tmpdir:
|
||||||
tmpfilename = os.path.join(tmpdir, 'policy')
|
tmpfilename = os.path.join(tmpdir, 'policy')
|
||||||
CONF.set_override('policy_file', tmpfilename, group='oslo_policy')
|
CONF.set_override('policy_file', tmpfilename, group='oslo_policy',
|
||||||
|
enforce_type=True)
|
||||||
action = "example:test"
|
action = "example:test"
|
||||||
with open(tmpfilename, "w") as policyfile:
|
with open(tmpfilename, "w") as policyfile:
|
||||||
policyfile.write("""{"example:test": []}""")
|
policyfile.write("""{"example:test": []}""")
|
||||||
|
@ -113,7 +113,8 @@ class CinderApiTestCase(test.TestCase):
|
|||||||
volume['attach_status'] = "detached"
|
volume['attach_status'] = "detached"
|
||||||
instance = {'availability_zone': 'zone1'}
|
instance = {'availability_zone': 'zone1'}
|
||||||
volume['availability_zone'] = 'zone2'
|
volume['availability_zone'] = 'zone2'
|
||||||
cinder.CONF.set_override('cross_az_attach', False, 'cinder')
|
cinder.CONF.set_override('cross_az_attach', False, 'cinder',
|
||||||
|
enforce_type=True)
|
||||||
self.assertRaises(exception.InvalidVolume,
|
self.assertRaises(exception.InvalidVolume,
|
||||||
self.api.check_attach, self.ctx, volume, instance)
|
self.api.check_attach, self.ctx, volume, instance)
|
||||||
volume['availability_zone'] = 'zone1'
|
volume['availability_zone'] = 'zone1'
|
||||||
@ -125,7 +126,8 @@ class CinderApiTestCase(test.TestCase):
|
|||||||
volume['attach_status'] = "detached"
|
volume['attach_status'] = "detached"
|
||||||
volume['availability_zone'] = 'zone1'
|
volume['availability_zone'] = 'zone1'
|
||||||
instance = {'availability_zone': 'zone1'}
|
instance = {'availability_zone': 'zone1'}
|
||||||
cinder.CONF.set_override('cross_az_attach', False, 'cinder')
|
cinder.CONF.set_override('cross_az_attach', False, 'cinder',
|
||||||
|
enforce_type=True)
|
||||||
self.assertIsNone(self.api.check_attach(self.ctx, volume, instance))
|
self.assertIsNone(self.api.check_attach(self.ctx, volume, instance))
|
||||||
cinder.CONF.reset()
|
cinder.CONF.reset()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user