import static org.junit.Assert.fail;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperties;
import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.InetAddress;
import org.junit.After;
import org.junit.Assert;
+import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.RunWith;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
+import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.notation.Version;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
import org.opendaylight.ovsdb.southbound.SouthboundProvider;
import org.opendaylight.ovsdb.southbound.SouthboundUtil;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
-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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
/**
* Integration tests for southbound-impl
private static final int OVSDB_UPDATE_TIMEOUT = 1000;
private static final int OVSDB_ROUNDTRIP_TIMEOUT = 10000;
private static final String FORMAT_STR = "%s_%s_%d";
+ private static final Version AUTOATTACH_FROM_VERSION = Version.fromString("7.11.2");
+ private static final Version IF_INDEX_FROM_VERSION = Version.fromString("7.2.1");
private static String addressStr;
private static int portNumber;
private static String connectionType;
private static Node ovsdbNode;
private static int testMethodsRemaining;
private static DataBroker dataBroker;
+ private static Version schemaVersion;
+ private static OvsdbClient ovsdbClient;
+ private static DatabaseSchema dbSchema;
@Inject
private BundleContext bundleContext;
.getURL();
}
- @Override
- public String getModuleName() {
- return "southbound-impl";
- }
-
- @Override
- public String getInstanceName() {
- return "southbound-default";
- }
-
@Override
public MavenUrlReference getFeatureRepo() {
return maven()
connectionType, addressStr, portStr);
return new Option[] {
+ propagateSystemProperties(
+ SouthboundITConstants.SERVER_IPADDRESS,
+ SouthboundITConstants.SERVER_PORT,
+ SouthboundITConstants.CONNECTION_TYPE),
editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES,
SouthboundITConstants.SERVER_IPADDRESS, addressStr),
editConfigurationFilePut(SouthboundITConstants.CUSTOM_PROPERTIES,
iid, OPERATIONAL_LISTENER, AsyncDataBroker.DataChangeScope.SUBTREE);
ovsdbNode = connectOvsdbNode(connectionInfo);
+ try {
+ ovsdbClient = SouthboundIntegrationTestUtils.getTestConnection(this);
+ assertNotNull("Invalid Client. Check connection params", ovsdbClient);
+
+ dbSchema = ovsdbClient.getSchema(SouthboundIntegrationTestUtils.OPEN_VSWITCH_SCHEMA).get();
+ assertNotNull("Invalid dbSchema.", dbSchema);
+ schemaVersion = dbSchema.getVersion();
+ LOG.info("{} schema version = {}", SouthboundIntegrationTestUtils.OPEN_VSWITCH_SCHEMA, schemaVersion);
+ } catch (Exception e) {
+ fail("Error accessing schemaVersion in SouthboundIT setUp()." + usage());
+ }
// Let's count the test methods (we need to use this instead of @AfterClass on teardown() since the latter is
// useless with pax-exam)
}
}
- // FIXME: Remove ignore annotation after ovs supports external_ids column to test CRUD
- @Ignore
@Test
public void testCRUDAutoAttach() throws InterruptedException {
- // FIXME: Perform schema version verification and assume test passed when table is unsupported in schema
+ final boolean isOldSchema = schemaVersion.compareTo(AUTOATTACH_FROM_VERSION) < 0;
ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
String testAutoattachId = new String("testAutoattachEntry");
String bridgeId = nodeId.getValue();
try(TestAutoAttach testAutoattach = new TestAutoAttach(connectionInfo, new Uri(testAutoattachId),
new Uri(bridgeId), testSystemName, testSystemDescription, null, null)) {
-
// READ: Read md-sal operational datastore to see if the AutoAttach table was created
// and if Bridge table was updated with AutoAttach Uuid
OvsdbNodeAugmentation ovsdbNodeAugmentation = getOvsdbNode(connectionInfo,
LogicalDatastoreType.OPERATIONAL);
Autoattach operAa = getAutoAttach(ovsdbNodeAugmentation, new Uri(testAutoattachId));
+
+ // skip tests after verifying that Autoattach doesn't break with unsupported schema
+ Assume.assumeFalse(isOldSchema);
+
+ // FIXME: Remove once CRUD is supported
+ Assume.assumeFalse(operAa == null);
+
Assert.assertNotNull(operAa);
Assert.assertEquals(testSystemName, operAa.getSystemName());
bridge = getBridge(connectionInfo);
final NotifyingDataChangeListener aaOperationalListener =
new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, iid);
aaOperationalListener.registerDataChangeListener();
- Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
- iid, updatedAa));
+ Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, iid, updatedAa));
aaOperationalListener.waitForUpdate(OVSDB_UPDATE_TIMEOUT);
// UPDATE: Update external_ids column of AutoAttach table that was created
.setAutoattachId(new Uri(testAutoattachId))
.setAutoattachExternalIds(externalIds)
.build();
- Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
- iid, updatedAa));
+ Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, iid, updatedAa));
aaOperationalListener.waitForUpdate(OVSDB_UPDATE_TIMEOUT);
// READ: Read the updated AutoAttach table for latest mappings and external_ids column value
LogicalDatastoreType.OPERATIONAL);
operAa = getAutoAttach(ovsdbNodeAugmentation, new Uri(testAutoattachId));
Assert.assertNull(operAa);
+ } catch (AssumptionViolatedException e) {
+ LOG.warn("Skipped test for Autoattach due to unsupported schema", e);
+ } catch (Exception e) {
+ fail("Unexpected exception in CRUD test for Autoattach table for schema:" + schemaVersion.toString() +". " + e);
}
}
}
return tpList.get(index).getAugmentation(OvsdbTerminationPointAugmentation.class);
}
+ @Test
+ public void testCRUDTerminationPointIfIndex() throws InterruptedException {
+ final boolean isOldSchema = schemaVersion.compareTo(IF_INDEX_FROM_VERSION) < 0;
+ Assume.assumeFalse(isOldSchema);
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
+
+ // Test create ifIndex
+ try (TestBridge testBridge = new TestBridge(connectionInfo, null, SouthboundITConstants.BRIDGE_NAME, null, true,
+ SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"),
+ true, SouthboundMapper.createDatapathType("netdev"), null, null, null)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+ Assert.assertNotNull(bridge);
+ LOG.info("bridge: {}", bridge);
+ NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundUtils.createInstanceIdentifier(
+ connectionInfo, bridge.getBridgeName()));
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+ String portName = "testIfIndex";
+ ovsdbTerminationBuilder.setName(portName);
+
+ Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
+ InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
+ Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
+ Assert.assertNotNull(terminationPointNode);
+
+ // Test read ifIndex
+ List<TerminationPoint> terminationPoints = terminationPointNode.getTerminationPoint();
+ for (TerminationPoint terminationPoint : terminationPoints) {
+ OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
+ terminationPoint.getAugmentation(OvsdbTerminationPointAugmentation.class);
+ if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
+ Long ifIndex = ovsdbTerminationPointAugmentation.getIfindex();
+ Assert.assertNotNull(ifIndex);
+ LOG.info("ifIndex: {} for the port:{}", ifIndex, portName);
+ }
+ }
+ }
+ }
+
@Test
public void testCRDTerminationPointOfPort() throws InterruptedException {
final Long OFPORT_EXPECTED = 45002L;
new PortOtherConfigsSouthboundHelper());
}
+ @Test
+ public void testCRUDTerminationPoints() throws InterruptedException {
+ String port1 = "vx1";
+ String port2 = "vxlanport";
+ ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
+
+ try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+ OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME);
+ Assert.assertNotNull(bridge);
+ NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier(
+ connectionInfo, bridge.getBridgeName()));
+ OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder =
+ createGenericOvsdbTerminationPointAugmentationBuilder();
+
+ // add and delete a single port
+ String portName = port1;
+ ovsdbTerminationBuilder.setName(portName);
+ Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
+ InstanceIdentifier<Node> terminationPointIid = getTpIid(connectionInfo, bridge);
+ Node terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
+ Assert.assertNotNull(terminationPointNode);
+
+ SouthboundUtils.createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME));
+ portName = port1;
+ InstanceIdentifier<TerminationPoint> nodePath =
+ SouthboundUtils.createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME))
+ .child(TerminationPoint.class, new TerminationPointKey(new TpId(portName)));
+
+ Assert.assertTrue("failed to delete port " + portName,
+ mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, nodePath));
+ LOG.info("shague: waiting for delete {}", portName);
+ Thread.sleep(1000);
+ TerminationPoint terminationPoint = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, nodePath);
+ Assert.assertNull(terminationPoint);
+
+ // add two ports, then delete them
+ portName = port1;
+ ovsdbTerminationBuilder.setName(portName);
+ Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
+ terminationPointIid = getTpIid(connectionInfo, bridge);
+ terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
+ Assert.assertNotNull(terminationPointNode);
+
+ portName = port2;
+ ovsdbTerminationBuilder.setName(portName);
+ Assert.assertTrue(addTerminationPoint(nodeId, portName, ovsdbTerminationBuilder));
+ terminationPointIid = getTpIid(connectionInfo, bridge);
+ terminationPointNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, terminationPointIid);
+ Assert.assertNotNull(terminationPointNode);
+
+ SouthboundUtils.createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME));
+ portName = port1;
+ nodePath =
+ SouthboundUtils.createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME))
+ .child(TerminationPoint.class, new TerminationPointKey(new TpId(portName)));
+
+ Assert.assertTrue("failed to delete port " + portName,
+ mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, nodePath));
+ LOG.info("shague: waiting for delete {}", portName);
+ Thread.sleep(1000);
+ terminationPoint = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, nodePath);
+ Assert.assertNull(terminationPoint);
+
+ portName = port2;
+ nodePath = SouthboundUtils.createInstanceIdentifier(connectionInfo,
+ new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME))
+ .child(TerminationPoint.class, new TerminationPointKey(new TpId(portName)));
+
+ Assert.assertTrue("failed to delete port " + portName,
+ mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, nodePath));
+ LOG.info("shague: waiting for delete {}", portName);
+ Thread.sleep(1000);
+ terminationPoint = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, nodePath);
+ Assert.assertNull(terminationPoint);
+
+ // DELETE handled by TestBridge
+ }
+ }
+
@Test
public void testCRUDTerminationPointVlan() throws InterruptedException {
final Integer CREATED_VLAN_ID = 4000;
private Queues getQueue(Uri queueId, OvsdbNodeAugmentation node) {
for (Queues queue : node.getQueues()) {
- if (queue.getKey().getQueueId().equals(queueId))
+ if (queue.getKey().getQueueId().getValue().equals(queueId.getValue()))
return queue;
}
return null;
List<QueueList> operQueueList = operQos.getQueueList();
Assert.assertNotNull(operQueueList);
for (QueueList queueEntry : queueList) {
- Assert.assertTrue(operQueueList.contains(queueEntry));
+ Assert.assertTrue(isQueueInList(operQueueList, queueEntry));
}
// DELETE one queue from queue list and check that one remains
operQueueList = operQos.getQueueList();
Assert.assertNotNull(operQueueList);
for (QueueList queueEntry : queueList) {
- if (queueEntry.getQueueUuid().equals(queue2Uuid))
- Assert.assertTrue(operQueueList.contains(queueEntry));
- else if (queueEntry.getQueueUuid().equals(queue1Uuid)) {
- Assert.assertFalse(operQueueList.contains(queueEntry));
+ if (queueEntry.getQueueUuid().equals(queue2Uuid)) {
+ Assert.assertTrue(isQueueInList(operQueueList, queueEntry));
+ } else if (queueEntry.getQueueUuid().equals(queue1Uuid)) {
+ Assert.assertFalse(isQueueInList(operQueueList, queueEntry));
} else {
Assert.assertTrue("Unknown queue entry in qos queue list", false);
}
}
}
+ private Boolean isQueueInList(List<QueueList> queueList, QueueList queue) {
+ for (QueueList queueEntry : queueList) {
+ if (queueEntry.getQueueNumber().equals(queue.getQueueNumber())
+ && queueEntry.getQueueUuid().equals(queue.getQueueUuid())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* <p>
* Representation of a southbound test case. Each test case has a name, a list of input values and a list of