Skip to content

Commit cd45cea

Browse files
authored
Fix delete notation merge where no variables are used (#467)
* if delete notation affects previous model, just delete key from dict during merge * update readme for change in functionality
1 parent fc909e3 commit cd45cea

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -305,25 +305,29 @@ If variable properties are used in element names, such as ```@@PROP:my-server@@`
305305

306306
#### Multiple Models and Delete Notation
307307

308-
A named element using [delete notation](#declaring-named-mbeans-to-delete) will completely replace an element with a matching name and no delete notation in a previous model. For example, if Model 1 looks like:
308+
A named element using [delete notation](#declaring-named-mbeans-to-delete) will completely delete an element with a matching name and no delete notation in a previous model. For example, if Model 1 looks like:
309309
```yaml
310310
topology:
311311
Server:
312312
m1:
313313
ListenPort: 7000
314314
Notes: "Server 1"
315+
m2:
316+
ListenPort: 9000
315317
```
316318
and Model 2 looks like:
317319
```yaml
318320
topology:
319321
Server:
320-
!m1:
322+
!m2:
321323
```
322324
The resulting model would be:
323325
```yaml
324326
topology:
325327
Server:
326-
!m1:
328+
m1:
329+
ListenPort: 7000
330+
Notes: "Server 1"
327331
```
328332

329333
Similarly, an element without delete notation will completely replace an element with a matching name that has delete notation in a previous model. For example, if Model 1 looks like:

core/src/main/python/deploy.py

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4646
from wlsdeploy.util.model import Model
4747
from wlsdeploy.util.model_context import ModelContext
48-
from wlsdeploy.util.model_translator import FileToPython
4948
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5049

5150
wlst_extended.wlst_functions = globals()

core/src/main/python/wlsdeploy/util/cla_helper.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def _merge_dictionaries(dictionary, new_dictionary, variable_map):
150150
# the new key should replace the existing one - delete the existing key and add the new one
151151
elif replace_key:
152152
del dictionary[dictionary_key]
153-
dictionary[new_key] = new_value
153+
if not deployer_utils.is_delete_name(new_key):
154+
dictionary[new_key] = new_value
154155

155156
# the key is in both dictionaries - merge if the values are dictionaries, otherwise replace the value
156157
else:
@@ -175,16 +176,15 @@ def _find_dictionary_merge_key(dictionary, new_key, variable_map):
175176
if new_key in dictionary:
176177
return new_key, False
177178

178-
if variable_map is not None:
179-
new_is_delete = deployer_utils.is_delete_name(new_key)
180-
match_new_key = _get_merge_match_key(new_key, variable_map)
179+
new_is_delete = deployer_utils.is_delete_name(new_key)
180+
match_new_key = _get_merge_match_key(new_key, variable_map)
181181

182-
for dictionary_key in dictionary.keys():
183-
dictionary_is_delete = deployer_utils.is_delete_name(dictionary_key)
184-
match_dictionary_key = _get_merge_match_key(dictionary_key, variable_map)
185-
if match_dictionary_key == match_new_key:
186-
replace_key = new_is_delete != dictionary_is_delete
187-
return dictionary_key, replace_key
182+
for dictionary_key in dictionary.keys():
183+
dictionary_is_delete = deployer_utils.is_delete_name(dictionary_key)
184+
match_dictionary_key = _get_merge_match_key(dictionary_key, variable_map)
185+
if match_dictionary_key == match_new_key:
186+
replace_key = new_is_delete != dictionary_is_delete
187+
return dictionary_key, replace_key
188188

189189
return None, False
190190

@@ -197,7 +197,11 @@ def _get_merge_match_key(key, variable_map):
197197
:param variable_map: variable map to use for substitutions
198198
:return: the key to use for matching
199199
"""
200-
match_key = variables.substitute_key(key, variable_map)
200+
if variable_map is not None:
201+
match_key = variables.substitute_key(key, variable_map)
202+
else:
203+
match_key = key
204+
201205
if deployer_utils.is_delete_name(match_key):
202206
match_key = deployer_utils.get_delete_item_name(match_key)
203207
return match_key

core/src/test/python/wlsdeploy/util/cla_helper_test.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def testMergeNameToProperty(self):
9999

100100
self._check_merged_server(dictionary, '@@PROP:server1a@@')
101101

102-
# an element with delete notation should replace a base element with a matching name and no notation.
102+
# an element with delete notation should remove a base element with a matching name.
103103
def testMergeDeletedNameToName(self):
104104
dictionary = _build_model_one('m1')
105105
new_dictionary = _build_delete_model('m1')
@@ -108,8 +108,20 @@ def testMergeDeletedNameToName(self):
108108
cla_helper._merge_dictionaries(dictionary, new_dictionary, variables)
109109
# print("Merged model: " + str(dictionary))
110110

111+
servers = dictionary['Servers']
112+
self.assertEquals(0, len(servers), "there should be no servers after delete")
113+
114+
# an element with delete notation should leave a base element with a matching delete notation.
115+
def testMergeDeletedNameToDeleteName(self):
116+
dictionary = _build_delete_model('m1')
117+
new_dictionary = _build_delete_model('m1')
118+
variables = {}
119+
120+
cla_helper._merge_dictionaries(dictionary, new_dictionary, variables)
121+
# print("Merged model: " + str(dictionary))
122+
111123
server = self._check_single_server(dictionary, '!m1')
112-
self.assertEquals(0, len(server), "delete server should have no attributes")
124+
self.assertEquals(0, len(server), "server should have no attributes")
113125

114126
# an element should replace a base element with a matching name and delete notation.
115127
def testMergeNameToDeletedName(self):

0 commit comments

Comments
 (0)