From 06c0ef9bb64f11f2f73455035df958c078296d18 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Thu, 17 Apr 2014 21:01:10 +0000 Subject: [PATCH] Remove utils.reset_is_neutron() to avoid races If a unit test does not call utils.reset_is_neutron() when it is complete, it may introduce a race condition because the utils.is_neutron() value is cached to the old result. This patch removes the utils.reset_is_neutron() and instead makes sure that we never have a cached value for it. It also refactors _is_neutron out of vmwareapi.VMOps because it cache the result unnecessarily. Change-Id: I2440e308b00979b31c750513d14608808a295c33 Closes-Bug: #1309043 --- nova/test.py | 6 ++++++ nova/utils.py | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/nova/test.py b/nova/test.py index 30ed7989d..1d425f5d9 100644 --- a/nova/test.py +++ b/nova/test.py @@ -52,6 +52,7 @@ from nova import rpc from nova import service from nova.tests import conf_fixture from nova.tests import policy_fixture +from nova import utils test_opts = [ @@ -305,6 +306,11 @@ class TestCase(testtools.TestCase): objects_base.NovaObject._obj_classes) self.addCleanup(self._restore_obj_registry) + # NOTE(mnaser): All calls to utils.is_neutron() are cached in + # nova.utils._IS_NEUTRON. We set it to None to avoid any + # caching of that value. + utils._IS_NEUTRON = None + mox_fixture = self.useFixture(moxstubout.MoxStubout()) self.mox = mox_fixture.mox self.stubs = mox_fixture.stubs diff --git a/nova/utils.py b/nova/utils.py index 6630c689b..2a1d01879 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1067,11 +1067,6 @@ def is_neutron(): return _IS_NEUTRON -def reset_is_neutron(): - global _IS_NEUTRON - _IS_NEUTRON = None - - def is_auto_disk_config_disabled(auto_disk_config_raw): auto_disk_config_disabled = False if auto_disk_config_raw is not None: