diff options
| author | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2012-09-28 22:34:25 +0000 |
|---|---|---|
| committer | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2012-09-28 22:44:37 +0000 |
| commit | 9d2dae37f2f092f126d1db3ef2b7248668cf8f78 (patch) | |
| tree | 53ff4dfabab96d4ecdb660329000ded5dfb4a815 | |
| parent | b2d53a8952ee5a3977ee75b25a4aacde81acc34e (diff) | |
| download | nova-9d2dae37f2f092f126d1db3ef2b7248668cf8f78.tar.gz nova-9d2dae37f2f092f126d1db3ef2b7248668cf8f78.tar.xz nova-9d2dae37f2f092f126d1db3ef2b7248668cf8f78.zip | |
Use self.flags() instead of manipulating FLAGS by hand
Since these test cases subclass test.TestCase, they can use self.flags()
to temporarily mutate FLAGS and have it cleaned automatically in the
tearDown() method provided by test.TestCase
Change-Id: I70ec3f8c947172816415190908d8a650d87d7b92
| -rw-r--r-- | nova/tests/compute/test_compute.py | 4 | ||||
| -rw-r--r-- | nova/tests/test_api.py | 4 | ||||
| -rw-r--r-- | nova/tests/test_netapp_nfs.py | 18 | ||||
| -rw-r--r-- | nova/tests/test_nfs.py | 26 |
4 files changed, 18 insertions, 34 deletions
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index d893d823a..3fb5fc230 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -2340,8 +2340,8 @@ class ComputeTestCase(BaseTestCase): self.mox.StubOutWithMock(self.compute.driver, 'list_instances') self.compute.driver.list_instances().AndReturn([instance['name']]) - FLAGS.running_deleted_instance_timeout = 3600 - FLAGS.running_deleted_instance_action = 'reap' + self.flags(running_deleted_instance_timeout=3600, + running_deleted_instance_action='reap') self.mox.StubOutWithMock(self.compute.db, "instance_get_all_by_host") self.compute.db.instance_get_all_by_host(admin_context, diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py index f176231d2..4a4260705 100644 --- a/nova/tests/test_api.py +++ b/nova/tests/test_api.py @@ -366,7 +366,7 @@ class ApiEc2TestCase(test.TestCase): for test in test_raise: self.expect_http() self.mox.ReplayAll() - FLAGS.ec2_strict_validation = test[0] + self.flags(ec2_strict_validation=test[0]) self.assertRaises(boto_exc.EC2ResponseError, self.ec2.create_security_group, test[1], @@ -378,7 +378,7 @@ class ApiEc2TestCase(test.TestCase): for test in test_accept: self.expect_http() self.mox.ReplayAll() - FLAGS.ec2_strict_validation = test[0] + self.flags(ec2_strict_validation=test[0]) self.ec2.create_security_group(test[1], test[2]) self.expect_http() self.mox.ReplayAll() diff --git a/nova/tests/test_netapp_nfs.py b/nova/tests/test_netapp_nfs.py index 49a93728d..1a8824386 100644 --- a/nova/tests/test_netapp_nfs.py +++ b/nova/tests/test_netapp_nfs.py @@ -77,21 +77,17 @@ class NetappNfsDriverTestCase(test.TestCase): def test_check_for_setup_error(self): mox = self.mox drv = self._driver - required_flags = [ - 'netapp_wsdl_url', - 'netapp_login', - 'netapp_password', - 'netapp_server_hostname', - 'netapp_server_port' - ] # check exception raises when flags are not set self.assertRaises(exception.NovaException, drv.check_for_setup_error) # set required flags - for flag in required_flags: - setattr(netapp.FLAGS, flag, 'val') + self.flags(netapp_wsdl_url='val', + netapp_login='val', + netapp_password='val', + netapp_server_hostname='val', + netapp_server_port='val') mox.StubOutWithMock(nfs.NfsDriver, 'check_for_setup_error') nfs.NfsDriver.check_for_setup_error() @@ -99,10 +95,6 @@ class NetappNfsDriverTestCase(test.TestCase): drv.check_for_setup_error() - # restore initial FLAGS - for flag in required_flags: - delattr(netapp.FLAGS, flag) - def test_do_setup(self): mox = self.mox drv = self._driver diff --git a/nova/tests/test_nfs.py b/nova/tests/test_nfs.py index ddfee2fd1..d0d235b1b 100644 --- a/nova/tests/test_nfs.py +++ b/nova/tests/test_nfs.py @@ -93,7 +93,7 @@ class NfsDriverTestCase(test.TestCase): def test_local_path(self): """local_path common use case""" - nfs.FLAGS.nfs_mount_point_base = self.TEST_MNT_POINT_BASE + self.flags(nfs_mount_point_base=self.TEST_MNT_POINT_BASE) drv = self._driver volume = DumbVolume() @@ -201,7 +201,7 @@ class NfsDriverTestCase(test.TestCase): """_get_mount_point_for_share should calculate correct value""" drv = self._driver - nfs.FLAGS.nfs_mount_point_base = self.TEST_MNT_POINT_BASE + self.flags(nfs_mount_point_base=self.TEST_MNT_POINT_BASE) self.assertEqual('/mnt/test/2f4f60214cf43c595666dd815f0360a4', drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1)) @@ -216,7 +216,7 @@ class NfsDriverTestCase(test.TestCase): df_data = 'nfs-host:/export 2620544 996864 %d 41%% /mnt' % df_avail df_output = df_head + df_data - setattr(nfs.FLAGS, 'nfs_disk_util', 'df') + self.flags(nfs_disk_util='df') mox.StubOutWithMock(drv, '_get_mount_point_for_share') drv._get_mount_point_for_share(self.TEST_NFS_EXPORT1).\ @@ -231,14 +231,12 @@ class NfsDriverTestCase(test.TestCase): self.assertEquals(df_avail, drv._get_available_capacity(self.TEST_NFS_EXPORT1)) - delattr(nfs.FLAGS, 'nfs_disk_util') - def test_get_available_capacity_with_du(self): """_get_available_capacity should calculate correct value""" mox = self.mox drv = self._driver - setattr(nfs.FLAGS, 'nfs_disk_util', 'du') + self.flags(nfs_disk_util='du') df_total_size = 2620544 df_used_size = 996864 @@ -270,13 +268,11 @@ class NfsDriverTestCase(test.TestCase): self.assertEquals(df_total_size - du_used, drv._get_available_capacity(self.TEST_NFS_EXPORT1)) - delattr(nfs.FLAGS, 'nfs_disk_util') - def test_load_shares_config(self): mox = self.mox drv = self._driver - nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE + self.flags(nfs_shares_config=self.TEST_SHARES_CONFIG_FILE) mox.StubOutWithMock(__builtin__, 'open') config_data = [] @@ -343,7 +339,7 @@ class NfsDriverTestCase(test.TestCase): """do_setup should throw error if shares config is not configured """ drv = self._driver - nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE + self.flags(nfs_shares_config=self.TEST_SHARES_CONFIG_FILE) self.assertRaises(exception.NfsException, drv.do_setup, IsA(context.RequestContext)) @@ -353,7 +349,7 @@ class NfsDriverTestCase(test.TestCase): mox = self.mox drv = self._driver - nfs.FLAGS.nfs_shares_config = self.TEST_SHARES_CONFIG_FILE + self.flags(nfs_shares_config=self.TEST_SHARES_CONFIG_FILE) mox.StubOutWithMock(os.path, 'exists') os.path.exists(self.TEST_SHARES_CONFIG_FILE).AndReturn(True) @@ -424,7 +420,7 @@ class NfsDriverTestCase(test.TestCase): drv = self._driver volume = self._simple_volume() - setattr(nfs.FLAGS, 'nfs_sparsed_volumes', True) + self.flags(nfs_sparsed_volumes=True) mox.StubOutWithMock(drv, '_create_sparsed_file') mox.StubOutWithMock(drv, '_set_rw_permissions_for_all') @@ -436,14 +432,12 @@ class NfsDriverTestCase(test.TestCase): drv._do_create_volume(volume) - delattr(nfs.FLAGS, 'nfs_sparsed_volumes') - def test_create_nonsparsed_volume(self): mox = self.mox drv = self._driver volume = self._simple_volume() - setattr(nfs.FLAGS, 'nfs_sparsed_volumes', False) + self.flags(nfs_sparsed_volumes=False) mox.StubOutWithMock(drv, '_create_regular_file') mox.StubOutWithMock(drv, '_set_rw_permissions_for_all') @@ -455,8 +449,6 @@ class NfsDriverTestCase(test.TestCase): drv._do_create_volume(volume) - delattr(nfs.FLAGS, 'nfs_sparsed_volumes') - def test_create_volume_should_ensure_nfs_mounted(self): """create_volume should ensure shares provided in config are mounted""" mox = self.mox |
