Refactor zaqar/storage/utils.py to respect DRY
Refactor the code merged to fix the py34 issue, let it follow the DRY principle. Depends-on: I6da301dc4935ec8e4254d71ca93036f3d8db2bcf Change-Id: Iaa0768e795e172649787dc6d26722848b5d732ee Closes-Bug: #1584958
This commit is contained in:
parent
dd0e12513a
commit
437c2fe567
@ -34,6 +34,10 @@ class Configuration(object):
|
||||
except cfg.NoSuchOptError:
|
||||
return None
|
||||
|
||||
def __contains__(self, key):
|
||||
"""Return True if key is in local_conf."""
|
||||
return key in self.local_conf
|
||||
|
||||
def __getattr__(self, value):
|
||||
# Don't use self.local_conf to avoid reentrant call to __getattr__()
|
||||
local_conf = object.__getattribute__(self, 'local_conf')
|
||||
|
@ -48,31 +48,20 @@ 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_wrap = configuration.Configuration(conf)
|
||||
conf = copy.copy(conf_wrap)
|
||||
dynamic = True
|
||||
|
||||
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')
|
||||
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…
Reference in New Issue
Block a user