Skip to content

Commit 3578ee9

Browse files
authored
Create validation mode for WKTUI (#1019)
* Use VariableConfiguration object methods; list all token failures; improve logging * Revised file token regexes and error checking * Use constant to set validation mode * Renumbered and re-ordered bundled messages * Throw a single exception for multiple variable substitution errors * Throw a single exception for substitution errors * Always show issue summary for validateModel * Refined logging messages * Renamed validation check methods; add wktui validation mode; check result of substitute_value * Use PlatformLogger in KubernetesValidator * Enable/disable archive reference checks in validate configuration * Revised test for validate with missing archive to expect error exit code * Log info or severe messages for missing archive entries * Correction to allow unresolved archive references for lax validation
1 parent 26404e6 commit 3578ee9

File tree

16 files changed

+305
-172
lines changed

16 files changed

+305
-172
lines changed

core/src/main/python/compare_model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
#
44
# ------------
@@ -40,6 +40,7 @@
4040
from wlsdeploy.tool.compare.model_comparer import ModelComparer
4141
from wlsdeploy.tool.validate.validator import Validator
4242
from wlsdeploy.util import cla_helper
43+
from wlsdeploy.util import validate_configuration
4344
from wlsdeploy.util import variables
4445
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4546
from wlsdeploy.util.model_context import ModelContext
@@ -75,9 +76,7 @@ def __process_args(args):
7576
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
7677
argument_map = cla_util.process_args(args, trailing_arg_count=2)
7778

78-
model_context = ModelContext(_program_name, argument_map)
79-
model_context.set_ignore_missing_archive_entries(True)
80-
return model_context
79+
return ModelContext(_program_name, argument_map)
8180

8281

8382
class ModelFileDiffer:
@@ -111,7 +110,8 @@ def compare(self):
111110
model_file_name = self.past_dict_file
112111
FileToPython(model_file_name, True).parse()
113112

114-
self.model_context.set_validation_method('lax')
113+
# allow unresolved tokens and archive entries
114+
self.model_context.set_validation_method(validate_configuration.LAX_METHOD)
115115

116116
aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE,
117117
exception_type=ExceptionType.COMPARE)

core/src/main/python/discover.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, 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
55
The entry point for the discoverDomain tool.
@@ -434,11 +434,6 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
434434
# target config always present in model context, default config if not declared
435435
target_configuration = model_context.get_target_configuration()
436436

437-
# if target config declared, use the validation method it contains (lax, etc.)
438-
if model_context.is_targetted_config():
439-
validation_method = target_configuration.get_validation_method()
440-
model_context.set_validation_method(validation_method)
441-
442437
credential_cache = None
443438
if credential_injector is not None:
444439
# filter variables or secrets that are no longer in the model

core/src/main/python/extract_resource.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
The entry point for the extractDomainResource tool.
@@ -20,6 +20,7 @@
2020
from wlsdeploy.tool.util import model_context_helper
2121
from wlsdeploy.util import cla_helper
2222
from wlsdeploy.util import tool_exit
23+
from wlsdeploy.util import validate_configuration
2324
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2425
from wlsdeploy.util.cla_utils import TOOL_TYPE_EXTRACT
2526
from wlsdeploy.util.model import Model
@@ -67,10 +68,9 @@ def __process_args(args):
6768
cla_helper.validate_variable_file_exists(_program_name, argument_map)
6869
cla_helper.process_encryption_args(argument_map)
6970

70-
argument_map[CommandLineArgUtil.VALIDATION_METHOD] = CommandLineArgUtil.LAX_VALIDATION_METHOD
71-
model_context = model_context_helper.create_context(_program_name, argument_map)
72-
model_context.set_ignore_missing_archive_entries(True)
73-
return model_context
71+
# allow unresolved tokens and archive entries
72+
argument_map[CommandLineArgUtil.VALIDATION_METHOD] = validate_configuration.LAX_METHOD
73+
return model_context_helper.create_context(_program_name, argument_map)
7474

7575

7676
def __extract_resource(model, model_context):

