Workaround to fix southbound it 20/18120/1
authorSam Hague <shague@redhat.com>
Fri, 10 Apr 2015 15:22:48 +0000 (11:22 -0400)
committerSam Hague <shague@redhat.com>
Fri, 10 Apr 2015 15:22:48 +0000 (11:22 -0400)
The problem was the dataBroker in the southbound-it was not right. Something from outside ovsdb changed and caused issues with the way the soutbound-it was getting the broker.

The workaround was to get the broker from the SouthboundProvider.

Also added basic NetworkTopology and Topology to read the OVSDBTopology from the datastores since those values have to exist for southbound-impl to work.

Change-Id: Ie24c2bed42976efc64c142c30f6b1a8935435209
Signed-off-by: Sam Hague <shague@redhat.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/MdsalUtils.java [new file with mode: 0644]
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java

index 5bc8e568434ffeae7dcdc67adcab13548f7f68f9..9512a6cc034215761115d8c2b611bbe0e49b3b8e 100644 (file)
@@ -32,7 +32,13 @@ import com.google.common.util.concurrent.CheckedFuture;
 public class SouthboundProvider implements BindingAwareProvider, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(SouthboundProvider.class);
-    private DataBroker db;
+
+    public static DataBroker getDb() {
+        return db;
+    }
+
+    //private DataBroker db;
+    private static DataBroker db;
     private OvsdbConnectionManager cm;
 //    private OvsdbNodeDataChangeListener ovsdbNodeListener;
 //    private OvsdbManagedNodeDataChangeListener ovsdbManagedNodeListener;
diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/MdsalUtils.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/MdsalUtils.java
new file mode 100644 (file)
index 0000000..ff573ad
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015 Red Hat, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.southbound.it;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility class to wrap mdsal transactions.
+ *
+ * @author Sam Hague (shague@redhat.com)
+ */
+public class MdsalUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(SouthboundIT.class);
+    private static DataBroker databroker = null;
+
+    /**
+     * Class constructor setting the data broker.
+     *
+     * @param dataBroker the {@link DataBroker}
+     */
+    public MdsalUtils(DataBroker dataBroker) {
+        this.databroker = dataBroker;
+    }
+
+    /**
+     * Executes read transaction as a test2.
+     *
+     * @param logicalDatastoreType {@link LogicalDatastoreType} from which read should occur
+     * @param path {@link InstanceIdentifier} for path to read
+     * @param <D> the data object type
+     * @return the data object requested
+     */
+    public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D readTransaction(
+            final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path)  {
+        D ret = null;
+        final ReadOnlyTransaction readTx = databroker.newReadOnlyTransaction();
+        Optional<D> optionalDataObject = Optional.absent();
+        CheckedFuture<Optional<D>, ReadFailedException> submitFuture = readTx.read(logicalDatastoreType, path);
+        try {
+            optionalDataObject = submitFuture.checkedGet();
+            if (optionalDataObject != null && optionalDataObject.isPresent()) {
+                ret = optionalDataObject.get();
+            } else {
+                LOG.debug("{}: Failed to read {}",
+                        Thread.currentThread().getStackTrace()[1], path);
+            }
+        } catch (ReadFailedException e) {
+            LOG.warn("Failed to read {} ", path, e);
+        }
+        return ret;
+    }
+
+}
index af8d29e39fc77f24d288ecdec878be5ae9e26b18..e1047e49b5bbe0513ae74f4e4fbd393710fc08f1 100644 (file)
@@ -25,6 +25,7 @@ import java.net.UnknownHostException;
 import java.util.Properties;
 import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -35,10 +36,16 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
+import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.ovsdb.southbound.SouthboundProvider;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
@@ -50,8 +57,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Integration test for
- * {@link org.opendaylight.ovsdb.southbound}
+ * Integration tests for southbound-impl
  *
  * @author Sam Hague (shague@redhat.com)
  */
@@ -75,6 +81,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     private static String portStr;
     private static String connectionType;
     private static Boolean setup = false;
+    private static MdsalUtils mdsalUtils = null;
 
     @Inject
     private BundleContext bc;
