summaryrefslogtreecommitdiffstats
path: root/nova/test.py
diff options
context:
space:
mode:
authorAndy Smith <code@term.ie>2010-10-15 17:37:26 +0900
committerAndy Smith <code@term.ie>2010-10-15 17:37:26 +0900
commite0ae19c7a911d742a7b82f90bac0fa86757eaeae (patch)
tree923380dff02389dbd23ba0fda1f8038d3c1417b1 /nova/test.py
parentaec330b34def7158f590ce855d0cd4ff5d0ed41c (diff)
downloadnova-e0ae19c7a911d742a7b82f90bac0fa86757eaeae.tar.gz
nova-e0ae19c7a911d742a7b82f90bac0fa86757eaeae.tar.xz
nova-e0ae19c7a911d742a7b82f90bac0fa86757eaeae.zip
prevent leakage of FLAGS changes across tests
Diffstat (limited to 'nova/test.py')
-rw-r--r--nova/test.py56
1 files changed, 27 insertions, 29 deletions
diff --git a/nova/test.py b/nova/test.py
index b9ea36e1d..dab3dcf41 100644
--- a/nova/test.py
+++ b/nova/test.py
@@ -22,9 +22,9 @@ Allows overriding of flags for use of fakes,
and some black magic for inline callbacks.
"""
+import datetime
import sys
import time
-import datetime
import mox
import stubout
@@ -80,30 +80,33 @@ class TrialTestCase(unittest.TestCase):
self.flag_overrides = {}
self.injected = []
self._monkeyPatchAttach()
+ self._original_flags = FLAGS.FlagValuesDict()
def tearDown(self): # pylint: disable-msg=C0103
"""Runs after each test method to finalize/tear down test environment"""
- self.reset_flags()
- self.mox.UnsetStubs()
- self.stubs.UnsetAll()
- self.stubs.SmartUnsetAll()
- self.mox.VerifyAll()
- # NOTE(vish): Clean up any ips associated during the test.
- ctxt = context.get_admin_context()
- db.fixed_ip_disassociate_all_by_timeout(ctxt, FLAGS.host, self.start)
- db.network_disassociate_all(ctxt)
- rpc.Consumer.attach_to_twisted = self.originalAttach
- for x in self.injected:
- try:
- x.stop()
- except AssertionError:
- pass
-
- if FLAGS.fake_rabbit:
- fakerabbit.reset_all()
- db.security_group_destroy_all(ctxt)
-
- super(TrialTestCase, self).tearDown()
+ try:
+ self.mox.UnsetStubs()
+ self.stubs.UnsetAll()
+ self.stubs.SmartUnsetAll()
+ self.mox.VerifyAll()
+ # NOTE(vish): Clean up any ips associated during the test.
+ ctxt = context.get_admin_context()
+ db.fixed_ip_disassociate_all_by_timeout(ctxt, FLAGS.host, self.start)
+ db.network_disassociate_all(ctxt)
+ rpc.Consumer.attach_to_twisted = self.originalAttach
+ for x in self.injected:
+ try:
+ x.stop()
+ except AssertionError:
+ pass
+
+ if FLAGS.fake_rabbit:
+ fakerabbit.reset_all()
+
+ db.security_group_destroy_all(ctxt)
+ super(TrialTestCase, self).tearDown()
+ finally:
+ self.reset_flags()
def flags(self, **kw):
"""Override flag variables for a test"""
@@ -117,7 +120,8 @@ class TrialTestCase(unittest.TestCase):
def reset_flags(self):
"""Resets all flag variables for the test. Runs after each test"""
- for k, v in self.flag_overrides.iteritems():
+ FLAGS.Reset()
+ for k, v in self._original_flags.iteritems():
setattr(FLAGS, k, v)
def run(self, result=None):
@@ -171,12 +175,6 @@ class BaseTestCase(TrialTestCase):
self._done_waiting = False
self._timed_out = False
- def tearDown(self):# pylint: disable-msg=C0103
- """Runs after each test method to finalize/tear down test environment"""
- super(BaseTestCase, self).tearDown()
- if FLAGS.fake_rabbit:
- fakerabbit.reset_all()
-
def _wait_for_test(self, timeout=60):
""" Push the ioloop along to wait for our test to complete. """
self._waiting = self.ioloop.add_timeout(time.time() + timeout,