Skip to content

Commit 586541d

Browse files
authored
JIRA WDT-512 - Compare model: compare simple properties correctly; fix output comments (#801)
1 parent 01c4a0d commit 586541d

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

core/src/main/python/compare_model.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import oracle.weblogic.deploy.util.TranslateException as TranslateException
3535
from wlsdeploy.aliases import alias_utils
3636
from wlsdeploy.aliases.alias_constants import ALIAS_LIST_TYPES
37+
from wlsdeploy.aliases.alias_constants import PROPERTIES
3738
from wlsdeploy.aliases.aliases import Aliases
3839
from wlsdeploy.aliases.location_context import LocationContext
3940
from wlsdeploy.aliases.model_constants import KUBERNETES
@@ -253,15 +254,18 @@ def calculate_changed_model(self):
253254

254255
def _parse_change_path(self, path):
255256
"""
256-
Determine the location and attribute name (if specified) for the specified change path
257+
Determine the location and attribute name (if specified) for the specified change path.
258+
Include a property key for property attribute paths.
257259
:param path: delimited change path, such as "resources|JDBCSystemResource|Generic2|JdbcResource"
258-
:return: tuple - location for path, attribute name from path or None
260+
:return: tuple - (location from path, attribute name from path, property key from path)
259261
"""
260262
_method_name = '_parse_change_path'
261263

262264
location = LocationContext()
263265
attribute_name = None
266+
property_key = None
264267
name_token_next = False
268+
property_key_next = False
265269

266270
path_tokens = path.split(PATH_TOKEN)
267271
folder_names = self.aliases.get_model_section_top_level_folder_names(path_tokens[0])
@@ -279,6 +283,8 @@ def _parse_change_path(self, path):
279283
token_name = self.aliases.get_name_token(location)
280284
location.add_name_token(token_name, path_token)
281285
name_token_next = False
286+
elif property_key_next:
287+
property_key = path_token
282288
elif path_token in folder_names:
283289
location.append_location(path_token)
284290
folder_names = self.aliases.get_model_subfolder_names(location)
@@ -294,13 +300,16 @@ def _parse_change_path(self, path):
294300
location.add_name_token(token_name, "TOKEN")
295301
elif path_token in attribute_names:
296302
attribute_name = path_token
303+
attribute_type = self.aliases.get_model_attribute_type(location, attribute_name)
304+
if attribute_type == PROPERTIES:
305+
property_key_next = True
297306
name_token_next = False
298307
else:
299308
ex = exception_helper.create_compare_exception('WLSDPLY-05712', path_token, path)
300309
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
301310
raise ex
302311

303-
return location, attribute_name
312+
return location, attribute_name, property_key
304313

305314
def _add_results(self, change_paths, is_delete=False):
306315
"""
@@ -312,7 +321,7 @@ def _add_results(self, change_paths, is_delete=False):
312321
for change_path in change_paths:
313322
# change_path is the keys of changes in the piped format, such as:
314323
# resources|JDBCSystemResource|Generic2|JdbcResource|JDBCConnectionPoolParams|TestConnectionsOnReserve
315-
location, attribute_name = self._parse_change_path(change_path)
324+
location, attribute_name, property_key = self._parse_change_path(change_path)
316325
is_folder_path = attribute_name is None
317326

318327
if is_delete and not is_folder_path:
@@ -361,10 +370,13 @@ def _add_results(self, change_paths, is_delete=False):
361370
if current_folder:
362371
current_value = current_folder[key]
363372
previous_value = dictionary_utils.get_element(previous_folder, key)
364-
change_value, comment = self._get_change_info(current_value, previous_value, location, attribute_name)
373+
change_value, comment = self._get_change_info(current_value, previous_value, location, attribute_name,
374+
property_key)
365375

366376
if comment:
367-
change_folder[COMMENT_MATCH] = comment
377+
# make comment key unique, key will not appear in output
378+
comment_key = COMMENT_MATCH + comment
379+
change_folder[comment_key] = comment
368380
change_folder[key] = change_value
369381
else:
370382
change_folder[key] = None
@@ -397,13 +409,14 @@ def _add_results(self, change_paths, is_delete=False):
397409
else:
398410
pointer_dict[parent_key]['!' + app_key] = PyOrderedDict()
399411

400-
def _get_change_info(self, current_value, previous_value, location, attribute_name):
412+
def _get_change_info(self, current_value, previous_value, location, attribute_name, property_key):
401413
"""
402414
Determine the value and comment to put in the change model based on the supplied arguments.
403415
:param current_value: the current value from the new model
404416
:param previous_value: the previous value from the old model
405417
:param location: the location of the value in the model
406418
:param attribute_name: the name of the attribute, or None if this is a folder path
419+
:param property_key: a key in a property value, or None if a different type
407420
:return: a tuple with the change value and comment, either can be None
408421
"""
409422
change_value = current_value
@@ -430,6 +443,8 @@ def _get_change_info(self, current_value, previous_value, location, attribute_na
430443
current_text = ','.join(current_list)
431444
previous_text = ','.join(previous_list)
432445
comment = attribute_name + ": '" + previous_text + "' -> '" + current_text + "'"
446+
elif attribute_type == PROPERTIES:
447+
comment = property_key + ": '" + str(previous_value) + "'"
433448
elif not isinstance(previous_value, dict):
434449
comment = attribute_name + ": '" + str(previous_value) + "'"
435450

core/src/test/python/compare_model_test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def testCompareModelFull2(self):
312312

313313
self.assertEqual(return_code, 0)
314314

315-
def _testCompareModelFull3(self):
315+
def testCompareModelFull3(self):
316316
_method_name = 'testCompareModelFull3'
317317
# This test for
318318
# 1. Changing MailSessionProperty
@@ -321,8 +321,8 @@ def _testCompareModelFull3(self):
321321
# 4. Changing ODL Logger attributes
322322

323323
_variables_file = self._resources_dir + '/compare_model_model1.10.properties'
324-
_new_model_file = self._resources_dir + '/compare_model_model7.yaml'
325-
_old_model_file = self._resources_dir + '/compare_model_model6.yaml'
324+
_new_model_file = self._resources_dir + '/compare_model_model8.yaml'
325+
_old_model_file = self._resources_dir + '/compare_model_model7.yaml'
326326
_temp_dir = os.path.join(tempfile.gettempdir(), _method_name)
327327

328328
if os.path.exists(_temp_dir):
@@ -359,10 +359,11 @@ def _testCompareModelFull3(self):
359359
self.assertEqual(model_dictionary.has_key('resources'), True)
360360
self.assertEqual(model_dictionary['resources'].has_key('MailSession'), True)
361361
self.assertEqual(model_dictionary['resources']['MailSession'].has_key('MyMailSession'), True)
362-
self.assertEqual(model_dictionary['resources']['MailSession']['MyMailSession'].has_key('mail.imap.port'),
363-
True)
364-
self.assertEqual(model_dictionary['resources']['MailSession']['MyMailSession']['mail.imap.port'], 993)
365-
self.assertEqual(len(model_dictionary['resources']['MailSession']['MyMailSession']['mail.imap.port']), 1)
362+
363+
mail_session = model_dictionary['resources']['MailSession']['MyMailSession']
364+
self.assertEqual(mail_session.has_key('Properties'), True)
365+
self.assertEqual(mail_session['Properties'].has_key('mail.imap.port'), True)
366+
self.assertEqual(mail_session['Properties']['mail.imap.port'], 993)
366367

367368
self.assertEqual(model_dictionary['resources'].has_key('ODLConfiguration'), True)
368369
self.assertEqual(model_dictionary['resources']['ODLConfiguration'].has_key('config'), True)

0 commit comments

Comments
 (0)