From 9e60df30dc648b3eebe755bf389e6c017d87b22b Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 13 Jun 2013 09:35:10 -0700 Subject: Backup and restore object registry for tests Without this, the object registry can become cluttered with test objects, which may conflict with each other, depending on the order and pairing of testr processes. Related to unified-object-model Change-Id: I77d3beebfb963cdc24c49eebb38ca8a768c69503 --- nova/test.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nova/test.py b/nova/test.py index 85ba990c0..a8af00889 100644 --- a/nova/test.py +++ b/nova/test.py @@ -26,6 +26,7 @@ inline callbacks. import eventlet eventlet.monkey_patch(os=False) +import copy import os import shutil import sys @@ -234,8 +235,12 @@ class TestCase(testtools.TestCase): self.useFixture(_DB_CACHE) # NOTE(danms): Make sure to reset us back to non-remote objects - # for each test to avoid interactions. + # for each test to avoid interactions. Also, backup the object + # registry. objects_base.NovaObject.indirection_api = None + self._base_test_obj_backup = copy.copy( + objects_base.NovaObject._obj_classes) + self.addCleanup(self._restore_obj_registry) mox_fixture = self.useFixture(MoxStubout()) self.mox = mox_fixture.mox @@ -246,6 +251,9 @@ class TestCase(testtools.TestCase): CONF.set_override('fatal_exception_format_errors', True) CONF.set_override('enabled', True, 'osapi_v3') + def _restore_obj_registry(self): + objects_base.NovaObject._obj_classes = self._base_test_obj_backup + def _clear_attrs(self): # Delete attributes that don't start with _ so they don't pin # memory around unnecessarily for the duration of the test -- cgit