Make is_neutron() thread-safe

The utils method is_neutron() was not thread safe and could have returned the
wrong value if two greenthreads called it at the same time.  Specifically, a
greenthread switch could occur when the import is being done.  At that point, it
looks like the check has already been completed, but the result has not yet been
recorded.

Closes-bug: #1274992
Change-Id: I5a6eedaeb4c0deee4b31509946ae5daedf98389d
This commit is contained in:
Russell Bryant 2014-02-08 16:42:08 -05:00
parent a1fe8dfd58
commit 2749bb9138

View File

@ -94,8 +94,7 @@ TIME_UNITS = {
}
_IS_NEUTRON_ATTEMPTED = False
_IS_NEUTRON = False
_IS_NEUTRON = None
synchronized = lockutils.synchronized_with_prefix('nova-')
@ -1025,10 +1024,9 @@ def convert_version_to_tuple(version_str):
def is_neutron():
global _IS_NEUTRON_ATTEMPTED
global _IS_NEUTRON
if _IS_NEUTRON_ATTEMPTED:
if _IS_NEUTRON is not None:
return _IS_NEUTRON
try:
@ -1036,7 +1034,6 @@ def is_neutron():
cls_name = CONF.network_api_class
if cls_name == 'nova.network.quantumv2.api.API':
cls_name = 'nova.network.neutronv2.api.API'
_IS_NEUTRON_ATTEMPTED = True
from nova.network.neutronv2 import api as neutron_api
_IS_NEUTRON = issubclass(importutils.import_class(cls_name),
@ -1048,11 +1045,8 @@ def is_neutron():
def reset_is_neutron():
global _IS_NEUTRON_ATTEMPTED
global _IS_NEUTRON
_IS_NEUTRON_ATTEMPTED = False
_IS_NEUTRON = False
_IS_NEUTRON = None
def is_auto_disk_config_disabled(auto_disk_config_raw):