From 222b23500cd5ca10b71977dcdd3ad13905938c0b Mon Sep 17 00:00:00 2001 From: chengli3 Date: Thu, 18 Apr 2019 12:10:29 +0800 Subject: [PATCH] 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 --- sysinv/sysinv/sysinv/sysinv/common/utils.py | 12 ++++++++++++ sysinv/sysinv/sysinv/sysinv/helm/neutron.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sysinv/sysinv/sysinv/sysinv/common/utils.py b/sysinv/sysinv/sysinv/sysinv/common/utils.py index e3fd3cb566..e5db4b0d04 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/utils.py +++ b/sysinv/sysinv/sysinv/sysinv/common/utils.py @@ -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 diff --git a/sysinv/sysinv/sysinv/sysinv/helm/neutron.py b/sysinv/sysinv/sysinv/sysinv/helm/neutron.py index ded2374e46..0345535065 100644 --- a/sysinv/sysinv/sysinv/sysinv/helm/neutron.py +++ b/sysinv/sysinv/sysinv/sysinv/helm/neutron.py @@ -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': {