From 02b63c6f8200042175b482b9cc00a0bc950f2f06 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Tue, 5 Jan 2016 01:39:06 +0100 Subject: Updated CLI to run individual selftests. The pki selftest-run command has been modified to execute the specified selftests, or all selftests if nothing is specified. The command will also display the status of each test and the stack trace if it fails. https://fedorahosted.org/pki/ticket/1502 --- .../cmscore/selftests/SelfTestSubsystem.java | 75 +++++++++++----------- 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'base/server/cmscore/src/com/netscape/cmscore') diff --git a/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java index 14fab26e4..4b89aa49e 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java +++ b/base/server/cmscore/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java @@ -501,16 +501,11 @@ public class SelfTestSubsystem Enumeration instances = mOnDemandOrder.elements(); while (instances.hasMoreElements()) { - SelfTestOrderedInstance instance = instances.nextElement(); - String instanceFullName = null; + SelfTestOrderedInstance instance = instances.nextElement(); String instanceName = instance.getSelfTestName(); - if (instanceName != null) { - instanceName = instanceName.trim(); - instanceFullName = getFullName(mPrefix, - instanceName); - } else { + if (instanceName == null) { log(mLogger, CMS.getLogMessage( "CMSCORE_SELFTESTS_PROPERTY_NAME_IS_NULL")); @@ -518,37 +513,11 @@ public class SelfTestSubsystem throw new EMissingSelfTestException(); } - if (mSelfTestInstances.containsKey(instanceName)) { - ISelfTest test = mSelfTestInstances.get(instanceName); - - try { - if (CMS.debugOn()) { - CMS.debug("SelfTestSubsystem::runSelfTestsOnDemand():" - + " running \"" - + test.getSelfTestName() - + "\""); - } - - test.runSelfTest(mLogger); - - } catch (Exception e) { - - CMS.debug(e); - - // Check to see if the self test was critical: - if (isSelfTestCriticalOnDemand(instanceName)) { - log(mLogger, - CMS.getLogMessage( - "CMSCORE_SELFTESTS_RUN_ON_DEMAND_FAILED", - instanceFullName)); + instanceName = instanceName.trim(); - // shutdown the system gracefully - CMS.shutdown(); + String instanceFullName = getFullName(mPrefix, instanceName); - return; - } - } - } else { + if (!mSelfTestInstances.containsKey(instanceName)) { // self test plugin instance property name is not present log(mLogger, CMS.getLogMessage( @@ -557,6 +526,27 @@ public class SelfTestSubsystem throw new EMissingSelfTestException(instanceFullName); } + + try { + runSelfTest(instanceName); + + } catch (Exception e) { + + CMS.debug(e); + + // Check to see if the self test was critical: + if (isSelfTestCriticalOnDemand(instanceName)) { + log(mLogger, + CMS.getLogMessage( + "CMSCORE_SELFTESTS_RUN_ON_DEMAND_FAILED", + instanceFullName)); + + // shutdown the system gracefully + CMS.shutdown(); + + return; + } + } } if (CMS.debugOn()) { @@ -565,6 +555,19 @@ public class SelfTestSubsystem } } + public void runSelfTest(String instanceName) throws Exception { + + CMS.debug("SelfTestSubsystem.runSelfTest(" + instanceName + ")"); + + ISelfTest test = mSelfTestInstances.get(instanceName); + + if (test == null) { + throw new EMissingSelfTestException(instanceName); + } + + test.runSelfTest(mLogger); + } + // // methods associated with the list of startup self tests // -- cgit