Fix py34 gate job
Add a configuration wrapper to avoid reentrant call to __getattr__() in copy.copy(conf) on Python 3.x which is causing Zaqar's py34 gate job failure randomly. The code is copied from Cinder, see the similar fix in Cinder: https://review.openstack.org/#/c/280241/ Co-Authored-By: wangxiyuan<wangxiyuan@huawei.com> Co-Authored-By: Wang Hao<wanghao749@huawei.com> Change-Id: I627b96f00e5b05993b8f4f586ea216214d5f1a5f
This commit is contained in:
parent
d1491c82f8
commit
58e8429e0f
44
zaqar/storage/configuration.py
Normal file
44
zaqar/storage/configuration.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2016 HuaWei, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
class Configuration(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
"""Initialize configuration."""
|
||||
self.local_conf = conf
|
||||
|
||||
def register_opts(self, volume_opts, group=None):
|
||||
self.local_conf.register_opts(volume_opts, group=group)
|
||||
|
||||
def set_override(self, name, override, group=None, enforce_type=False):
|
||||
self.local_conf.set_override(name, override, group=group,
|
||||
enforce_type=enforce_type)
|
||||
|
||||
def safe_get(self, value):
|
||||
try:
|
||||
return self.__getattr__(value)
|
||||
except cfg.NoSuchOptError:
|
||||
return None
|
||||
|
||||
def __getattr__(self, value):
|
||||
# Don't use self.local_conf to avoid reentrant call to __getattr__()
|
||||
local_conf = object.__getattribute__(self, 'local_conf')
|
||||
return getattr(local_conf, value)
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Look up an option value and perform string substitution."""
|
||||
return self.local_conf.__getitem__(key)
|
@ -22,6 +22,7 @@ from stevedore import driver
|
||||
from zaqar.common import errors
|
||||
from zaqar.common import utils
|
||||
from zaqar.i18n import _LE
|
||||
from zaqar.storage import configuration
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -47,20 +48,31 @@ def dynamic_conf(uri, options, conf=None):
|
||||
storage_opts = utils.dict_to_conf(options)
|
||||
storage_group = u'drivers:message_store:%s' % storage_type
|
||||
|
||||
dynamic = False
|
||||
# NOTE(cpp-cabrera): register those options!
|
||||
if conf is None:
|
||||
conf = cfg.ConfigOpts()
|
||||
else:
|
||||
conf = copy.copy(conf)
|
||||
conf_wrap = configuration.Configuration(conf)
|
||||
conf = copy.copy(conf_wrap)
|
||||
dynamic = True
|
||||
|
||||
if storage_group not in conf:
|
||||
conf.register_opts(storage_opts,
|
||||
group=storage_group)
|
||||
|
||||
if 'drivers' not in conf:
|
||||
# NOTE(cpp-cabrera): parse general opts: 'drivers'
|
||||
driver_opts = utils.dict_to_conf({'message_store': storage_type})
|
||||
conf.register_opts(driver_opts, group=u'drivers')
|
||||
if dynamic:
|
||||
if not conf.safe_get(storage_group):
|
||||
conf.register_opts(storage_opts,
|
||||
group=storage_group)
|
||||
if not conf.safe_get('drivers'):
|
||||
# NOTE(cpp-cabrera): parse general opts: 'drivers'
|
||||
driver_opts = utils.dict_to_conf({'message_store': storage_type})
|
||||
conf.register_opts(driver_opts, group=u'drivers')
|
||||
else:
|
||||
if storage_group not in conf:
|
||||
conf.register_opts(storage_opts,
|
||||
group=storage_group)
|
||||
if 'drivers' not in conf:
|
||||
# NOTE(cpp-cabrera): parse general opts: 'drivers'
|
||||
driver_opts = utils.dict_to_conf({'message_store': storage_type})
|
||||
conf.register_opts(driver_opts, group=u'drivers')
|
||||
|
||||
conf.set_override('message_store', storage_type, 'drivers',
|
||||
enforce_type=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user