core/src/main/python/prepare_model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
#
44
# ------------
@@ -55,7 +55,8 @@ def __process_args(args):
5555
target_configuration_helper.process_target_arguments(argument_map)
5656

5757
model_context = ModelContext(_program_name, argument_map)
58-
model_context.set_ignore_missing_archive_entries(True)
58+
# override this check, since archive file is not supplied here
59+
model_context.get_validate_configuration().set_allow_unresolved_archive_references(True)
5960
return model_context
6061

6162

core/src/main/python/validate.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, 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
55
The WLS Deploy tooling entry point for the validateModel tool.
@@ -28,6 +28,7 @@
2828
from wlsdeploy.util import cla_helper
2929
from wlsdeploy.util import dictionary_utils
3030
from wlsdeploy.util import tool_exit
31+
from wlsdeploy.util import validate_configuration
3132
from wlsdeploy.util import variables
3233
from wlsdeploy.util.cla_utils import CommandLineArgUtil
3334
from wlsdeploy.util.weblogic_helper import WebLogicHelper
@@ -84,7 +85,7 @@ def __process_model_args(argument_map):
8485
except CLAException, ce:
8586
# in lax validation mode, if no model is found, log at INFO and exit
8687
method = dictionary_utils.get_element(argument_map, CommandLineArgUtil.VALIDATION_METHOD)
87-
if method == CommandLineArgUtil.LAX_VALIDATION_METHOD:
88+
if method == validate_configuration.LAX_METHOD:
8889
__logger.info('WLSDPLY-20032', _program_name, class_name=_class_name, method_name=_method_name)
8990
model_context = model_context_helper.create_exit_context(_program_name)
9091
tool_exit.end(model_context, CommandLineArgUtil.PROG_OK_EXIT_CODE)
@@ -131,8 +132,6 @@ def __perform_model_file_validation(model_file_name, model_context):
131132
model_context.get_archive_file_name())
132133

133134
except (TranslateException, VariableException), te:
134-
__logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(),
135-
error=te, class_name=_class_name, method_name=_method_name)
136135
ex = exception_helper.create_validate_exception(te.getLocalizedMessage(), error=te)
137136
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
138137
raise ex
@@ -167,9 +166,9 @@ def main(args):
167166
model_context = model_context_helper.create_exit_context(_program_name)
168167
tool_exit.end(model_context, exit_code)
169168

170-
try:
171-
model_file_name = model_context.get_model_file()
169+
model_file_name = model_context.get_model_file()
172170

171+
try:
173172
if model_file_name is not None:
174173
__perform_model_file_validation(model_file_name, model_context)
175174

@@ -182,10 +181,9 @@ def main(args):
182181
exit_code = CommandLineArgUtil.PROG_WARNING_EXIT_CODE
183182

184183
except ValidateException, ve:
184+
exit_code = CommandLineArgUtil.PROG_ERROR_EXIT_CODE
185185
__logger.severe('WLSDPLY-20000', _program_name, ve.getLocalizedMessage(), error=ve,
186186
class_name=_class_name, method_name=_method_name)
187-
cla_helper.clean_up_temp_files()
188-
sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
189187

190188
cla_helper.clean_up_temp_files()
191189

core/src/main/python/wlsdeploy/tool/prepare/model_preparer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2021, 2022, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
import os
@@ -199,8 +199,8 @@ def fix_property_secrets(self):
199199
credential_caches = self.credential_injector.get_variable_cache()
200200
for key in credential_caches:
201201
if variables.is_variable_string(credential_caches[key]):
202-
credential_caches[key] = variables._substitute(credential_caches[key],
203-
original_variables, self.model_context)
202+
credential_caches[key] = variables.substitute_value(credential_caches[key],
203+
original_variables, self.model_context)
204204

