Fix dict update
In python, dict.update doesn't merge dict recursive. It only merge the top level dict. In following example, {'foo1': { 'bar1': 'val1', 'bar2': 'val2'}} is expected. But {'bar1': 'val1'} is replaced by {'bar2': 'val2'} ``` >>> dict1 = {'foo1': {'bar1': 'val1'}} >>> dict1.update({'foo1': {'bar2': 'val2'}}) >>> print dict1 {'foo1': {'bar2': 'val2'}} ``` This patch is to fix the 'updates' where recursive merges are expected. Closes-bug: #1825275 Change-Id: Ib7d14c9631ce959f506ca309efb314411239ea7b Signed-off-by: chengli3 <cheng1.li@intel.com>
This commit is contained in:
parent
5070f6491b
commit
222b23500c
|
@ -1962,3 +1962,15 @@ def get_vswitch_type(dbapi):
|
|||
|
||||
def is_initial_config_complete():
|
||||
return os.path.isfile(tsc.INITIAL_CONFIG_COMPLETE_FLAG)
|
||||
|
||||
|
||||
def recur_update(orig_dict, new_dict):
|
||||
for key, val in new_dict.iteritems():
|
||||
if isinstance(val, collections.Mapping):
|
||||
tmp = recur_update(orig_dict.get(key, {}), val)
|
||||
orig_dict[key] = tmp
|
||||
elif isinstance(val, list) and isinstance(orig_dict.get(key), list):
|
||||
orig_dict[key] = orig_dict.get[key] + val
|
||||
else:
|
||||
orig_dict[key] = new_dict[key]
|
||||
return orig_dict
|
||||
|
|
|
@ -93,7 +93,7 @@ class NeutronHelm(openstack.OpenstackBaseHelm):
|
|||
|
||||
def update_dynamic_options(self, overrides):
|
||||
if utils.is_virtual():
|
||||
overrides.update({
|
||||
utils.recur_update(overrides, {
|
||||
'plugins': {
|
||||
'ml2_conf': {
|
||||
'ovs_driver': {
|
||||
|
|
Loading…
Reference in New Issue