Sanity test to verify that the bundles that are included as plugins in the controller... 36/1736/6
authorMoiz Raja <moraja@cisco.com>
Mon, 7 Oct 2013 23:22:34 +0000 (16:22 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 9 Oct 2013 19:59:04 +0000 (19:59 +0000)
Change-Id: Id472ab9f17f7a604e473177096b8a5045af913d3
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/distribution/opendaylight/pom.xml
opendaylight/distribution/opendaylight/run.bat [new file with mode: 0644]
opendaylight/distribution/opendaylight/run.sh [new file with mode: 0755]
opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java [new file with mode: 0644]
opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java
pom.xml

index f718621b26da6b3d6d97229c77a85da78cb0576d..74d2b74f11059159a6ca5f78ad95bbd724fdf924 100644 (file)
     </dependency>
 
     <!-- Southbound bundles -->
-
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>protocol_plugins.openflow</artifactId>
       <version>${controller.version}</version>
     </dependency>
 
-    <!-- Sanitytest
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sanitytest</artifactId>
-      <version>${controller.version}</version>
-    </dependency>
-
-    -->
-
     <!-- Third party depedencies -->
 
     <dependency>
      <artifactId>yang-model-api</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sanitytest</artifactId>
+      <version>${controller.version}</version>
+    </dependency>
 
   </dependencies>
 
+
   <build>
     <plugins>
       <plugin>
           </execution>
         </executions>
       </plugin>
-      <!--
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>2.8</version>
+          <executions>
+            <execution>
+              <id>copy</id>
+              <phase>package</phase>
+              <goals>
+                <goal>copy</goal>
+              </goals>
+            </execution>
+          </executions>
+          <configuration>
+            <artifactItems>
+              <artifactItem>
+                <groupId>org.opendaylight.controller</groupId>
+                <artifactId>sanitytest</artifactId>
+                <version>${controller.version}</version>
+                <type>jar</type>
+              </artifactItem>
+            </artifactItems>
+          </configuration>
+      </plugin>
+
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>exec-maven-plugin</artifactId>
             </goals>
           </execution>
         </executions>
-        <configuration>
-          <executable>./run.sh</executable>
-        </configuration>
+          <configuration>
+            <executable>java</executable>
+            <arguments>
+                <argument>-cp</argument>
+                <argument>../sanitytest/target/classes</argument>
+                <argument>org.opendaylight.controller.distribution.Sanity</argument>
+            </arguments>
+            <workingDirectory>${exec.workingdir}/../../sanitytest</workingDirectory>
+          </configuration>
       </plugin>
-      -->
     </plugins>
   </build>
 </project>
diff --git a/opendaylight/distribution/opendaylight/run.bat b/opendaylight/distribution/opendaylight/run.bat
new file mode 100644 (file)
index 0000000..8981709
--- /dev/null
@@ -0,0 +1 @@
+REM This is where the sanity test execution for windows needs to go (see run.sh)
diff --git a/opendaylight/distribution/opendaylight/run.sh b/opendaylight/distribution/opendaylight/run.sh
new file mode 100755 (executable)
index 0000000..4ee9555
--- /dev/null
@@ -0,0 +1,24 @@
+# Inject the sanitytest jar as a controller plugin
+cp ./target/dependency/sanitytest*.jar ./target/distribution.opendaylight-osgipackage/opendaylight/plugins
+
+# Store the current working directory in a variable so that we can get back to it later
+cwd=`pwd`
+
+# Switch to the distribution folder
+cd ./target/distribution.opendaylight-osgipackage/opendaylight/
+
+# Run the controller
+./run.sh
+
+# Store the exit value of the controller in a variable
+success=`echo $?`
+
+# Switch back to the directory from which this script was invoked
+cd $cwd
+
+# Remove the sanitytest jar from the plugins directory
+rm ./target/distribution.opendaylight-osgipackage/opendaylight/plugins/sanitytest*.jar
+
+# Exit using the exit code that we had captured earlier after running the controller
+exit $success
+
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
new file mode 100644 (file)
index 0000000..378ea8a
--- /dev/null
@@ -0,0 +1,47 @@
+package org.opendaylight.controller.distribution;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class Sanity {
+
+    static void copy(InputStream in, OutputStream out) throws IOException {
+      while (true) {
+        int c = in.read();
+        if (c == -1) break;
+        out.write((char)c);
+      }
+    }
+
+    public static void main(String[] args) throws IOException, InterruptedException {
+        String cwd = System.getProperty("user.dir");
+
+        System.out.println("Current working directory = " + cwd);
+
+        // We assume that the program is being run from the sanitytest directory
+        // We need to specify the opendaylight directory as the working directory for the shell/batch scripts
+        File processWorkingDir = new File(cwd, "../opendaylight");
+
+        String os = System.getProperty("os.name").toLowerCase();
+        String script = "./run.sh";
+
+        if(os.contains("windows")){
+            script = "run.bat";
+        }
+
+        ProcessBuilder processBuilder = new ProcessBuilder();
+        processBuilder.directory(processWorkingDir.getCanonicalFile());
+        processBuilder.command(script);
+        Process p = processBuilder.start();
+
+        copy(p.getInputStream(), System.out);
+
+        p.waitFor();
+
+        System.out.println("Test exited with exitValue = " + p.exitValue());
+
+        System.exit(p.exitValue());
+    }
+}
index 262884fa3545ba5e8ac9ee91eb720b86e609c8f7..65bc3800311c97ff5cc170e0a8d2ec2498adf99b 100644 (file)
@@ -27,14 +27,13 @@ public class Activator implements BundleActivator {
 
     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()));
+                        System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
                         failed = true;
                     }
                 }
diff --git a/pom.xml b/pom.xml
index d1b65d590233509bf4ec092fcc9faa380eb8871c..4d0d2ee52b7d5b67dbf9ea6947a049b73d2f029f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <module>opendaylight/samples/loadbalancer</module>
     <module>opendaylight/samples/northbound/loadbalancer</module>
 
-    <!-- sanity test
     <module>opendaylight/distribution/sanitytest/</module>
-    -->
+
     <!-- Parents -->
     <module>opendaylight/commons/concepts</module>
     <module>opendaylight/commons/httpclient</module>