Integration tests for AutoAttach Table 52/35952/11
authorRashmi Pujar <rpujar@inocybe.com>
Tue, 8 Mar 2016 19:53:35 +0000 (14:53 -0500)
committerRashmi Pujar <rpujar@inocybe.com>
Fri, 11 Mar 2016 17:55:22 +0000 (12:55 -0500)
- IT test for library/schema
- IT for southbound

Change-Id: I5e6d665aba7bc2c20fcf264d1f06ed62070630e0
Signed-off-by: Rashmi Pujar <rpujar@inocybe.com>
library/it/src/test/java/org/opendaylight/ovsdb/integrationtest/schema/openvswitch/OpenVSwitchIT.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java

index 079ac5c10ffd1a4de9bde0678f6d44fdbe2f9708..cad4a5e129d9304e1e84ddf1a2ff105e605b65bc 100644 (file)
@@ -56,6 +56,7 @@ import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
 import org.opendaylight.ovsdb.lib.schema.TableSchema;
 import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
+import org.opendaylight.ovsdb.schema.openvswitch.AutoAttach;
 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
 import org.opendaylight.ovsdb.schema.openvswitch.Controller;
 import org.opendaylight.ovsdb.schema.openvswitch.FlowSampleCollectorSet;
@@ -107,12 +108,14 @@ public class OpenVSwitchIT extends LibraryIntegrationTestBase {
     private UUID testQueueUuid = null;
     private UUID testSFlowUuid = null;
     private UUID testSslUuid = null;
+    private UUID testAutoattachUuid = null;
     private Version flowSampleCollectorSetFromVersion = Version.fromString("7.1.0");
     private Version flowTableFromVersion = Version.fromString("6.5.0");
     private Version prefixesAddedVersion = Version.fromString("7.4.0");
     private Version externalIdAddedVerson = Version.fromString("7.5.0");
     private Version ipfixFromVersion = Version.fromString("7.1.0");
     private Version ipfixCacheFromVersion = Version.fromString("7.3.0");
+    private Version autoAttachFromVersion = Version.fromString("7.11.2");
 
     private static Map<String, Map<UUID, Row>> tableCache = new HashMap<>();
     private static Map<String, Map<UUID, Row>> getTableCache () {
@@ -1000,6 +1003,78 @@ public class OpenVSwitchIT extends LibraryIntegrationTestBase {
         bridgeDelete(testBridgeUuid);
     }
 
+    public void autoAttachInsert() throws ExecutionException, InterruptedException {
+        String autoattachUuid = "testAutoattachUuid";
+        String systemName = "testSystemName";
+        String systemDescription = "testSystemDescription";
+        Map<Long, Long> mappings = ImmutableMap.of(100L, 200L);
+
+        // FIXME: Add external_ids column when it is supported in ovs
+        AutoAttach autoattach = getClient().createTypedRowWrapper(AutoAttach.class);
+        autoattach.setSystemName(systemName);
+        autoattach.setSystemDescription(systemDescription);
+        autoattach.setMappings(mappings);
+
+        Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
+        TransactionBuilder transactionBuilder = getClient().transactBuilder(getDbSchema())
+                .add(op.insert(autoattach.getSchema())
+                        .withId(autoattachUuid)
+                        .value(autoattach.getSystemNameColumn())
+                        .value(autoattach.getSystemDescriptionColumn())
+                        .value(autoattach.getMappingsColumn()))
+                .add(op.comment("Autoattach: Inserting " + autoattachUuid))
+                .add(op.mutate(bridge.getSchema())
+                        .addMutation(bridge.getAutoAttachColumn().getSchema(), Mutator.INSERT,
+                                Sets.newHashSet(new UUID(autoattachUuid)))
+                        .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
+                        .build())
+                .add(op.comment("Bridge: Mutating " + TEST_BRIDGE_NAME));
+
+        int insertAutoattachOperationIndex = 0;
+        List<OperationResult> operationResults = executeTransaction(transactionBuilder,
+                "Insert and Mutate operation results for AutoAttach and Bridge");
+
+        testAutoattachUuid = operationResults.get(insertAutoattachOperationIndex).getUuid();
+        assertNotNull(ASSERT_TRANS_UUID, testAutoattachUuid);
+
+        // Verify that the local cache was updated with the remote changes
+        Row autoattachRow = getTableCache().get(autoattach.getSchema().getName()).get(testAutoattachUuid);
+        AutoAttach monitoredAutoattach = getClient().getTypedRowWrapper(AutoAttach.class, autoattachRow);
+        assertEquals(autoattach.getSystemNameColumn().getData(), monitoredAutoattach.getSystemNameColumn().getData());
+    }
+
+    public void autoAttachDelete() throws ExecutionException, InterruptedException {
+        AutoAttach autoattach = getClient().getTypedRowWrapper(AutoAttach.class, null);
+        Bridge bridge = getClient().getTypedRowWrapper(Bridge.class, null);
+        DatabaseSchema dbSchema = getClient().getSchema(LibraryIntegrationTestUtils.OPEN_VSWITCH_SCHEMA).get();
+        TransactionBuilder transactionBuilder = getClient().transactBuilder(dbSchema)
+                .add(op.delete(autoattach.getSchema())
+                        .where(autoattach.getUuidColumn().getSchema().opEqual(testAutoattachUuid))
+                        .build())
+                .add(op.comment("AutoAttach: Deleting " + testAutoattachUuid))
+                .add(op.mutate(bridge.getSchema()) // Delete auto_attach column in the Bridge table
+                        .addMutation(bridge.getAutoAttachColumn().getSchema(), Mutator.DELETE,
+                                Sets.newHashSet(testAutoattachUuid)))
+                .add(op.comment("Bridge: Mutating " + testAutoattachUuid))
+                .add(op.commit(true));
+        executeTransaction(transactionBuilder, "AutoAttach, Bridge auto_attach column: Delete operation results");
+
+        // Verify if autoattach was deleted
+        autoattach = getClient().getTypedRowWrapper(AutoAttach.class, null);
+        assertNull(autoattach.getUuid());
+    }
+
+    @Test
+    public void testAutoAttach() throws ExecutionException, InterruptedException {
+        // Don't run this test if the table is not supported
+        assumeTrue(schemaVersion.compareTo(autoAttachFromVersion) >= 0);
+
+        testBridgeUuid = bridgeInsert();
+        autoAttachInsert();
+        autoAttachDelete();
+        bridgeDelete(testBridgeUuid);
+    }
+
     public void qosInsert() throws ExecutionException, InterruptedException {
         String portUuidStr = "testQosPortUuid";
         String intfUuidStr = "testQosIntfUuid";
index 9a2848c28402a8bee0812b8a316eb974848cb6ff..e9bf4995d319cf702969561e6592bdf94e743a5b 100644 (file)
@@ -77,6 +77,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Autoattach;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.AutoattachBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.AutoattachKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.DatapathTypeEntry;
@@ -89,6 +92,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.Queues;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.QueuesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.autoattach.AutoattachExternalIds;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.autoattach.AutoattachExternalIdsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.autoattach.Mappings;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.autoattach.MappingsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIds;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosExternalIdsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.qos.entries.QosOtherConfig;
@@ -140,6 +147,8 @@ import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * Integration tests for southbound-impl
  *
@@ -838,6 +847,172 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         }
     }
 
+    private static class TestAutoAttach implements AutoCloseable {
+        private final ConnectionInfo connectionInfo;
+        private final Uri autoattachId;
+        private final Uri bridgeId;
+
+        public TestAutoAttach (final ConnectionInfo connectionInfo,
+                final Uri autoattachId,
+                final Uri bridgeId,
+                @Nullable final String systemName,
+                @Nullable final String systemDescription,
+                @Nullable final List<Mappings> mappings,
+                @Nullable final List<AutoattachExternalIds> externalIds) {
+            this.connectionInfo = connectionInfo;
+            this.autoattachId = autoattachId;
+            this.bridgeId = bridgeId;
+
+            Autoattach aaEntry = new AutoattachBuilder()
+                    .setAutoattachId(autoattachId)
+                    .setBridgeId(bridgeId)
+                    .setSystemName(systemName)
+                    .setSystemDescription(systemDescription)
+                    .setMappings(mappings)
+                    .setAutoattachExternalIds(externalIds)
+                    .build();
+            InstanceIdentifier<Autoattach> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo)
+                    .augmentation(OvsdbNodeAugmentation.class)
+                    .child(Autoattach.class, aaEntry.getKey());
+            final NotifyingDataChangeListener aaOperationalListener =
+                    new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, iid);
+            aaOperationalListener.registerDataChangeListener();
+
+            Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, iid, aaEntry));
+            try {
+                aaOperationalListener.waitForCreation(OVSDB_ROUNDTRIP_TIMEOUT);
+            } catch (InterruptedException e) {
+                LOG.warn("Sleep interrupted while waiting for queue {}", iid, e);
+            }
+        }
+        @Override
+        public void close() {
+            final InstanceIdentifier<Autoattach> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo)
+                    .augmentation(OvsdbNodeAugmentation.class)
+                    .child(Autoattach.class, new AutoattachKey(this.autoattachId));
+            final NotifyingDataChangeListener aaOperationalListener =
+                    new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, iid);
+            aaOperationalListener.registerDataChangeListener();
+
+            Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid));
+            try {
+                aaOperationalListener.waitForDeletion(OVSDB_ROUNDTRIP_TIMEOUT);
+            } catch (InterruptedException e) {
+                LOG.warn("Sleep interrupted while waiting for qos deletion (qos {})", iid, e);
+            }
+        }
+    }
+
+    // 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
+
+        ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
+        String testAutoattachId = new String("testAutoattachEntry");
+        String testSystemName = new String("testSystemName");
+        String testSystemDescription = new String("testSystemDescription");
+        String testAutoattachExternalKey = new String("testAutoattachExternalKey");
+        String testAutoattachExternalValue = new String("testAutoattachExternalValue");
+
+        try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) {
+            OvsdbBridgeAugmentation bridge = getBridge(connectionInfo);
+            Assert.assertNotNull(bridge);
+
+            // CREATE: Create Autoattach table
+            NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier(
+                    connectionInfo, bridge.getBridgeName()));
+            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));
+                Assert.assertNotNull(operAa);
+                Assert.assertEquals(testSystemName, operAa.getSystemName());
+                bridge = getBridge(connectionInfo);
+                Uuid aaUuid = new Uuid(operAa.getAutoattachUuid().getValue());
+                Assert.assertEquals(aaUuid, bridge.getAutoAttach());
+
+                // UPDATE: Update mappings column of AutoAttach table that was created
+                List<Mappings> mappings = ImmutableList.of(new MappingsBuilder().setMappingsKey(100L).setMappingsValue(200).build());
+                Autoattach updatedAa = new AutoattachBuilder()
+                        .setAutoattachId(new Uri(testAutoattachId))
+                        .setMappings(mappings)
+                        .build();
+                InstanceIdentifier<Autoattach> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo)
+                        .augmentation(OvsdbNodeAugmentation.class)
+                        .child(Autoattach.class, updatedAa.getKey());
+                final NotifyingDataChangeListener aaOperationalListener =
+                        new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, iid);
+                aaOperationalListener.registerDataChangeListener();
+                Assert.assertTrue(mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
+                        iid, updatedAa));
+                aaOperationalListener.waitForUpdate(OVSDB_UPDATE_TIMEOUT);
+
+                // UPDATE: Update external_ids column of AutoAttach table that was created
+                List<AutoattachExternalIds> externalIds = new ArrayList<>();
+                externalIds.add(new AutoattachExternalIdsBuilder()
+                        .setAutoattachExternalIdKey(testAutoattachExternalKey)
+                        .setAutoattachExternalIdValue(testAutoattachExternalValue)
+                        .build());
+                updatedAa = new AutoattachBuilder()
+                        .setAutoattachId(new Uri(testAutoattachId))
+                        .setAutoattachExternalIds(externalIds)
+                        .build();
+                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
+                ovsdbNodeAugmentation = getOvsdbNode(connectionInfo,
+                        LogicalDatastoreType.OPERATIONAL);
+                operAa = getAutoAttach(ovsdbNodeAugmentation, new Uri(testAutoattachId));
+                Assert.assertNotNull(operAa);
+                List<Mappings> operMappingsList = operAa.getMappings();
+                for (Mappings operMappings: operMappingsList) {
+                    Assert.assertEquals(mappings.get(operMappingsList.indexOf(operMappings)).getMappingsKey(), operMappings.getMappingsKey());
+                    Assert.assertEquals(mappings.get(operMappingsList.indexOf(operMappings)).getMappingsValue(), operMappings.getMappingsValue());
+                }
+                List<AutoattachExternalIds> operExternalIds = operAa.getAutoattachExternalIds();
+                externalIds.add(new AutoattachExternalIdsBuilder()
+                        .setAutoattachExternalIdKey(SouthboundConstants.AUTOATTACH_ID_EXTERNAL_ID_KEY)
+                        .setAutoattachExternalIdValue(operAa.getAutoattachId().getValue())
+                        .build());
+                for (AutoattachExternalIds operExternalId : operExternalIds) {
+                    Assert.assertEquals(externalIds.get(operExternalIds.indexOf(operExternalId)).getAutoattachExternalIdKey(),
+                            operExternalId.getAutoattachExternalIdKey());
+                    Assert.assertEquals(externalIds.get(operExternalIds.indexOf(operExternalId)).getAutoattachExternalIdValue(),
+                            operExternalId.getAutoattachExternalIdValue());
+                }
+
+                // DELETE: Delete AutoAttach table
+                Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid));
+                aaOperationalListener.waitForUpdate(OVSDB_UPDATE_TIMEOUT);
+                ovsdbNodeAugmentation = getOvsdbNode(connectionInfo,
+                        LogicalDatastoreType.OPERATIONAL);
+                operAa = getAutoAttach(ovsdbNodeAugmentation, new Uri(testAutoattachId));
+                Assert.assertNull(operAa);
+            }
+        }
+    }
+
+    private Autoattach getAutoAttach(OvsdbNodeAugmentation ovsdbNodeAugmentation, Uri uri) {
+        if (ovsdbNodeAugmentation.getAutoattach() != null
+                && !ovsdbNodeAugmentation.getAutoattach().isEmpty()) {
+            for (Autoattach aa : ovsdbNodeAugmentation.getAutoattach()) {
+                if (aa.getKey().getAutoattachId().equals(uri)) {
+                    return aa;
+                }
+            }
+        }
+        return null;
+    }
+
     private static class TestQos implements AutoCloseable {
         private final ConnectionInfo connectionInfo;
         private final Uri qosId;