@@ -122,7 +129,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
         String connectionType = props.getProperty(CONNECTION_TYPE, CONNECTION_TYPE_ACTIVE);
 
-        LOG.info("1: Using the following properties: mode= {}, ip:port= {}:{}",
+        LOG.info("Using the following properties: mode= {}, ip:port= {}:{}",
                 connectionType, addressStr, portStr);
 
         Option[] options = new Option[] {
@@ -134,7 +141,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     }
 
     @Before
-    public void setUp() {
+    public void setUp() throws InterruptedException {
         if (setup == true) {
             LOG.info("Skipping setUp, already initialized");
             return;
@@ -145,7 +152,10 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         } catch (Exception e) {
             e.printStackTrace();
         }
-        dataBroker = getSession().getSALService(DataBroker.class);
+        //dataBroker = getSession().getSALService(DataBroker.class);
+        Thread.sleep(3000);
+        dataBroker = SouthboundProvider.getDb();
+        Assert.assertNotNull("db should not be null", dataBroker);
 
         addressStr = bc.getProperty(SERVER_IPADDRESS);
         portStr = bc.getProperty(SERVER_PORT);
@@ -159,6 +169,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             }
         }
 
+        mdsalUtils = new MdsalUtils(dataBroker);
         setup = true;
     }
 
@@ -173,7 +184,6 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     @Test
     public void testAddRemoveOvsdbNode() throws InterruptedException {
         OvsdbClientKey ovsdbClientKey = getOvsdbClientKey(addressStr, portStr);
-        DataBroker dataBroker = getSession().getSALService(DataBroker.class);
 
         // Write OVSDB node to configuration
         final ReadWriteTransaction configNodeTx = dataBroker.newReadWriteTransaction();
@@ -291,8 +301,8 @@ public class SouthboundIT extends AbstractMdsalTestBase {
                 SouthboundMapper.createNode(ovsdbClientKey));
         CheckedFuture<Void, TransactionCommitFailedException> commitFuture = rwTx.submit();
         try {
-            commitFuture.get();
-        } catch (ExecutionException | InterruptedException e) {
+            commitFuture.checkedGet();
+        } catch (TransactionCommitFailedException e) {
             fail("Failed transaction: " + rwTx + e);
         }
     }
@@ -328,4 +338,52 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             fail("Failed transaction: " + rwTx + e);
         }
     }
+
+    private NetworkTopology readNetworkTopology(LogicalDatastoreType type) {
+        OvsdbClientKey ovsdbClientKey = getOvsdbClientKey(addressStr, portStr);
+
+        final ReadWriteTransaction rwTx = dataBroker.newReadWriteTransaction();
+        Optional<NetworkTopology> optional = Optional.absent();
+        CheckedFuture<Optional<NetworkTopology>, ReadFailedException> read;
+        read = rwTx.read(type, InstanceIdentifier.create(NetworkTopology.class));
+        try {
+            optional = read.checkedGet();
+            if (optional.isPresent()) {
+                return optional.get();
+            }
+        } catch (ReadFailedException e) {
+            fail("Failed transaction: " + rwTx + e);
+        }
+
+        return null;
+    }
+
+    @Test
+    public void testNetworkTopology() throws InterruptedException {
+        NetworkTopology networkTopology = MdsalUtils.readTransaction(LogicalDatastoreType.CONFIGURATION,
+                InstanceIdentifier.create(NetworkTopology.class));
+        Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.CONFIGURATION,
+                networkTopology);
+
+        networkTopology = MdsalUtils.readTransaction(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(NetworkTopology.class));
+        Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.OPERATIONAL,
+                networkTopology);
+    }
+
+    @Test
+    public void testOvsdbTopology() throws InterruptedException {
+        InstanceIdentifier<Topology> path = InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
+
+        Topology topology = MdsalUtils.readTransaction(LogicalDatastoreType.CONFIGURATION, path);
+        Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.CONFIGURATION,
+                topology);
+
+        topology = MdsalUtils.readTransaction(LogicalDatastoreType.OPERATIONAL, path);
+
+        Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.OPERATIONAL,
+                topology);
+    }
 }