]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use cfg's new behavior of reset() clearing overrides
authorMark McLoughlin <markmc@redhat.com>
Mon, 16 Jul 2012 20:10:17 +0000 (21:10 +0100)
committerJenkins <jenkins@review.openstack.org>
Wed, 18 Jul 2012 17:04:05 +0000 (17:04 +0000)
Cherry-picks b858108 from Nova.

Change-Id: I5e14dea25afd5bff03a39671b2d3b85481977bec
Reviewed-on: https://review.openstack.org/9868
Reviewed-by: Huang Zhiteng <zhiteng.huang@intel.com>
Reviewed-by: Vish Ishaya <vishvananda@gmail.com>
Approved: John Griffith <john.griffith@solidfire.com>
Tested-by: Jenkins
cinder/test.py
cinder/tests/__init__.py
cinder/tests/fake_flags.py
cinder/tests/test_flags.py

index fb88c89c0f047fc6c004c1ec7ca9d7b38ef42ca7..ef9ccce9e7874e76f022b6c5cc858403e75a0710 100644 (file)
@@ -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
index 82532bf04af7a3ee9045be55a2b1415dc0ef4890..3b5e43e05640197f8be842ccb4f1b22a38fa5629 100644 (file)
@@ -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:
index 89d0f84f7886f2ecb1db194f8220b8d1661c704e..c4abf41cfdbe79804a8daab0ec20dd141f4adbdc 100644 (file)
@@ -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')
index 704966c8156d2cd6a13fa97c6d6bdc4796a418d8..267380bd000e3fdbddab92dd3698f7c101e80a8e 100644 (file)
@@ -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):