From c8ff80353173d8785df01a71842d78bbfa290234 Mon Sep 17 00:00:00 2001 From: nidhimittalhada Date: Thu, 28 Apr 2016 14:58:18 +0530 Subject: [PATCH] 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 --- manila/test.py | 2 +- manila/tests/cmd/test_manage.py | 2 +- manila/tests/cmd/test_share.py | 5 +++-- .../drivers/cephfs/test_cephfs_native.py | 3 ++- .../cluster_mode/test_data_motion.py | 20 +++++++++---------- .../share/drivers/netapp/dataontap/fakes.py | 3 ++- .../tests/share/drivers/netapp/test_common.py | 6 ++++-- .../drivers/windows/test_service_instance.py | 4 ++-- manila/tests/test_conf.py | 2 +- manila/tests/test_policy.py | 3 ++- manila/tests/volume/test_cinder.py | 6 ++++-- 11 files changed, 32 insertions(+), 24 deletions(-) diff --git a/manila/test.py b/manila/test.py index 352e8782..eebc8a42 100644 --- a/manila/test.py +++ b/manila/test.py @@ -173,7 +173,7 @@ class TestCase(base_test.BaseTestCase): def flags(self, **kw): """Override flag variables for a test.""" 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): host = host and host or uuid.uuid4().hex diff --git a/manila/tests/cmd/test_manage.py b/manila/tests/cmd/test_manage.py index 0e1d012b..fd73c90b 100644 --- a/manila/tests/cmd/test_manage.py +++ b/manila/tests/cmd/test_manage.py @@ -260,7 +260,7 @@ class ManilaCmdManageTestCase(test.TestCase): @mock.patch('six.moves.builtins.open') @mock.patch('os.listdir') 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'] with mock.patch('sys.stdout', new=six.StringIO()) as fake_out: diff --git a/manila/tests/cmd/test_share.py b/manila/tests/cmd/test_share.py index f9bcf3c9..2592bcc4 100644 --- a/manila/tests/cmd/test_share.py +++ b/manila/tests/cmd/test_share.py @@ -39,8 +39,9 @@ class ManilaCmdShareTestCase(test.TestCase): self.mock_object(self.launcher, 'wait') self.server = manila_share.service.Service.create.return_value fake_host = 'fake_host' - CONF.set_override('enabled_share_backends', backends) - CONF.set_override('host', fake_host) + CONF.set_override('enabled_share_backends', backends, + enforce_type=True) + CONF.set_override('host', fake_host, enforce_type=True) sys.argv = ['manila-share'] manila_share.main() diff --git a/manila/tests/share/drivers/cephfs/test_cephfs_native.py b/manila/tests/share/drivers/cephfs/test_cephfs_native.py index d95dab3d..d083ab51 100644 --- a/manila/tests/share/drivers/cephfs/test_cephfs_native.py +++ b/manila/tests/share/drivers/cephfs/test_cephfs_native.py @@ -351,7 +351,8 @@ class CephFSNativeDriverTestCase(test.TestCase): def test_connect_noevict(self): # When acting as "admin", driver should skip evicting self._driver.configuration.local_conf.set_override('cephfs_auth_id', - "admin") + "admin", + enforce_type=True) self._driver.create_share(self._context, self._share) diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py index 7db0d3bd..5f679cbe 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py @@ -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_replication_opts) CONF.set_override("share_backend_name", self.backend, - group=self.backend) + group=self.backend, enforce_type=True) CONF.set_override("netapp_transport_type", "https", - group=self.backend) + group=self.backend, enforce_type=True) CONF.set_override("netapp_login", "fake_user", - group=self.backend) + group=self.backend, enforce_type=True) CONF.set_override("netapp_password", "fake_password", - group=self.backend) + group=self.backend, enforce_type=True) CONF.set_override("netapp_server_hostname", "fake_hostname", - group=self.backend) + group=self.backend, enforce_type=True) CONF.set_override("netapp_server_port", 8866, - group=self.backend) + group=self.backend, enforce_type=True) def test_get_client_for_backend(self): self.mock_object(data_motion, "get_backend_configuration", @@ -81,7 +81,7 @@ class NetAppCDOTDataMotionTestCase(test.TestCase): mock.Mock(return_value=self.config)) CONF.set_override("netapp_vserver", 'fake_vserver', - group=self.backend) + group=self.backend, enforce_type=True) data_motion.get_client_for_backend(self.backend) @@ -93,7 +93,7 @@ class NetAppCDOTDataMotionTestCase(test.TestCase): def test_get_config_for_backend(self): self.mock_object(data_motion, "CONF") 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] 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): self.mock_object(data_motion, "CONF") 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", - group=self.backend) + group=self.backend, enforce_type=True) data_motion.CONF.list_all_sections.return_value = [self.backend] config = data_motion.get_backend_configuration(self.backend) diff --git a/manila/tests/share/drivers/netapp/dataontap/fakes.py b/manila/tests/share/drivers/netapp/dataontap/fakes.py index 9cf522b9..b12eafbd 100644 --- a/manila/tests/share/drivers/netapp/dataontap/fakes.py +++ b/manila/tests/share/drivers/netapp/dataontap/fakes.py @@ -567,7 +567,8 @@ SSC_DISK_TYPES = { def get_config_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.netapp_login = CLIENT_KWARGS['username'] config.netapp_password = CLIENT_KWARGS['password'] diff --git a/manila/tests/share/drivers/netapp/test_common.py b/manila/tests/share/drivers/netapp/test_common.py index 2008ac78..a53971f9 100644 --- a/manila/tests/share/drivers/netapp/test_common.py +++ b/manila/tests/share/drivers/netapp/test_common.py @@ -120,7 +120,8 @@ class NetAppDriverFactoryTestCase(test.TestCase): config = na_fakes.create_configuration() config.local_conf.set_override('driver_handles_share_servers', - mode == na_common.MULTI_SVM) + mode == na_common.MULTI_SVM, + enforce_type=True) kwargs = { 'configuration': config, 'private_storage': mock.Mock(), @@ -135,7 +136,8 @@ class NetAppDriverFactoryTestCase(test.TestCase): def test_create_driver_case_insensitive(self): 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 = { 'configuration': config, diff --git a/manila/tests/share/drivers/windows/test_service_instance.py b/manila/tests/share/drivers/windows/test_service_instance.py index 7c359e03..eca61f0e 100644 --- a/manila/tests/share/drivers/windows/test_service_instance.py +++ b/manila/tests/share/drivers/windows/test_service_instance.py @@ -82,7 +82,7 @@ class WindowsServiceInstanceManagerTestCase(test.TestCase): if not use_cert_auth: mock_check_complexity.assert_called_once_with( - mock.sentinel.password) + str(mock.sentinel.password)) @ddt.data(False, True) 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) else: 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() diff --git a/manila/tests/test_conf.py b/manila/tests/test_conf.py index 2c9e897a..a285ef64 100644 --- a/manila/tests/test_conf.py +++ b/manila/tests/test_conf.py @@ -38,7 +38,7 @@ class ConfigTestCase(test.TestCase): self.assertEqual(42, CONF.answer) # 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) CONF.import_opt('answer', 'manila.tests.declare_conf') self.assertEqual(256, CONF.answer) diff --git a/manila/tests/test_policy.py b/manila/tests/test_policy.py index 354b5935..b99d53dc 100644 --- a/manila/tests/test_policy.py +++ b/manila/tests/test_policy.py @@ -41,7 +41,8 @@ class PolicyFileTestCase(test.TestCase): def test_modified_policy_reloads(self): with utils.tempdir() as tmpdir: 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" with open(tmpfilename, "w") as policyfile: policyfile.write("""{"example:test": []}""") diff --git a/manila/tests/volume/test_cinder.py b/manila/tests/volume/test_cinder.py index 4565c07a..d6709ccc 100644 --- a/manila/tests/volume/test_cinder.py +++ b/manila/tests/volume/test_cinder.py @@ -113,7 +113,8 @@ class CinderApiTestCase(test.TestCase): volume['attach_status'] = "detached" instance = {'availability_zone': 'zone1'} 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.api.check_attach, self.ctx, volume, instance) volume['availability_zone'] = 'zone1' @@ -125,7 +126,8 @@ class CinderApiTestCase(test.TestCase): volume['attach_status'] = "detached" volume['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)) cinder.CONF.reset()