Skip to content

Commit bb224f9

Browse files
Wdt 433 compare model validation (#683)
* Fix validation message by creating copy of model context * Fix location of status variable
1 parent 80ea8b4 commit bb224f9

File tree

5 files changed

+170
-19
lines changed

5 files changed

+170
-19
lines changed

core/src/main/python/compare_model.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,13 @@ def compare(self):
443443
# references a file in an archive, the compareModel will fail if
444444
# running in the stricter tool mode (even with lax).
445445
#
446-
return_code = validator.validate_in_standalone_mode(model_dictionary,
447-
None,
448-
archive_file_name=None)
446+
arg_map = dict()
447+
arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = model_file_name
448+
model_context_copy = self.model_context.copy(arg_map)
449+
val_copy = Validator(model_context_copy, aliases, wlst_mode=WlstModes.OFFLINE)
450+
return_code = val_copy.validate_in_standalone_mode(model_dictionary,
451+
None,
452+
archive_file_name=None)
449453

450454
if return_code == Validator.ReturnCode.STOP:
451455
_logger.severe('WLSDPLY-05705', model_file_name)
@@ -457,9 +461,12 @@ def compare(self):
457461
model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map)
458462
variables.substitute(model_dictionary, variable_map, self.model_context)
459463

460-
return_code = validator.validate_in_tool_mode(model_dictionary,
461-
variables_file_name=None,
462-
archive_file_name=None)
464+
arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = model_file_name
465+
model_context_copy = self.model_context.copy(arg_map)
466+
val_copy = Validator(model_context_copy, aliases, wlst_mode=WlstModes.OFFLINE)
467+
return_code = val_copy.validate_in_standalone_mode(model_dictionary,
468+
None,
469+
archive_file_name=None)
463470

464471
if return_code == Validator.ReturnCode.STOP:
465472
_logger.severe('WLSDPLY-05705', model_file_name)

