From: Mark McLoughlin Date: Mon, 16 Jul 2012 20:10:17 +0000 (+0100) Subject: Use cfg's new behavior of reset() clearing overrides X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f07d38bca4ca26edb6f68d4183656b2e87a6c7fc;p=openstack-build%2Fcinder-build.git Use cfg's new behavior of reset() clearing overrides Cherry-picks b858108 from Nova. Change-Id: I5e14dea25afd5bff03a39671b2d3b85481977bec Reviewed-on: https://review.openstack.org/9868 Reviewed-by: Huang Zhiteng Reviewed-by: Vish Ishaya Approved: John Griffith Tested-by: Jenkins --- diff --git a/cinder/test.py b/cinder/test.py index fb88c89c0..ef9ccce9e 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -40,6 +40,7 @@ from cinder.openstack.common import timeutils from cinder import utils from cinder import service from cinder import tests +from cinder.tests import fake_flags test_opts = [ @@ -124,6 +125,9 @@ class TestCase(unittest.TestCase): def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() + + fake_flags.set_defaults(FLAGS) + # NOTE(vish): We need a better method for creating fixtures for tests # now that we have some required db setup for the system # to work properly. @@ -136,7 +140,6 @@ class TestCase(unittest.TestCase): self.stubs = stubout.StubOutForTesting() self.injected = [] self._services = [] - self._overridden_opts = [] def tearDown(self): """Runs after each test method to tear down test environment.""" @@ -148,7 +151,7 @@ class TestCase(unittest.TestCase): super(TestCase, self).tearDown() finally: # Reset any overridden flags - self.reset_flags() + FLAGS.reset() # Stop any timers for x in self.injected: @@ -174,17 +177,6 @@ class TestCase(unittest.TestCase): """Override flag variables for a test.""" for k, v in kw.iteritems(): FLAGS.set_override(k, v) - self._overridden_opts.append(k) - - def reset_flags(self): - """Resets all flag variables for the test. - - Runs after each test. - - """ - for k in self._overridden_opts: - FLAGS.set_override(k, None) - self._overridden_opts = [] def start_service(self, name, host=None, **kwargs): host = host and host or uuid.uuid4().hex diff --git a/cinder/tests/__init__.py b/cinder/tests/__init__.py index 82532bf04..3b5e43e05 100644 --- a/cinder/tests/__init__.py +++ b/cinder/tests/__init__.py @@ -64,6 +64,7 @@ def setup(): from cinder.db import migration from cinder.tests import fake_flags + fake_flags.set_defaults(FLAGS) if FLAGS.sql_connection == "sqlite://": if migration.db_version() > 1: diff --git a/cinder/tests/fake_flags.py b/cinder/tests/fake_flags.py index 89d0f84f7..c4abf41cf 100644 --- a/cinder/tests/fake_flags.py +++ b/cinder/tests/fake_flags.py @@ -20,15 +20,18 @@ from cinder import flags FLAGS = flags.FLAGS -flags.DECLARE('volume_driver', 'cinder.volume.manager') -FLAGS.set_default('volume_driver', 'cinder.volume.driver.FakeISCSIDriver') -FLAGS.set_default('connection_type', 'fake') -FLAGS.set_default('fake_rabbit', True) -FLAGS.set_default('rpc_backend', 'cinder.rpc.impl_fake') flags.DECLARE('iscsi_num_targets', 'cinder.volume.driver') -FLAGS.set_default('iscsi_num_targets', 8) -FLAGS.set_default('verbose', True) -FLAGS.set_default('sql_connection', "sqlite://") -FLAGS.set_default('sqlite_synchronous', False) flags.DECLARE('policy_file', 'cinder.policy') -FLAGS.set_default('policy_file', 'cinder/tests/policy.json') +flags.DECLARE('volume_driver', 'cinder.volume.manager') + + +def set_defaults(conf): + conf.set_default('volume_driver', 'cinder.volume.driver.FakeISCSIDriver') + conf.set_default('connection_type', 'fake') + conf.set_default('fake_rabbit', True) + conf.set_default('rpc_backend', 'cinder.rpc.impl_fake') + conf.set_default('iscsi_num_targets', 8) + conf.set_default('verbose', True) + conf.set_default('sql_connection', "sqlite://") + conf.set_default('sqlite_synchronous', False) + conf.set_default('policy_file', 'cinder/tests/policy.json') diff --git a/cinder/tests/test_flags.py b/cinder/tests/test_flags.py index 704966c81..267380bd0 100644 --- a/cinder/tests/test_flags.py +++ b/cinder/tests/test_flags.py @@ -96,7 +96,7 @@ class FlagsTestCase(test.TestCase): self.assertEqual(FLAGS.flags_unittest, 'foo') self.flags(flags_unittest='bar') self.assertEqual(FLAGS.flags_unittest, 'bar') - self.reset_flags() + FLAGS.reset() self.assertEqual(FLAGS.flags_unittest, 'foo') def test_defaults(self):