Fix parameter merging with merge strategies
Earlier users had to specify merge strategy for a parameter/parameter_default in every environment file where they are used(or the defaults for that environment was used). However, the strategy for a parameter in the first environment was ignored as there is nothing to merge. With Iec3367667248d0b46196a6d569f3cbb3b200d842, we changed to use existing merge strategies, but the strategies in the first environment were still ignored. This patch fixes it. Task: 45578 Change-Id: Ic6125c6af60c1007243523cc8510a17f49c7b5af
This commit is contained in:
parent
567615f6fc
commit
d9fe7301b3
@ -113,24 +113,26 @@ def merge_parameters(old, new, param_schemata, strategies_in_file,
|
||||
raise exception.InvalidMergeStrategyForParam(strategy=MERGE,
|
||||
param=p_key)
|
||||
|
||||
new_strategies = {}
|
||||
|
||||
if not old:
|
||||
return new, new_strategies
|
||||
|
||||
for key, value in new.items():
|
||||
# if key not in param_schemata ignore it
|
||||
if key in param_schemata and value is not None:
|
||||
param_merge_strategy = get_param_merge_strategy(
|
||||
strategies_in_file, key, available_strategies)
|
||||
if key not in available_strategies:
|
||||
new_strategies[key] = param_merge_strategy
|
||||
available_strategies[key] = param_merge_strategy
|
||||
|
||||
elif param_merge_strategy != available_strategies[key]:
|
||||
raise exception.ConflictingMergeStrategyForParam(
|
||||
strategy=param_merge_strategy,
|
||||
param=key, env_file=env_file)
|
||||
|
||||
if not old:
|
||||
return new
|
||||
|
||||
for key, value in new.items():
|
||||
# if key not in param_schemata ignore it
|
||||
if key in param_schemata and value is not None:
|
||||
param_merge_strategy = available_strategies[key]
|
||||
if param_merge_strategy == DEEP_MERGE:
|
||||
LOG.debug("Deep Merging Parameter: %s", key)
|
||||
param_merge(key, value,
|
||||
@ -143,7 +145,7 @@ def merge_parameters(old, new, param_schemata, strategies_in_file,
|
||||
LOG.debug("Overriding Parameter: %s", key)
|
||||
old[key] = value
|
||||
|
||||
return old, new_strategies
|
||||
return old
|
||||
|
||||
|
||||
def merge_environments(environment_files, files,
|
||||
@ -181,11 +183,10 @@ def merge_environments(environment_files, files,
|
||||
if section_value:
|
||||
if section_key in (env_fmt.PARAMETERS,
|
||||
env_fmt.PARAMETER_DEFAULTS):
|
||||
params[section_key], new_strategies = merge_parameters(
|
||||
params[section_key] = merge_parameters(
|
||||
params[section_key], section_value,
|
||||
param_schemata, strategies_in_file,
|
||||
available_strategies, filename)
|
||||
available_strategies.update(new_strategies)
|
||||
else:
|
||||
params[section_key] = merge_map(params[section_key],
|
||||
section_value)
|
||||
|
@ -135,7 +135,7 @@ class TestMergeEnvironments(common.HeatTestCase):
|
||||
|
||||
def test_merge_envs_with_specified_default(self):
|
||||
merge_strategies = {'default': 'deep_merge'}
|
||||
self.env_2['parameter_merge_strategies'] = merge_strategies
|
||||
self.env_1['parameter_merge_strategies'] = merge_strategies
|
||||
files = {'env_1': json.dumps(self.env_1),
|
||||
'env_2': json.dumps(self.env_2)}
|
||||
environment_files = ['env_1', 'env_2']
|
||||
@ -169,7 +169,7 @@ class TestMergeEnvironments(common.HeatTestCase):
|
||||
'lst_value2': 'merge',
|
||||
'json_value1': 'deep_merge'}
|
||||
|
||||
self.env_2['parameter_merge_strategies'] = merge_strategies
|
||||
self.env_1['parameter_merge_strategies'] = merge_strategies
|
||||
|
||||
files = {'env_1': json.dumps(self.env_1),
|
||||
'env_2': json.dumps(self.env_2)}
|
||||
@ -207,7 +207,7 @@ class TestMergeEnvironments(common.HeatTestCase):
|
||||
'lst_value1': "deep_merge",
|
||||
'json_value1': "merge"}
|
||||
|
||||
self.env_2['parameter_merge_strategies'] = merge_strategies
|
||||
self.env_1['parameter_merge_strategies'] = merge_strategies
|
||||
self.env_3['parameter_merge_strategies'] = env3_merge_strategies
|
||||
|
||||
files = {'env_1': json.dumps(self.env_1),
|
||||
@ -231,7 +231,7 @@ class TestMergeEnvironments(common.HeatTestCase):
|
||||
'default': "overwrite",
|
||||
'lst_value2': "overwrite"}
|
||||
|
||||
self.env_2['parameter_merge_strategies'] = merge_strategies
|
||||
self.env_1['parameter_merge_strategies'] = merge_strategies
|
||||
self.env_4['parameter_merge_strategies'] = env4_merge_strategies
|
||||
|
||||
files = {'env_1': json.dumps(self.env_1),
|
||||
@ -275,9 +275,9 @@ class TestMergeEnvironments(common.HeatTestCase):
|
||||
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}},
|
||||
env1 = {'parameter_defaults': {'value1': {'foo': 1}},
|
||||
'parameter_merge_strategies': {'value1': 'deep_merge'}}
|
||||
env2 = {'parameter_defaults': {'value1': {'foo': 0}}}
|
||||
files = {'env_1': json.dumps(env1),
|
||||
'env_2': json.dumps(env2)}
|
||||
environment_files = ['env_1', 'env_2']
|
||||
|
Loading…
Reference in New Issue
Block a user