Skip to content

WDT-659 cleanup CLAException for compare_model.py #1163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions core/src/main/python/compare_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def compare(self):
except YamlException, ye:
_logger.severe('WLSDPLY-05708', file_name, ye.getLocalizedMessage(),
error=ye, class_name=_class_name, method_name=_method_name)
return 2
System.exit(ExitCode.ERROR)
else:
# write the change model to standard output in YAML format
print(format_message('WLSDPLY-05707'))
Expand Down Expand Up @@ -232,6 +232,12 @@ def debug(format_string, *arguments):
else:
_logger.finest(format_string, arguments)

def _check_model_extension(file):
model_file = JFile(file)
if not (FileUtils.isYamlFile(model_file) or FileUtils.isJsonFile(model_file)):
return False
else:
return True

def main():
"""
Expand All @@ -254,25 +260,16 @@ def main():

for f in [model1, model2]:
if not os.path.exists(f):
raise CLAException("Model %s does not exists" % f)
raise CLAException(ExitCode.ERROR, 'WLSDPLY-85717', [f])
if os.path.isdir(f):
raise CLAException("Model %s is a directory" % f)

model1_file = JFile(model1)
model2_file = JFile(model2)

if not (FileUtils.isYamlFile(model1_file) or FileUtils.isJsonFile(model1_file)):
raise CLAException("Model extension must be either yaml or json")

if not (FileUtils.isYamlFile(model1_file) and FileUtils.isYamlFile(model2_file)
or FileUtils.isJsonFile(model1_file) and FileUtils.isJsonFile(model2_file)):
ext = os.path.splitext(model1)[1]
raise CLAException("Model %s is not a %s file " % (model2, ext))
raise CLAException(ExitCode.ERROR, 'WLSDPLY-85718', [f])
if not _check_model_extension(f):
raise CLAException(ExitCode.ERROR, 'WLSDPLY-85719', [f])

obj = ModelFileDiffer(model1, model2, model_context, _outputdir)
rc = obj.compare()
if rc == VALIDATION_FAIL:
System.exit(2)
System.exit(ExitCode.ERROR)

if _outputdir:
fos = None
Expand Down Expand Up @@ -317,7 +314,7 @@ def main():
System.exit(0)

except CLAException, ex:
exit_code = 2
exit_code = ex.getExitCode()
if exit_code != ExitCode.HELP:
_logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
class_name=_class_name, method_name=_method_name)
Expand All @@ -326,17 +323,17 @@ def main():
except CompareException, ce:
cla_helper.clean_up_temp_files()
_logger.severe('WLSDPLY-05704', ce.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
System.exit(2)
System.exit(ExitCode.ERROR)
except PyWLSTException, pe:
cla_helper.clean_up_temp_files()
_logger.severe('WLSDPLY-05704', pe.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
System.exit(2)
System.exit(ExitCode.ERROR)
except:
exc_type, exc_obj, exc_tb = sys.exc_info()
ee_string = traceback.format_exception(exc_type, exc_obj, exc_tb)
cla_helper.clean_up_temp_files()
_logger.severe('WLSDPLY-05704', ee_string)
System.exit(2)
System.exit(ExitCode.ERROR)


def format_message(key, *args):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ WLSDPLY-05714=NOT USED
WLSDPLY-05715=There are {0} attributes that only exist in the previous model, see {1}
WLSDPLY-05716=The Security Configuration Provider at location {0} has a difference and the current \
provider(s) will replace the previous provider(s)

WLSDPLY-85717=Model {0} does not exists
WLSDPLY-85718=Model {0} is a directory
WLSDPLY-85719=Model {0} does not have the correct file extension, it must be either .yaml or .json

# prepare_model.py
WLSDPLY-05801=Error in prepare model: {0}
Expand Down