Add karaf-based pax-exam so that net-virt can be tested.
authorSam Hague <shague@redhat.com>
Mon, 16 Feb 2015 23:08:48 +0000 (18:08 -0500)
committerSam Hague <shague@redhat.com>
Mon, 16 Feb 2015 23:08:48 +0000 (18:08 -0500)
Use the following command to run the NetVirtIT test:

mvn -Dit.test=NetVirtIT verify -Pintegrationtest -Dovsdbserver.ipaddress=192.168.120.31 -Dovsdbserver.port=6640 -Pkarafit

This will start the test and bring up the ovsdb karaf distribution. You should first build the distribution and install it to your local m2 repo. When the odl-ovsdb-openstack feature is fully loaded you can then manual configure the bridge to connect to odl with ovs-vsctl set-manager tcp:192.168.120.1:6640.

By default the integration tests exclude NetVirtIt. This is because the current test cannot get service interfaces to make use of their services. An example is getting the connect interfce from the plugin to initiate and outgoing connection to an ovsdb node. The usual "ServiceHelper.getGlobalInstance" did not work in the karaf pax-exam container so another workaround needs to be found.

The test will wait for 10s for the connection from the ovsdb node. Look for the output: "Try to connect!" before connecting. This message indicates the odl-ovsdb-openstack feature is active and ready to receive connections. The timeout can be increased if needed.

Change-Id: I17a944542b564f456f841623083635ac9c4304d0
Signed-off-by: Sam Hague <shague@redhat.com>
integrationtest/pom.xml
integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/netvirt/NetVirtIT.java [new file with mode: 0644]

index c00758a465ef5f1cd910e9862925e3387f7fe220..740edb19d00de55f74c1cae611319d76281f0880 100644 (file)
       <artifactId>mockito-all</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.ops4j.pax.exam</groupId>
-      <artifactId>pax-exam-container-native</artifactId>
-    </dependency>
   </dependencies>
   <build>
     <pluginManagement>
@@ -99,6 +95,7 @@
               <parallel>none</parallel>
               <threadCount>1</threadCount>
               <excludes>
+                <exclude>**/NetVirtIT.java</exclude>
               </excludes>
             </configuration>
           </execution>
       </plugin>
     </plugins>
   </build>
+  <profiles>
+    <profile>
+      <id>default</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <dependencies>
+        <dependency>
+          <groupId>org.ops4j.pax.exam</groupId>
+          <artifactId>pax-exam-container-native</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.ops4j.pax.exam</groupId>
+          <artifactId>pax-exam-container-karaf</artifactId>
+          <scope>compile</scope>
+        </dependency>
+      </dependencies>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-failsafe-plugin</artifactId>
+            <version>${failsafe.version}</version>
+            <configuration>
+            </configuration>
+            <executions>
+              <execution>
+                <id>failsafe-integration-tests</id>
+                <phase>integration-test</phase>
+                <goals>
+                  <goal>integration-test</goal>
+                </goals>
+                <configuration>
+                  <classpathDependencyExcludes>
+                    <classpathDependencyExcludes>org.ops4j.pax.exam:pax-exam-container-karaf</classpathDependencyExcludes>
+                  </classpathDependencyExcludes>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
+      <id>karafit</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <dependencies>
+        <dependency>
+          <groupId>org.ops4j.pax.exam</groupId>
+          <artifactId>pax-exam-container-karaf</artifactId>
+        </dependency>
+      </dependencies>
+    </profile>
+  </profiles>
   <scm>
     <connection>scm:git:ssh://git.opendaylight.org:29418/ovsdb.git</connection>
     <developerConnection>scm:git:ssh://git.opendaylight.org:29418/ovsdb.git</developerConnection>
