From: Ryan Moats Date: Mon, 14 Oct 2013 23:40:37 +0000 (-0500) Subject: Add code for working sanity test in windows. X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~617 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=98a87e05e8658955e697525434f028c34bdfa877 Add code for working sanity test in windows. Refactor application windows batch file to avoid delayed execution issues. Add windows batch file to run sanity test. Refactor sanity test class to call windows batch file properly. Refactor activator class to close System.out stream before exiting so that ProcessBuilder detects the exit. Refactor to first check at 10 seconds and then recheck every second if bundles are still in the STARTING state. Refactor to inherit IO and add limit of 60 retries. And fix style errors Change-Id: Ifa4d78ebfcf0eeaaccf99e56e84a88d33377f0fa Signed-off-by: Ryan Moats --- diff --git a/opendaylight/distribution/opendaylight/run.bat b/opendaylight/distribution/opendaylight/run.bat index 8981709bb1..f219828bad 100644 --- a/opendaylight/distribution/opendaylight/run.bat +++ b/opendaylight/distribution/opendaylight/run.bat @@ -1 +1,23 @@ -REM This is where the sanity test execution for windows needs to go (see run.sh) +rem Inject the sanitytest jar as a controller plugin +copy .\target\dependency\sanitytest*.jar .\target\distribution.opendaylight-osgipackage\opendaylight\plugins + +rem Store the current working directory in a variable so that we can get back to it later +set cwd=%cd% + +rem Switch to the distribution folder +cd .\target\distribution.opendaylight-osgipackage\opendaylight + +rem Run the controller +cmd.exe /c run.bat + +rem Store the exit value of the controller in a variable +set success=%ERRORLEVEL% + +rem Switch back to the directory from which this script was invoked +cd %cwd% + +rem Remove the sanitytest jar from the plugins directory +del .\target\distribution.opendaylight-osgipackage\opendaylight\plugins\sanitytest*.jar + +rem Exit using the exit code that we had captured earlier after running the controller +exit /b %SUCCESS% \ No newline at end of file diff --git a/opendaylight/distribution/opendaylight/src/main/resources/run.bat b/opendaylight/distribution/opendaylight/src/main/resources/run.bat index 6fb9f0655c..d6583a021d 100644 --- a/opendaylight/distribution/opendaylight/src/main/resources/run.bat +++ b/opendaylight/distribution/opendaylight/src/main/resources/run.bat @@ -1,22 +1,24 @@ @ECHO OFF -SETLOCAL -SETLOCAL ENABLEDELAYEDEXPANSION IF EXIST "%JAVA_HOME%" ( - set basedir=%~dp0 + REM CONTINUE +) ELSE ( + ECHO JAVA_HOME environment variable is not set + EXIT 2 +) + +set basedir=%~dp0 REM Now set the classpath: - set cp="!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar;!basedir!lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar;!basedir!lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar" +set cp="%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar;%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar;%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar" REM Now set framework classpath - set fwcp="file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar,file:\!basedir!lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar,file:\!basedir!lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar" +set fwcp="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar,file:\%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar,file:\%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar" REM echo cp: %cp% REM echo fwcp: %fwcp% -REM echo %JAVA_HOME%\bin\java.exe %* -Djava.io.tmpdir=!basedir!work\tmp -Dosgi.install.area=!basedir! -Dosgi.configuration.area=!basedir!configuration -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework=file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog -"%JAVA_HOME%\bin\java.exe" %* -Djava.io.tmpdir="!basedir!work\tmp" -Dosgi.install.area=!basedir! -Dosgi.configuration.area="!basedir!configuration" -Dosgi.frameworkClassPath=!fwcp! -Dosgi.framework="file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar" -classpath !cp! org.eclipse.equinox.launcher.Main -console -consoleLog +REM echo %JAVA_HOME%\bin\java.exe %* -Djava.io.tmpdir=%basedir%work\tmp -Dosgi.install.area=%basedir% -Dosgi.configuration.area=%basedir%configuration -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework=file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog +"%JAVA_HOME%\bin\java.exe" %* -Djava.io.tmpdir="%basedir%work\tmp" -Dosgi.install.area=%basedir% -Dosgi.configuration.area="%basedir%configuration" -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar" -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog + +exit %ERRORLEVEL% + -) ELSE ( - ECHO JAVA_HOME environment variable is not set - PAUSE -) -ENDLOCAL diff --git a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java index 33ff8ea18a..6f395c9e6c 100644 --- a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java +++ b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + public class Sanity { static void copy(InputStream in, OutputStream out) throws IOException { @@ -20,16 +23,18 @@ public class Sanity { System.out.println("Current working directory = " + cwd); String os = System.getProperty("os.name").toLowerCase(); - String script = "./run.sh"; + List script = new ArrayList(); if(os.contains("windows")){ - System.out.println("Sorry no sanity testing on Windows yet"); - System.exit(0); - return; + script.add("cmd.exe"); + script.add("/c"); + script.add("run.bat"); + } else { + script.add("./run.sh"); } ProcessBuilder processBuilder = new ProcessBuilder(); - processBuilder.command(script); + processBuilder.inheritIO().command(script); Process p = processBuilder.start(); copy(p.getInputStream(), System.out); 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 index c27cd07a7e..d92277269a 100644 --- 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 @@ -9,8 +9,9 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.wiring.BundleRevision; public class Activator implements BundleActivator { - //30 Second - private static final int DELAY = 30000; + //10 Second initial, 1 second subsequent + private static final int INITIAL_DELAY = 10000; + private static final int SUBSEQUENT_DELAY = 1000; private String stateToString(int state) { @@ -23,8 +24,10 @@ public class Activator implements BundleActivator { return "RESOLVED"; case Bundle.UNINSTALLED: return "UNINSTALLED"; + case Bundle.STARTING: + return "STARTING"; default: - return "Not CONVERTED"; + return "Not CONVERTED: state value is " + state; } } @@ -33,27 +36,61 @@ public class Activator implements BundleActivator { monitorTimer.schedule(new TimerTask() { @Override public void run() { + int countup = 0; boolean failed = false; - for(Bundle bundle : bundleContext.getBundles()){ - /* - * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED - */ - if(!(bundle.getState() == Bundle.ACTIVE) || - (bundle.getState() != Bundle.RESOLVED && - (bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0)) - 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; + boolean resolved = false; + while (!resolved) { + resolved = true; + failed = false; + for(Bundle bundle : bundleContext.getBundles()){ + /* + * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED + */ + int state = bundle.getState(); + if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) { + //fragment + if (state != Bundle.RESOLVED) { + System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState())); + failed = true; + if (state == Bundle.STARTING) + resolved = false; + } + } else { + if(state != Bundle.ACTIVE) { + System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState())); + failed = true; + if (state == Bundle.STARTING) + resolved = false; + } + } + } + if (!resolved) { + countup++; + if (countup < 60) { + System.out.println("all bundles haven't finished starting, will repeat"); + try { + Thread.sleep(SUBSEQUENT_DELAY); + } catch (Exception e) { + ; + } + } else + resolved = true; } } if(failed){ - System.exit(-1); + System.out.flush(); + System.out.println("exiting with 1 as failed"); + System.out.close(); + Runtime.getRuntime().exit(1); } else { - System.exit(0); + System.out.flush(); + System.out.println("exiting with 0 as succeeded"); + System.out.close(); + Runtime.getRuntime().exit(0); } } - }, DELAY); + }, INITIAL_DELAY); } public void stop(BundleContext bundleContext) throws Exception {