From 2749bb9138f5946d1ef3030c7fe349fbd5920139 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Sat, 8 Feb 2014 16:42:08 -0500 Subject: [PATCH] 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 --- nova/utils.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/nova/utils.py b/nova/utils.py index 008348c1eed8..65d99aa3f1ff 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -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):