Handle zero values when merging environments
When merging multiple envs, 0 values where ignored in later envs, not taking precedence. This fixes it by checking for None instead. Change-Id: Ia0da6988f92825bcc9a19dd3dcce771baa978a59 Closes-Bug: #1669442
This commit is contained in:
parent
a77ef39048
commit
16999806e6
@ -55,7 +55,7 @@ def merge_map(old, new, deep_merge=False):
|
|||||||
return new
|
return new
|
||||||
|
|
||||||
for k, v in new.items():
|
for k, v in new.items():
|
||||||
if v:
|
if v is not None:
|
||||||
if not deep_merge:
|
if not deep_merge:
|
||||||
old[k] = v
|
old[k] = v
|
||||||
elif isinstance(v, collections.Mapping):
|
elif isinstance(v, collections.Mapping):
|
||||||
@ -113,7 +113,7 @@ def merge_parameters(old, new, param_schemata, strategies_in_file,
|
|||||||
|
|
||||||
for key, value in new.items():
|
for key, value in new.items():
|
||||||
# if key not in param_schemata ignore it
|
# if key not in param_schemata ignore it
|
||||||
if key in param_schemata and value:
|
if key in param_schemata and value is not None:
|
||||||
param_merge_strategy = get_param_merge_strategy(
|
param_merge_strategy = get_param_merge_strategy(
|
||||||
strategies_in_file, key)
|
strategies_in_file, key)
|
||||||
if key not in available_strategies:
|
if key not in available_strategies:
|
||||||
|
@ -248,3 +248,33 @@ class TestMergeEnvironments(common.HeatTestCase):
|
|||||||
'parameter_defaults': {}}
|
'parameter_defaults': {}}
|
||||||
|
|
||||||
self.assertEqual(expected, self.params)
|
self.assertEqual(expected, self.params)
|
||||||
|
|
||||||
|
def test_merge_envs_with_zeros(self):
|
||||||
|
env1 = {'parameter_defaults': {'value1': 1}}
|
||||||
|
env2 = {'parameter_defaults': {'value1': 0}}
|
||||||
|
files = {'env_1': json.dumps(env1),
|
||||||
|
'env_2': json.dumps(env2)}
|
||||||
|
environment_files = ['env_1', 'env_2']
|
||||||
|
|
||||||
|
param_schemata = {
|
||||||
|
'value1': parameters.Schema(parameters.Schema.NUMBER)}
|
||||||
|
env_util.merge_environments(environment_files, files, self.params,
|
||||||
|
param_schemata)
|
||||||
|
|
||||||
|
self.assertEqual({'value1': 0}, self.params['parameter_defaults'])
|
||||||
|
|
||||||
|
def test_merge_envs_with_zeros_in_maps(self):
|
||||||
|
env1 = {'parameter_defaults': {'value1': {'foo': 1}}}
|
||||||
|
env2 = {'parameter_defaults': {'value1': {'foo': 0}},
|
||||||
|
'parameter_merge_strategies': {'value1': 'deep_merge'}}
|
||||||
|
files = {'env_1': json.dumps(env1),
|
||||||
|
'env_2': json.dumps(env2)}
|
||||||
|
environment_files = ['env_1', 'env_2']
|
||||||
|
|
||||||
|
param_schemata = {
|
||||||
|
'value1': parameters.Schema(parameters.Schema.MAP)}
|
||||||
|
env_util.merge_environments(environment_files, files, self.params,
|
||||||
|
param_schemata)
|
||||||
|
|
||||||
|
self.assertEqual({'value1': {'foo': 0}},
|
||||||
|
self.params['parameter_defaults'])
|
||||||
|
Loading…
Reference in New Issue
Block a user