Skip to content

changing tool exit codes to reflect summary handler results #1328

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 1 commit into from
Dec 21, 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
1 change: 1 addition & 0 deletions core/src/main/python/wlsdeploy/util/exit_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Standard exit codes for command-line utilities.
"""


class ExitCode(object):
"""
Standard exit codes for command-line utilities.
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/python/wlsdeploy/util/tool_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import traceback

from java.lang import Exception as JException
from java.util.logging import Level as JLevel

from oracle.weblogic.deploy.logging import WLSDeployLoggingConfig
from oracle.weblogic.deploy.logging import WLSDeployLogEndHandler
from oracle.weblogic.deploy.util import CLAException
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
from oracle.weblogic.deploy.util import WLSDeployExit
Expand All @@ -21,6 +23,7 @@
import wlsdeploy.util.unicode_helper as str_helper
from wlsdeploy.util.exit_code import ExitCode


def run_tool(main, process_args, args, program_name, class_name, logger):
"""
The standardized entry point into each tool.
Expand Down Expand Up @@ -78,6 +81,9 @@ def __exit_tool(model_context, exit_code):
version = model_context.get_target_wls_version()
if model_context.get_target_wlst_mode() == WlstModes.ONLINE:
tool_mode = JWLSTMode.ONLINE

exit_code = __get_summary_handler_exit_code(exit_code)

WLSDeployExit.exit(WLSDeployContext(program, version, tool_mode), exit_code)


Expand Down Expand Up @@ -107,3 +113,25 @@ def __handle_unexpected_exception(ex, model_context, class_name, method_name, lo
# and of course only while in the except block handling code
logger.fine('WLSDPLY-20036', program_name, traceback.format_exception(type(ex), ex, sys.exc_info()[2]),
class_name=class_name, method_name=method_name, error=ex)


def __get_summary_handler_exit_code(program_exit_code):
"""
Private method for use only within this module.

Helper method to get the proper tool exit code based on the exit code from the tool and the number
of errors and warnings from the summary log handler.
:param program_exit_code: the exit code from the tool
:return: the exit code to use
"""
if program_exit_code != ExitCode.OK:
return program_exit_code

exit_code = ExitCode.OK
summary_handler = WLSDeployLogEndHandler.getSummaryHandler()
if summary_handler is not None:
if summary_handler.getMessageCount(JLevel.SEVERE) > 0:
exit_code = ExitCode.ERROR
elif summary_handler.getMessageCount(JLevel.WARNING) > 0:
exit_code = ExitCode.WARNING
return exit_code
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ void test17DiscoverDomainWithRequiredArgument(TestInfo testInfo) throws Exceptio
+ " -archive_file " + discoveredArchive
+ " -domain_type RestrictedJRF";
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);

verifyResult(result, "discoverDomain.sh completed successfully");
// SecurityConfiguration warning
assertEquals(1, result.exitValue(), "Unexpected return code");

// unzip discoveredArchive.zip
cmd = "unzip -o " + discoveredArchive + " -d " + getTestOutputPath(testInfo);
Expand Down Expand Up @@ -561,8 +561,8 @@ void test18DiscoverDomainWithModelFile(TestInfo testInfo) throws Exception {
" -model_file " + discoveredModelFile;
try (PrintWriter out = getTestMethodWriter(testInfo)) {
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);

verifyResult(result, "discoverDomain.sh completed successfully");
// SecurityConfiguration warning
assertEquals(1, result.exitValue(), "Unexpected return code");

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

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

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

CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);

verifyResult(result, "discoverDomain.sh completed successfully");
// SecurityConfiguration warning
assertEquals(1, result.exitValue(), "Unexpected return code");

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

CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);

verifyResult(result, "prepareModel.sh completed successfully");
// ListenPort differences warning
assertEquals(1, result.exitValue(), "Unexpected return code");

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