core/src/main/python/wlsdeploy/tool/validate/validator.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def validate_in_standalone_mode(self, model_dict, variable_map, archive_file_nam
116116

117117
# If standalone, log file will not be passed, so get a new logger with correct mode type
118118
self._validation_mode = _ValidationModes.STANDALONE
119+
return_code = Validator.ReturnCode.STOP
119120
self._logger = ValidatorLogger(self._logger.get_name(), _ValidationModes.from_value(self._validation_mode))
120121
self._logger.entering(archive_file_name, class_name=_class_name, method_name=_method_name)
121122

@@ -128,7 +129,20 @@ def validate_in_standalone_mode(self, model_dict, variable_map, archive_file_nam
128129
self._logger.entering(archive_file_name, class_name=_class_name, method_name=_method_name)
129130
self.__validate_model_file(cloned_model_dict, variable_map, archive_file_name)
130131

131-
self._logger.exiting(class_name=_class_name, method_name=_method_name)
132+
status = Validator.ValidationStatus.VALID
133+
summary_handler = SummaryHandler.findInstance()
134+
if summary_handler is not None:
135+
summary_level = summary_handler.getMaximumMessageLevel()
136+
if summary_level == Level.SEVERE:
137+
status = Validator.ValidationStatus.INVALID
138+
elif summary_level == Level.WARNING:
139+
status = Validator.ValidationStatus.WARNINGS_INVALID
140+
141+
if status == Validator.ValidationStatus.VALID or status == Validator.ValidationStatus.INFOS_VALID \
142+
or status == Validator.ValidationStatus.WARNINGS_INVALID:
143+
return_code = Validator.ReturnCode.PROCEED
144+
self._logger.exiting(class_name=_class_name, method_name=_method_name, result=return_code)
145+
return return_code
132146

133147
def validate_in_tool_mode(self, model_dict, variables_file_name=None, archive_file_name=None):
134148
"""

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

Lines changed: 111 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5+
6+
import copy
57
import os
68
import tempfile
79

@@ -88,6 +90,17 @@ def __init__(self, program_name, arg_map):
8890

8991
self._trailing_args = []
9092

93+
if self._wl_version is None:
94+
self._wl_version = self._wls_helper.get_actual_weblogic_version()
95+
96+
if self._wlst_mode is None:
97+
self._wlst_mode = WlstModes.OFFLINE
98+
99+
self.__copy_from_args(arg_map)
100+
101+
return
102+
103+
def __copy_from_args(self, arg_map):
91104
if CommandLineArgUtil.ORACLE_HOME_SWITCH in arg_map:
92105
self._oracle_home = arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH]
93106
self._wl_home = self._wls_helper.get_weblogic_home(self._oracle_home)
@@ -200,10 +213,13 @@ def __init__(self, program_name, arg_map):
200213

201214
if CommandLineArgUtil.TARGET_MODE_SWITCH in arg_map:
202215
wlst_mode_string = arg_map[CommandLineArgUtil.TARGET_MODE_SWITCH]
203-
if wlst_mode_string.lower() == 'online':
204-
self._wlst_mode = WlstModes.ONLINE
216+
if type(wlst_mode_string) == int:
217+
self._wlst_mode = wlst_mode_string
205218
else:
206-
self._wlst_mode = WlstModes.OFFLINE
219+
if wlst_mode_string.lower() == 'online':
220+
self._wlst_mode = WlstModes.ONLINE
221+
else:
222+
self._wlst_mode = WlstModes.OFFLINE
207223

208224
if CommandLineArgUtil.OUTPUT_DIR_SWITCH in arg_map:
209225
self._output_dir = arg_map[CommandLineArgUtil.OUTPUT_DIR_SWITCH]
@@ -217,13 +233,91 @@ def __init__(self, program_name, arg_map):
217233
if CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH in arg_map:
218234
self._variable_properties_file = arg_map[CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH]
219235

220-
if self._wl_version is None:
221-
self._wl_version = self._wls_helper.get_actual_weblogic_version()
222-
223-
if self._wlst_mode is None:
224-
self._wlst_mode = WlstModes.OFFLINE
225-
226-
return
236+
def __copy__(self):
237+
arg_map = dict()
238+
if self._oracle_home is not None:
239+
arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH] = self._oracle_home
240+
if self._java_home is not None:
241+
arg_map[CommandLineArgUtil.JAVA_HOME_SWITCH] = self._java_home
242+
if self._domain_home is not None:
243+
arg_map[CommandLineArgUtil.DOMAIN_HOME_SWITCH] = self._domain_home
244+
if self._domain_parent_dir is not None:
245+
arg_map[CommandLineArgUtil.DOMAIN_PARENT_SWITCH] = self._domain_parent_dir
246+
if self._domain_type is not None:
247+
arg_map[CommandLineArgUtil.DOMAIN_TYPE_SWITCH] = self._domain_type
248+
if self._admin_url is not None:
249+
arg_map[CommandLineArgUtil.ADMIN_URL_SWITCH] = self._admin_url
250+
if self._admin_user is not None:
251+
arg_map[CommandLineArgUtil.ADMIN_USER_SWITCH] = self._admin_user
252+
if self._admin_password is not None:
253+
arg_map[CommandLineArgUtil.ADMIN_PASS_SWITCH] = self._admin_password
254+
if self._archive_file_name is not None:
255+
arg_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH] = self._archive_file_name
256+
if self._model_file is not None:
257+
arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = self._model_file
258+
if self._previous_model_file is not None:
259+
arg_map[CommandLineArgUtil.PREVIOUS_MODEL_FILE_SWITCH] = self._previous_model_file
260+
if self._attributes_only is not None:
261+
arg_map[CommandLineArgUtil.ATTRIBUTES_ONLY_SWITCH] = self._attributes_only
262+
if self._folders_only is not None:
263+
arg_map[CommandLineArgUtil.FOLDERS_ONLY_SWITCH] = self._folders_only
264+
if self._recursive is not None:
265+
arg_map[CommandLineArgUtil.RECURSIVE_SWITCH] = self._recursive
266+
if self._variable_file_name is not None:
267+
arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = self._variable_file_name
268+
if self._run_rcu is not None:
269+
arg_map[CommandLineArgUtil.RUN_RCU_SWITCH]= self._run_rcu
270+
if self._rcu_database is not None:
271+
arg_map[CommandLineArgUtil.RCU_DB_SWITCH] = self._rcu_database
272+
if self._rcu_prefix is not None:
273+
arg_map[CommandLineArgUtil.RCU_PREFIX_SWITCH] = self._rcu_prefix
274+
if self._rcu_sys_pass is not None:
275+
arg_map[CommandLineArgUtil.RCU_SYS_PASS_SWITCH] = self._rcu_sys_pass
276+
if self._rcu_db_user is not None:
277+
arg_map[CommandLineArgUtil.RCU_DB_USER_SWITCH] = self._rcu_db_user
278+
if self._rcu_schema_pass is not None:
279+
arg_map[CommandLineArgUtil.RCU_SCHEMA_PASS_SWITCH] = self._rcu_schema_pass
280+
if self._domain_typedef is not None:
281+
arg_map[CommandLineArgUtil.DOMAIN_TYPEDEF] = self._domain_typedef
282+
if self._encryption_passphrase is not None:
283+
arg_map[CommandLineArgUtil.PASSPHRASE_SWITCH] = self._encryption_passphrase
284+
if self._encrypt_manual is not None:
285+
arg_map[CommandLineArgUtil.ENCRYPT_MANUAL_SWITCH] = self._encrypt_manual
286+
if self._encrypt_one_pass is not None:
287+
arg_map[CommandLineArgUtil.ONE_PASS_SWITCH] = self._encrypt_one_pass
288+
if self._rollback_if_restart_required is not None:
289+
arg_map[CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH] = self._rollback_if_restart_required
290+
if self._use_encryption is not None:
291+
arg_map[CommandLineArgUtil.USE_ENCRYPTION_SWITCH] = self._use_encryption
292+
if self._archive_file is not None:
293+
arg_map[CommandLineArgUtil.ARCHIVE_FILE] = self._archive_file
294+
if self._opss_wallet_passphrase is not None:
295+
arg_map[CommandLineArgUtil.OPSS_WALLET_PASSPHRASE] = self._opss_wallet_passphrase
296+
if self._opss_wallet is not None:
297+
arg_map[CommandLineArgUtil.OPSS_WALLET_SWITCH] = self._opss_wallet
298+
if self._update_rcu_schema_pass is not None:
299+
arg_map[CommandLineArgUtil.UPDATE_RCU_SCHEMA_PASS_SWITCH] = self._update_rcu_schema_pass
300+
if self._validation_method is not None:
301+
arg_map[CommandLineArgUtil.VALIDATION_METHOD] = self._validation_method
302+
if self._wl_version is not None:
303+
arg_map[CommandLineArgUtil.TARGET_VERSION_SWITCH] = self._wl_version
304+
if self._domain_resource_file is not None:
305+
arg_map[CommandLineArgUtil.DOMAIN_RESOURCE_FILE_SWITCH] = self._domain_resource_file
306+
if self._trailing_args is not None:
307+
arg_map[CommandLineArgUtil.TRAILING_ARGS_SWITCH] = self._trailing_args
308+
if self._target is not None:
309+
arg_map[CommandLineArgUtil.TARGET_SWITCH] = self._target
310+
if self._wlst_mode is not None:
311+
arg_map[CommandLineArgUtil.TARGET_MODE_SWITCH] = self._wlst_mode
312+
if self._output_dir is not None:
313+
arg_map[CommandLineArgUtil.OUTPUT_DIR_SWITCH] = self._output_dir
314+
if self._variable_injector_file is not None:
315+
arg_map[CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH] = self._variable_injector_file
316+
if self._variable_keywords_file is not None:
317+
arg_map[CommandLineArgUtil.VARIABLE_KEYWORDS_FILE_SWITCH] = self._variable_keywords_file
318+
if self._variable_properties_file is not None:
319+
arg_map[CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH] = self._variable_properties_file
320+
return ModelContext(self._program_name, arg_map)
227321

228322
def get_program_name(self):
229323
"""
@@ -761,6 +855,11 @@ def tokenize_classpath(self, classpath):
761855

762856
return separator.join(cp_elements)
763857

858+
def copy(self, arg_map):
859+
model_context_copy = copy.copy(self)
860+
model_context_copy.__copy_from_args(arg_map)
861+
return model_context_copy
862+
764863
# private methods
765864

766865

@@ -778,3 +877,4 @@ def _replace(string_value, token, replace_token_string):
778877
else:
779878
result = string_value.replace(token, replace_token_string)
780879
return result
880+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Copyright (c) 2020, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
"""
5+
import unittest
6+
7+
from wlsdeploy.util.cla_utils import CommandLineArgUtil
8+
from wlsdeploy.util.model_context import ModelContext
9+
10+
11+
class ClaHelperTest(unittest.TestCase):
12+
13+
def testCopyModelContext(self):
14+
__program_name = 'model_context_test'
15+
__oracle_home = '/my/oracle/home'
16+
__model_file = 'my_model_file.yaml'
17+
18+
arg_map = dict()
19+
arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH] = __oracle_home
20+
model_context = ModelContext(__program_name, arg_map)
21+
self.assertEquals(model_context.get_program_name(), __program_name)
22+
self.assertEquals(model_context.get_oracle_home(), __oracle_home)
23+
self.assertEquals(model_context.get_model_file(), None)
24+
25+
arg_map = dict()
26+
arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = __model_file
27+
model_context_copy = model_context.copy(arg_map)
28+
self.assertEquals(model_context_copy.get_program_name(), __program_name)
29+
self.assertEquals(model_context_copy.get_oracle_home(), __oracle_home)
30+
self.assertEquals(model_context_copy.get_model_file(), __model_file)

core/src/test/resources/compare_model_model3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ topology:
4545
StrictOwnershipCheck: true
4646
Cluster: "cluster-2"
4747
'nosuchkey' : 'value'
48-
appDeployments:
48+
appDeployment:
4949
Application:
5050
myear:
5151
SourcePath: /home/johnny/dimtemp23/sample_app_stage/wlsdeploy/applications/sample_app.ear

0 commit comments

Comments
 (0)