Skip to content

Commit e80b816

Browse files
authored
WDT-659 cleanup CLAException for compare_model.py (#1163)
* WDT-659 correct exit code logic and clean up throwing CLAException earlier. * Use ExitCode.ERROR
1 parent 13c9818 commit e80b816

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

core/src/main/python/compare_model.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def compare(self):
203203
except YamlException, ye:
204204
_logger.severe('WLSDPLY-05708', file_name, ye.getLocalizedMessage(),
205205
error=ye, class_name=_class_name, method_name=_method_name)
206-
return 2
206+
System.exit(ExitCode.ERROR)
207207
else:
208208
# write the change model to standard output in YAML format
209209
print(format_message('WLSDPLY-05707'))
@@ -232,6 +232,12 @@ def debug(format_string, *arguments):
232232
else:
233233
_logger.finest(format_string, arguments)
234234

235+
def _check_model_extension(file):
236+
model_file = JFile(file)
237+
if not (FileUtils.isYamlFile(model_file) or FileUtils.isJsonFile(model_file)):
238+
return False
239+
else:
240+
return True
235241

236242
def main():
237243
"""
@@ -254,25 +260,16 @@ def main():
254260

255261
for f in [model1, model2]:
256262
if not os.path.exists(f):
257-
raise CLAException("Model %s does not exists" % f)
263+
raise CLAException(ExitCode.ERROR, 'WLSDPLY-85717', [f])
258264
if os.path.isdir(f):
259-
raise CLAException("Model %s is a directory" % f)
260-
261-
model1_file = JFile(model1)
262-
model2_file = JFile(model2)
263-
264-
if not (FileUtils.isYamlFile(model1_file) or FileUtils.isJsonFile(model1_file)):
265-
raise CLAException("Model extension must be either yaml or json")
266-
267-
if not (FileUtils.isYamlFile(model1_file) and FileUtils.isYamlFile(model2_file)
268-
or FileUtils.isJsonFile(model1_file) and FileUtils.isJsonFile(model2_file)):
269-
ext = os.path.splitext(model1)[1]
270-
raise CLAException("Model %s is not a %s file " % (model2, ext))
265+
raise CLAException(ExitCode.ERROR, 'WLSDPLY-85718', [f])
266+
if not _check_model_extension(f):
267+
raise CLAException(ExitCode.ERROR, 'WLSDPLY-85719', [f])
271268

272269
obj = ModelFileDiffer(model1, model2, model_context, _outputdir)
273270
rc = obj.compare()
274271
if rc == VALIDATION_FAIL:
275-
System.exit(2)
272+
System.exit(ExitCode.ERROR)
276273

277274
if _outputdir:
278275
fos = None
@@ -317,7 +314,7 @@ def main():
317314
System.exit(0)
318315

319316
except CLAException, ex:
320-
exit_code = 2
317+
exit_code = ex.getExitCode()
321318
if exit_code != ExitCode.HELP:
322319
_logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
323320
class_name=_class_name, method_name=_method_name)
@@ -326,17 +323,17 @@ def main():
326323
except CompareException, ce:
327324
cla_helper.clean_up_temp_files()
328325
_logger.severe('WLSDPLY-05704', ce.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
329-
System.exit(2)
326+
System.exit(ExitCode.ERROR)
330327
except PyWLSTException, pe:
331328
cla_helper.clean_up_temp_files()
332329
_logger.severe('WLSDPLY-05704', pe.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
333-
System.exit(2)
330+
System.exit(ExitCode.ERROR)
334331
except:
335332
exc_type, exc_obj, exc_tb = sys.exc_info()
336333
ee_string = traceback.format_exception(exc_type, exc_obj, exc_tb)
337334
cla_helper.clean_up_temp_files()
338335
_logger.severe('WLSDPLY-05704', ee_string)
339-
System.exit(2)
336+
System.exit(ExitCode.ERROR)
340337

341338

342339
def format_message(key, *args):

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,9 @@ WLSDPLY-05714=NOT USED
521521
WLSDPLY-05715=There are {0} attributes that only exist in the previous model, see {1}
522522
WLSDPLY-05716=The Security Configuration Provider at location {0} has a difference and the current \
523523
provider(s) will replace the previous provider(s)
524-
524+
WLSDPLY-85717=Model {0} does not exists
525+
WLSDPLY-85718=Model {0} is a directory
526+
WLSDPLY-85719=Model {0} does not have the correct file extension, it must be either .yaml or .json
525527

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

0 commit comments

Comments
 (0)