205205
def _apply_filter_and_inject_variable(self, model_dict, model_context):
206206
"""

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55

66
from wlsdeploy.aliases.model_constants import KUBERNETES
77
from wlsdeploy.exception.expection_types import ExceptionType
8+
from wlsdeploy.logging.platform_logger import PlatformLogger
89
from wlsdeploy.tool.extract import wko_schema_helper
9-
from wlsdeploy.tool.validate.validator_logger import ValidatorLogger
1010
from wlsdeploy.util import dictionary_utils
1111

1212

@@ -15,7 +15,7 @@ class KubernetesValidator(object):
1515
Class for validating the kubernetes section of a model file
1616
"""
1717
_class_name = 'KubernetesValidator'
18-
_logger = ValidatorLogger('wlsdeploy.validate')
18+
_logger = PlatformLogger('wlsdeploy.validate')
1919

2020
def __init__(self, model_context):
2121
self._model_context = model_context

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, 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
"""
55
import os
@@ -62,6 +62,7 @@ class Validator(object):
6262

6363
def __init__(self, model_context, aliases=None, logger=None, wlst_mode=None, domain_name='base_domain'):
6464
self._model_context = model_context
65+
self._validate_configuration = model_context.get_validate_configuration()
6566

6667
if logger is None:
6768
# No logger specified, so use the one declared at the module level
@@ -761,9 +762,9 @@ def __validate_variable_substitution(self, tokenized_value, model_folder_path):
761762
# FIXME(mwooten) - the cla_utils should be fixing all windows paths to use forward slashes already
762763
# assuming that the value is not None
763764

764-
logger_method = self._logger.info
765-
if self._model_context.get_validation_method() == 'strict':
766-
logger_method = self._logger.warning
765+
logger_method = self._logger.warning
766+
if self._validate_configuration.allow_unresolved_variable_tokens():
767+
logger_method = _info_logger.info
767768

768769
variables_file_name = self._model_context.get_variable_file()
769770
if variables_file_name is None:
@@ -821,23 +822,21 @@ def __validate_single_path_in_archive(self, path, attribute_name, model_folder_p
821822
# token to make that explicit in the model.
822823
#
823824
if WLSDeployArchive.isPathIntoArchive(path):
825+
# If the validate configuration allows unresolved archive references,
826+
# log INFO messages identifying missing entries, and allow validation to succeed.
827+
# Otherwise, log SEVERE messages that will cause validation to fail.
828+
log_method = self._logger.severe
829+
if self._validate_configuration.allow_unresolved_archive_references():
830+
log_method = _info_logger.info
831+
824832
if self._archive_helper is not None:
825833
archive_has_file = self._archive_helper.contains_file_or_path(path)
826834
if not archive_has_file:
827-
self._logger.severe('WLSDPLY-05024', attribute_name, model_folder_path, path,
828-
self._archive_file_name, class_name=_class_name, method_name=_method_name)
835+
log_method('WLSDPLY-05024', attribute_name, model_folder_path, path,
836+
self._archive_file_name, class_name=_class_name, method_name=_method_name)
829837
else:
830-
# If running in STANDALONE mode, or configured to ignore missing archive entries,
831-
# log an INFO message identifying missing entries, and allow validation to succeed.
832-
# In TOOL mode, unless the ignore flag is set, log a SEVERE message that will cause
833-
# validation to fail.
834-
ignore_missing_entries = self._model_context.get_ignore_missing_archive_entries()
835-
if self._validation_mode == _ValidationModes.STANDALONE or ignore_missing_entries:
836-
self._logger.info('WLSDPLY-05025', attribute_name, model_folder_path, path,
837-
class_name=_class_name, method_name=_method_name)
838-
elif self._validation_mode == _ValidationModes.TOOL:
839-
self._logger.severe('WLSDPLY-05025', attribute_name, model_folder_path, path,
840-
class_name=_class_name, method_name=_method_name)
838+
log_method('WLSDPLY-05025', attribute_name, model_folder_path, path,
839+
class_name=_class_name, method_name=_method_name)
841840
else:
842841
tokens = validation_utils.extract_path_tokens(path)
843842
self._logger.finest('tokens={0}', str(tokens), class_name=_class_name, method_name=_method_name)
@@ -937,14 +936,9 @@ def _report_unsupported_variable_usage(self, tokenized_value, model_folder_path)
937936
def _log_version_invalid(self, message, method_name):
938937
"""
939938
Log a message indicating that an attribute is not valid for the current WLS version and WLST mode.
940-
Log INFO if validation method is "lax", otherwise log WARNING.
939+
Log INFO or WARNING, depending on validation mode.
941940
"""
942-
if self._model_context.is_targetted_config():
943-
validation_method = self._model_context.get_target_configuration().get_validation_method()
944-
else:
945-
validation_method = self._model_context.get_validation_method()
946-
947941
log_method = self._logger.warning
948-
if validation_method == 'lax':
942+
if self._validate_configuration.allow_version_invalid_attributes():
949943
log_method = _info_logger.info
950944
log_method('WLSDPLY-05027', message, class_name=_class_name, method_name=method_name)

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, 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
55
Module that handles command-line argument parsing and common validation.
@@ -20,17 +20,19 @@
2020
from wlsdeploy.exception import exception_helper
2121
from wlsdeploy.logging.platform_logger import PlatformLogger
2222
from wlsdeploy.util import path_utils
23+
from wlsdeploy.util import validate_configuration
2324
from wlsdeploy.util.target_configuration import CREDENTIALS_METHOD
2425
from wlsdeploy.util.target_configuration import CREDENTIALS_METHODS
2526
from wlsdeploy.util.target_configuration import TargetConfiguration
27+
from wlsdeploy.util.target_configuration import VALIDATION_METHOD
28+
from wlsdeploy.util.validate_configuration import VALIDATION_METHODS
2629

2730
# tool type may indicate variations in argument processing
2831
TOOL_TYPE_CREATE = "create"
2932
TOOL_TYPE_DEFAULT = "default"
3033
TOOL_TYPE_EXTRACT = "extract"
3134

3235

33-
3436
class CommandLineArgUtil(object):
3537
"""
3638
Class that handles command-line argument parsing and common validation.
@@ -120,10 +122,6 @@ class CommandLineArgUtil(object):
120122
ARCHIVE_FILES_SEPARATOR = ','
121123
MODEL_FILES_SEPARATOR = ','
122124

