--- /dev/null
+/*
+ * 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;
+ }
+
+}
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;
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;
import org.slf4j.LoggerFactory;
/**
- * Integration test for
- * {@link org.opendaylight.ovsdb.southbound}
+ * Integration tests for southbound-impl
*
* @author Sam Hague (shague@redhat.com)
*/
private static String portStr;
private static String connectionType;
private static Boolean setup = false;
+ private static MdsalUtils mdsalUtils = null;
@Inject
private BundleContext bc;
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[] {
}
@Before
- public void setUp() {
+ public void setUp() throws InterruptedException {
if (setup == true) {
LOG.info("Skipping setUp, already initialized");
return;
} 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);
}
}
+ mdsalUtils = new MdsalUtils(dataBroker);
setup = true;
}
@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();
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);
}
}
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);
+ }
}