diff --git a/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/netvirt/NetVirtIT.java b/integrationtest/src/test/java/org/opendaylight/ovsdb/integrationtest/netvirt/NetVirtIT.java
new file mode 100644 (file)
index 0000000..31f5b13
--- /dev/null
@@ -0,0 +1,117 @@
+package org.opendaylight.ovsdb.integrationtest.netvirt;
+
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import javax.inject.Inject;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.ovsdb.integrationtest.OvsdbIntegrationTestBase;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@RunWith(PaxExam.class)
+public class NetVirtIT extends OvsdbIntegrationTestBase {
+    private Logger LOG = LoggerFactory.getLogger(NetVirtIT.class);
+    private static final String NETVIRT = "org.opendaylight.ovsdb.openstack.net-virt-providers";
+
+    @Inject
+    private BundleContext bc;
+
+    @Configuration
+    public Option[] config() {
+        return new Option[] {
+                // Provision and launch a container based on a distribution of Karaf (Apache ServiceMix).
+                karafDistributionConfiguration()
+                        .frameworkUrl(
+                                maven()
+                                        .groupId("org.opendaylight.ovsdb")
+                                        .artifactId("distribution-karaf")
+                                        .type("tar.gz")
+                                        .version("1.3.0-SNAPSHOT"))
+                        .name("OpenDaylight")
+                        .unpackDirectory(new File("target/pax"))
+                        .useDeployFolder(false),
+                // It is really nice if the container sticks around after the test so you can check the contents
+                // of the data directory when things go wrong.
+                keepRuntimeFolder(),
+                // Don't bother with local console output as it just ends up cluttering the logs
+                configureConsole().ignoreLocalConsole(),
+                // Force the log level to INFO so we have more details during the test.  It defaults to WARN.
+                logLevel(LogLevel.INFO),
+                // Remember that the test executes in another process.  If you want to debug it, you need
+                // to tell Pax Exam to launch that process with debugging enabled.  Launching the test class itself with
+                // debugging enabled (for example in Eclipse) will not get you the desired results.
+                //debugConfiguration("5005", true),
+                features("mvn:org.opendaylight.controller/features-base/1.5.0-SNAPSHOT/xml/features",
+                       "odl-base-all"),
+                features("mvn:org.opendaylight.controller/features-neutron/0.5.0-SNAPSHOT/xml/features",
+                        "odl-neutron-all"),
+                features("mvn:org.opendaylight.ovsdb/features-ovsdb/1.1.0-SNAPSHOT/xml/features",
+                        "odl-ovsdb-openstack")
+        };
+    }
+
+    @Before
+    public void setUp () throws ExecutionException, InterruptedException, IOException, InvalidSyntaxException {
+        areWeReady(bc);
+
+        // TODO: this is where we should connect, but it fails currently because of
+        // dependency issues.
+        //try {
+        //    node = getPluginTestConnection();
+        //} catch (Exception e) {
+        //    fail("Exception : " + e.getMessage());
+        //}
+        isBundleReady(bc, NETVIRT);
+        // To be certain that all the bundles are Active sleep some more.
+        Thread.sleep(5000);
+    }
+
+    @Test
+    public void testGetProperty ()  throws Exception {
+        LOG.info(">>>>> We did it! Try to connect!");
+        LOG.info(">>>>> We did it! Try to connect!");
+        LOG.info(">>>>> We did it! Try to connect!");
+        Thread.sleep(10000);
+    }
+
+    /**
+     * isBundleReady is used to check if the requested bundle is Active
+     */
+    public void isBundleReady (BundleContext bc, String bundleName) throws InterruptedException {
+        boolean ready = false;
+
+        while (!ready) {
+            int state = Bundle.UNINSTALLED;
+            Bundle b[] = bc.getBundles();
+            for (Bundle element : b) {
+                if (element.getSymbolicName().equals(bundleName)) {
+                    state = element.getState();
+                    break;
+                }
+            }
+            if (state != Bundle.ACTIVE) {
+                LOG.info(">>>>> bundle not ready");
+                Thread.sleep(5000);
+            } else {
+                ready = true;
+            }
+        }
+    }
+}