From: Moiz Raja Date: Wed, 2 Oct 2013 17:43:54 +0000 (-0700) Subject: Simple Sanity Test to validate that all the bundles in a distribution are active... X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~680 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=6a5de1746ad68b1fe9464ec414126f1b559737e2 Simple Sanity Test to validate that all the bundles in a distribution are active and resolved The idea behind the Sanity Test is to ultimately fail a build when the test fails. The test would launch run.sh but with a slightly modified config.ini where the sanitytest bundle would be injected as a framework bundle. The test waits for 30 seconds for the container to finish loading all the bundles. It then gets all the bundles from the BundleContext and checks if they are ACTIVE or RESOLVED. If they are neither it prints out the name of the bundle and it's state and returns an error code. Change-Id: Ia6905318f1cf63e852791ba107193094a83fddf1 Signed-off-by: Moiz Raja --- diff --git a/opendaylight/distribution/sanitytest/pom.xml b/opendaylight/distribution/sanitytest/pom.xml new file mode 100644 index 0000000000..a0001f6db5 --- /dev/null +++ b/opendaylight/distribution/sanitytest/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.1-SNAPSHOT + ../../commons/opendaylight + + + scm:git:ssh://git.opendaylight.org:29418/controller.git + scm:git:ssh://git.opendaylight.org:29418/controller.git + https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main + HEAD + + + sanitytest + 0.4.1-SNAPSHOT + bundle + + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + true + + + + org.opendaylight.controller.sanitytest + + + javax.xml.bind.annotation, + org.osgi.service.component, + org.slf4j, + org.eclipse.osgi.framework.console, + org.osgi.framework, + org.eclipse.osgi.baseadaptor, + org.eclipse.osgi.framework.adaptor + + + org.opendaylight.controller.sanitytest.internal.Activator + + + ${project.basedir}/META-INF + + + + + diff --git a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java new file mode 100644 index 0000000000..262884fa35 --- /dev/null +++ b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java @@ -0,0 +1,54 @@ +package org.opendaylight.controller.sanitytest.internal; + +import org.osgi.framework.*; + +import java.util.Timer; +import java.util.TimerTask; + +public class Activator implements BundleActivator { + //30 Second + private static final int DELAY = 30000; + + + private String stateToString(int state) { + switch (state) { + case Bundle.ACTIVE: + return "ACTIVE"; + case Bundle.INSTALLED: + return "INSTALLED"; + case Bundle.RESOLVED: + return "RESOLVED"; + case Bundle.UNINSTALLED: + return "UNINSTALLED"; + default: + return "Not CONVERTED"; + } + } + + public void start(final BundleContext bundleContext) throws Exception { + Timer monitorTimer = new Timer("monitor timer", true); + + monitorTimer.schedule(new TimerTask() { + @Override + public void run() { + boolean failed = false; + for(Bundle bundle : bundleContext.getBundles()){ + if(bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.RESOLVED) { + System.out.println("Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState())); + failed = true; + } + } + + if(failed){ + System.exit(-1); + } else { + System.exit(0); + } + } + }, DELAY); + } + + public void stop(BundleContext bundleContext) throws Exception { + + } +}