123-
LAX_VALIDATION_METHOD = 'lax'
124-
STRICT_VALIDATION_METHOD = 'strict'
125-
VALIDATION_METHODS = [LAX_VALIDATION_METHOD, STRICT_VALIDATION_METHOD]
126-
127125
HELP_EXIT_CODE = 100
128126
USAGE_ERROR_EXIT_CODE = 99
129127
ARG_VALIDATION_ERROR_EXIT_CODE = 98
@@ -844,8 +842,8 @@ def _validate_validate_method_arg(self, value):
844842
ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
845843
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
846844
raise ex
847-
elif value not in self.VALIDATION_METHODS:
848-
ex = exception_helper.create_cla_exception('WLSDPLY-20030', value, self.VALIDATION_METHODS)
845+
elif value not in VALIDATION_METHODS:
846+
ex = exception_helper.create_cla_exception('WLSDPLY-20030', value, VALIDATION_METHODS)
849847
ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
850848
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
851849
raise ex
@@ -1163,8 +1161,11 @@ def _validate_target_arg(self, value):
11631161
config_dictionary = eval(file_handle.read())
11641162
target_configuration = TargetConfiguration(config_dictionary)
11651163
validation_method = target_configuration.get_validation_method()
1166-
if (validation_method is not None) and (validation_method not in self.VALIDATION_METHODS):
1167-
ex = exception_helper.create_cla_exception('WLSDPLY-01645', target_configuration_file)
1164+
if (validation_method is not None) and \
1165+
(validation_method not in validate_configuration.VALIDATION_METHODS):
1166+
ex = exception_helper.create_cla_exception('WLSDPLY-01648', target_configuration_file,
1167+
validation_method, VALIDATION_METHOD,
1168+
', '.join(validate_configuration.VALIDATION_METHODS))
11681169
ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
11691170
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
11701171
raise ex

0 commit comments

Comments
 (0)