From f72c547dbaa41b82ff243f0407cffc39a23424f7 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 24 Feb 2014 15:28:23 -0500 Subject: [PATCH] Update tests to use CONF.set_override This patch updates some tests that were overriding configuration values by means other than CONF.set_override. It also removes any left over references to the glusterfs_disk_util config option. Closes-bug: 1284293 Closes-bug: 1284300 Change-Id: Id2d14cc3ff77322d017033f3558aed9cd637589b --- cinder/tests/test_backup.py | 5 +---- cinder/tests/test_glusterfs.py | 31 +++++++++++++++++-------------- cinder/tests/test_nfs.py | 8 ++------ 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/cinder/tests/test_backup.py b/cinder/tests/test_backup.py index 94a2d29c5..19618c14b 100644 --- a/cinder/tests/test_backup.py +++ b/cinder/tests/test_backup.py @@ -416,14 +416,11 @@ class BackupTestCase(test.TestCase): def test_backup_manager_driver_name(self): """"Test mapping between backup services and backup drivers.""" - - old_setting = CONF.backup_driver - setattr(cfg.CONF, 'backup_driver', "cinder.backup.services.swift") + cfg.CONF.set_override('backup_driver', "cinder.backup.services.swift") backup_mgr = \ importutils.import_object(CONF.backup_manager) self.assertEqual('cinder.backup.drivers.swift', backup_mgr.driver_name) - setattr(cfg.CONF, 'backup_driver', old_setting) def test_export_record_with_bad_service(self): """Test error handling when attempting an export of a backup diff --git a/cinder/tests/test_glusterfs.py b/cinder/tests/test_glusterfs.py index 94dbd8b1b..88456b0a5 100644 --- a/cinder/tests/test_glusterfs.py +++ b/cinder/tests/test_glusterfs.py @@ -22,6 +22,7 @@ import mox as mox_lib from mox import IgnoreArg from mox import IsA from mox import stubout +from oslo.config import cfg from cinder import brick from cinder import context @@ -38,6 +39,9 @@ from cinder.volume import driver as base_driver from cinder.volume.drivers import glusterfs +CONF = cfg.CONF + + class DumbVolume(object): fields = {} @@ -84,7 +88,6 @@ class GlusterFsDriverTestCase(test.TestCase): self.TEST_SHARES_CONFIG_FILE self._configuration.glusterfs_mount_point_base = \ self.TEST_MNT_POINT_BASE - self._configuration.glusterfs_disk_util = 'df' self._configuration.glusterfs_sparsed_volumes = True self._configuration.glusterfs_qcow2_volumes = False @@ -123,7 +126,8 @@ class GlusterFsDriverTestCase(test.TestCase): def test_local_path(self): """local_path common use case.""" - glusterfs.CONF.glusterfs_mount_point_base = self.TEST_MNT_POINT_BASE + CONF.set_override("glusterfs_mount_point_base", + self.TEST_MNT_POINT_BASE) drv = self._driver volume = DumbVolume() @@ -229,7 +233,8 @@ class GlusterFsDriverTestCase(test.TestCase): mox.StubOutWithMock(brick.remotefs.remotefs.RemoteFsClient, 'get_mount_point') - glusterfs.CONF.glusterfs_mount_point_base = self.TEST_MNT_POINT_BASE + CONF.set_override("glusterfs_mount_point_base", + self.TEST_MNT_POINT_BASE) brick.remotefs.remotefs.RemoteFsClient.\ get_mount_point(self.TEST_EXPORT1).AndReturn(hashed_path) @@ -250,8 +255,6 @@ class GlusterFsDriverTestCase(test.TestCase): (df_total_size, df_avail) df_output = df_head + df_data - setattr(glusterfs.CONF, 'glusterfs_disk_util', 'df') - mox.StubOutWithMock(drv, '_get_mount_point_for_share') drv._get_mount_point_for_share(self.TEST_EXPORT1).\ AndReturn(self.TEST_MNT_POINT) @@ -268,8 +271,6 @@ class GlusterFsDriverTestCase(test.TestCase): mox.VerifyAll() - delattr(glusterfs.CONF, 'glusterfs_disk_util') - def test_load_shares_config(self): mox = self._mox drv = self._driver @@ -381,7 +382,8 @@ class GlusterFsDriverTestCase(test.TestCase): """do_setup should throw error if shares config is not configured.""" drv = self._driver - glusterfs.CONF.glusterfs_shares_config = self.TEST_SHARES_CONFIG_FILE + CONF.set_override("glusterfs_shares_config", + self.TEST_SHARES_CONFIG_FILE) self.assertRaises(exception.GlusterfsException, drv.do_setup, IsA(context.RequestContext)) @@ -391,7 +393,8 @@ class GlusterFsDriverTestCase(test.TestCase): mox = self._mox drv = self._driver - glusterfs.CONF.glusterfs_shares_config = self.TEST_SHARES_CONFIG_FILE + CONF.set_override("glusterfs_shares_config", + self.TEST_SHARES_CONFIG_FILE) mox.StubOutWithMock(os.path, 'exists') os.path.exists(self.TEST_SHARES_CONFIG_FILE).AndReturn(True) @@ -416,7 +419,8 @@ class GlusterFsDriverTestCase(test.TestCase): mox = self._mox drv = self._driver - glusterfs.CONF.glusterfs_shares_config = self.TEST_SHARES_CONFIG_FILE + CONF.set_override("glusterfs_shares_config", + self.TEST_SHARES_CONFIG_FILE) self.stubs.Set(drv, '_load_shares_config', self._fake_load_shares_config) @@ -523,7 +527,7 @@ class GlusterFsDriverTestCase(test.TestCase): drv = self._driver volume = self._simple_volume() - setattr(glusterfs.CONF, 'glusterfs_sparsed_volumes', True) + CONF.set_override('glusterfs_sparsed_volumes', True) mox.StubOutWithMock(drv, '_create_sparsed_file') mox.StubOutWithMock(drv, '_set_rw_permissions_for_all') @@ -537,8 +541,6 @@ class GlusterFsDriverTestCase(test.TestCase): mox.VerifyAll() - delattr(glusterfs.CONF, 'glusterfs_sparsed_volumes') - def test_create_nonsparsed_volume(self): mox = self._mox drv = self._driver @@ -1506,7 +1508,8 @@ class GlusterFsDriverTestCase(test.TestCase): def test_get_backing_chain_for_path(self): (mox, drv) = self._mox, self._driver - glusterfs.CONF.glusterfs_mount_point_base = self.TEST_MNT_POINT_BASE + CONF.set_override('glusterfs_mount_point_base', + self.TEST_MNT_POINT_BASE) volume = self._simple_volume() vol_filename = volume['name'] diff --git a/cinder/tests/test_nfs.py b/cinder/tests/test_nfs.py index 27b38fc1c..719ac88da 100644 --- a/cinder/tests/test_nfs.py +++ b/cinder/tests/test_nfs.py @@ -465,7 +465,7 @@ class NfsDriverTestCase(test.TestCase): drv = self._driver volume = self._simple_volume() - setattr(cfg.CONF, 'nfs_sparsed_volumes', True) + cfg.CONF.set_override('nfs_sparsed_volumes', True) mox.StubOutWithMock(drv, '_create_sparsed_file') mox.StubOutWithMock(drv, '_set_rw_permissions_for_all') @@ -479,15 +479,13 @@ class NfsDriverTestCase(test.TestCase): mox.VerifyAll() - delattr(cfg.CONF, 'nfs_sparsed_volumes') - def test_create_nonsparsed_volume(self): mox = self._mox drv = self._driver self.configuration.nfs_sparsed_volumes = False volume = self._simple_volume() - setattr(cfg.CONF, 'nfs_sparsed_volumes', False) + cfg.CONF.set_override('nfs_sparsed_volumes', False) mox.StubOutWithMock(drv, '_create_regular_file') mox.StubOutWithMock(drv, '_set_rw_permissions_for_all') @@ -501,8 +499,6 @@ class NfsDriverTestCase(test.TestCase): mox.VerifyAll() - delattr(cfg.CONF, 'nfs_sparsed_volumes') - def test_create_volume_should_ensure_nfs_mounted(self): """create_volume ensures shares provided in config are mounted.""" mox = self._mox -- 2.45.2