Skip to content

Commit 6e9c011

Browse files
changing tool exit codes to reflect summary handler results (#1328)
1 parent 940d7bd commit 6e9c011

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Standard exit codes for command-line utilities.
66
"""
77

8+
89
class ExitCode(object):
910
"""
1011
Standard exit codes for command-line utilities.

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import traceback
88

99
from java.lang import Exception as JException
10+
from java.util.logging import Level as JLevel
1011

1112
from oracle.weblogic.deploy.logging import WLSDeployLoggingConfig
13+
from oracle.weblogic.deploy.logging import WLSDeployLogEndHandler
1214
from oracle.weblogic.deploy.util import CLAException
1315
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
1416
from oracle.weblogic.deploy.util import WLSDeployExit
@@ -21,6 +23,7 @@
2123
import wlsdeploy.util.unicode_helper as str_helper
2224
from wlsdeploy.util.exit_code import ExitCode
2325

26+
2427
def run_tool(main, process_args, args, program_name, class_name, logger):
2528
"""
2629
The standardized entry point into each tool.
@@ -78,6 +81,9 @@ def __exit_tool(model_context, exit_code):
7881
version = model_context.get_target_wls_version()
7982
if model_context.get_target_wlst_mode() == WlstModes.ONLINE:
8083
tool_mode = JWLSTMode.ONLINE
84+
85+
exit_code = __get_summary_handler_exit_code(exit_code)
86+
8187
WLSDeployExit.exit(WLSDeployContext(program, version, tool_mode), exit_code)
8288

8389

@@ -107,3 +113,25 @@ def __handle_unexpected_exception(ex, model_context, class_name, method_name, lo
107113
# and of course only while in the except block handling code
108114
logger.fine('WLSDPLY-20036', program_name, traceback.format_exception(type(ex), ex, sys.exc_info()[2]),
109115
class_name=class_name, method_name=method_name, error=ex)
116+
117+
118+
def __get_summary_handler_exit_code(program_exit_code):
119+
"""
120+
Private method for use only within this module.
121+
122+
Helper method to get the proper tool exit code based on the exit code from the tool and the number
123+
of errors and warnings from the summary log handler.
124+
:param program_exit_code: the exit code from the tool
125+
:return: the exit code to use
126+
"""
127+
if program_exit_code != ExitCode.OK:
128+
return program_exit_code
129+
130+
exit_code = ExitCode.OK
131+
summary_handler = WLSDeployLogEndHandler.getSummaryHandler()
132+
if summary_handler is not None:
133+
if summary_handler.getMessageCount(JLevel.SEVERE) > 0:
134+
exit_code = ExitCode.ERROR
135+
elif summary_handler.getMessageCount(JLevel.WARNING) > 0:
136+
exit_code = ExitCode.WARNING
137+
return exit_code

integration-tests/system-test/src/test/java/oracle/weblogic/deploy/integration/ITWdt.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ void test17DiscoverDomainWithRequiredArgument(TestInfo testInfo) throws Exceptio
517517
+ " -archive_file " + discoveredArchive
518518
+ " -domain_type RestrictedJRF";
519519
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
520-
521-
verifyResult(result, "discoverDomain.sh completed successfully");
520+
// SecurityConfiguration warning
521+
assertEquals(1, result.exitValue(), "Unexpected return code");
522522

523523
// unzip discoveredArchive.zip
524524
cmd = "unzip -o " + discoveredArchive + " -d " + getTestOutputPath(testInfo);
@@ -561,8 +561,8 @@ void test18DiscoverDomainWithModelFile(TestInfo testInfo) throws Exception {
561561
" -model_file " + discoveredModelFile;
562562
try (PrintWriter out = getTestMethodWriter(testInfo)) {
563563
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
564-
565-
verifyResult(result, "discoverDomain.sh completed successfully");
564+
// SecurityConfiguration warning
565+
assertEquals(1, result.exitValue(), "Unexpected return code");
566566

567567
// verify model file
568568
verifyModelFile(discoveredModelFile.toString());
@@ -593,7 +593,8 @@ void test19DiscoverDomainWithVariableFile(TestInfo testInfo) throws Exception {
593593

594594
try (PrintWriter out = getTestMethodWriter(testInfo)) {
595595
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
596-
verifyResult(result, "discoverDomain.sh completed successfully");
596+
// SecurityConfiguration warning
597+
assertEquals(1, result.exitValue(), "Unexpected return code");
597598

598599
// verify model file and variable file
599600
verifyModelFile(discoveredModelFile.toString());
@@ -643,8 +644,8 @@ void test20DiscoverDomainJRFDomainType(TestInfo testInfo) throws Exception {
643644
+ " -domain_type JRF";
644645

645646
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
646-
647-
verifyResult(result, "discoverDomain.sh completed successfully");
647+
// SecurityConfiguration warning
648+
assertEquals(1, result.exitValue(), "Unexpected return code");
648649

649650
// verify model file
650651
verifyModelFile(discoveredModelFile.toString());
@@ -1034,8 +1035,8 @@ void test32PrepareModel(TestInfo testInfo) throws Exception {
10341035
+ " -target " + "wko";
10351036

10361037
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
1037-
1038-
verifyResult(result, "prepareModel.sh completed successfully");
1038+
// ListenPort differences warning
1039+
assertEquals(1, result.exitValue(), "Unexpected return code");
10391040

10401041
// verify model file
10411042
String tempWkoModel = outputFiles + FS + "simple-topology-targetwko.yaml";

0 commit comments

Comments
 (0)