Add support for setting the db schema version 42/42342/2
authorSam Hague <shague@redhat.com>
Fri, 22 Jul 2016 01:38:49 +0000 (21:38 -0400)
committerSam Hague <shague@redhat.com>
Sat, 23 Jul 2016 13:13:01 +0000 (09:13 -0400)
The db schema was a field in the ovsdb.yang but it was never copied
from the ovsdb to mdsal.

Also removed IT test code that was getting the schema version
via connecting to the ovsdb nodes.

Change-Id: Id7a49f9832c27eec746aeff9d190e9295dbd3244
Signed-off-by: Sam Hague <shague@redhat.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommandTest.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIntegrationTestUtils.java [deleted file]

index ea822d1f26fbf3716fb519f4d6946a0b331e71f3..431df7317f97fa2b269d62bbcb2acb0f4902fd6a 100644 (file)
@@ -76,7 +76,8 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand {
 
             OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder();
 
-            setVersion(ovsdbNodeBuilder, openVSwitch);
+            setDbVersion(ovsdbNodeBuilder, openVSwitch);
+            setOvsVersion(ovsdbNodeBuilder, openVSwitch);
             setDataPathTypes(ovsdbNodeBuilder, openVSwitch);
             setInterfaceTypes(ovsdbNodeBuilder, openVSwitch);
             OpenVSwitch oldEntry = deletedOpenVSwitchRows.get(entry.getKey());
@@ -238,8 +239,7 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
-    private void setVersion(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder,
-            OpenVSwitch openVSwitch) {
+    private void setOvsVersion(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder, OpenVSwitch openVSwitch) {
         try {
             ovsdbNodeBuilder.setOvsVersion(openVSwitch.getOvsVersionColumn().getData().iterator().next());
         } catch (NoSuchElementException e) {
@@ -247,6 +247,14 @@ public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
+    private void setDbVersion(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder, OpenVSwitch openVSwitch) {
+        try {
+            ovsdbNodeBuilder.setDbVersion(openVSwitch.getDbVersionColumn().getData().iterator().next());
+        } catch (NoSuchElementException e) {
+            LOG.debug("db_version is not set for this switch",e);
+        }
+    }
+
     private InstanceIdentifier<Node> getInstanceIdentifier(OpenVSwitch ovs) {
         if (ovs.getExternalIdsColumn() != null
                 && ovs.getExternalIdsColumn().getData() != null
index 043ed9ac5f60d554bdfe709d9586ac21858e1e3d..fcea92dfbc39bf3a36ea1372097da7dba652f3e4 100644 (file)
@@ -125,7 +125,9 @@ public class OpenVSwitchUpdateCommandTest {
         PowerMockito.whenNew(OvsdbNodeAugmentationBuilder.class).withNoArguments().thenReturn(ovsdbNodeBuilder);
 
         //suppress the setter methods of the class
-        MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setVersion",
+        MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setOvsVersion",
+                OvsdbNodeAugmentationBuilder.class, OpenVSwitch.class));
+        MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setDbVersion",
                 OvsdbNodeAugmentationBuilder.class, OpenVSwitch.class));
         MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setDataPathTypes",
                 OvsdbNodeAugmentationBuilder.class, OpenVSwitch.class));
@@ -364,7 +366,7 @@ public class OpenVSwitchUpdateCommandTest {
 
     @Test
     @SuppressWarnings("unchecked")
-    public void testSetVersion() throws Exception {
+    public void testSetOvsVersion() throws Exception {
         OpenVSwitch openVSwitch = mock(OpenVSwitch.class);
         Column<GenericTableSchema, Set<String>> column = mock(Column.class);
         when(openVSwitch.getOvsVersionColumn()).thenReturn(column);
@@ -374,10 +376,25 @@ public class OpenVSwitchUpdateCommandTest {
         OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = mock(OvsdbNodeAugmentationBuilder.class);
         when(ovsdbNodeBuilder.setOvsVersion(anyString())).thenReturn(ovsdbNodeBuilder);
 
-        Whitebox.invokeMethod(openVSwitchUpdateCommand, "setVersion", ovsdbNodeBuilder, openVSwitch);
+        Whitebox.invokeMethod(openVSwitchUpdateCommand, "setOvsVersion", ovsdbNodeBuilder, openVSwitch);
         verify(ovsdbNodeBuilder).setOvsVersion(anyString());
         verify(openVSwitch).getOvsVersionColumn();
+    }
 
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testSetDbVersion() throws Exception {
+        OpenVSwitch openVSwitch = mock(OpenVSwitch.class);
+        Column<GenericTableSchema, Set<String>> column = mock(Column.class);
+        when(openVSwitch.getDbVersionColumn()).thenReturn(column);
+        Set<String> set = new HashSet<>();
+        set.add("7.6.1");
+        when(column.getData()).thenReturn(set);
+        OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = mock(OvsdbNodeAugmentationBuilder.class);
+        when(ovsdbNodeBuilder.setOvsVersion(anyString())).thenReturn(ovsdbNodeBuilder);
 
+        Whitebox.invokeMethod(openVSwitchUpdateCommand, "setDbVersion", ovsdbNodeBuilder, openVSwitch);
+        verify(ovsdbNodeBuilder).setDbVersion(anyString());
+        verify(openVSwitch).getDbVersionColumn();
     }
 }
\ No newline at end of file
index 6817bfa1850b8b5a615816fdd105922c7f495e98..612e32abdf0c58925f188f6ddba2eb687bab96e2 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.ovsdb.southbound.it;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 import static org.ops4j.pax.exam.CoreOptions.maven;
@@ -16,6 +17,10 @@ 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.ImmutableList;
+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;
@@ -26,10 +31,8 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
-
 import javax.annotation.Nullable;
 import javax.inject.Inject;
-
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Assume;
@@ -44,12 +47,9 @@ import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 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;
@@ -125,6 +125,7 @@ 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.port._interface.attributes.TrunksBuilder;
 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.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
 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;
@@ -145,15 +146,11 @@ import org.ops4j.pax.exam.karaf.options.LogLevelOption;
 import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
 import org.osgi.framework.BundleContext;
 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
  *
@@ -176,10 +173,9 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     private static MdsalUtils mdsalUtils = null;
     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 @Filter(timeout=60000)
+    private static DataBroker dataBroker = null;
 
     @Inject
     private BundleContext bundleContext;
@@ -385,11 +381,11 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         } catch (Exception e) {
             LOG.warn("Failed to setup test", e);
         }
-        //dataBroker = getSession().getSALService(DataBroker.class);
-        Thread.sleep(3000);
-        dataBroker = SouthboundProvider.getDb();
         Assert.assertNotNull("db should not be null", dataBroker);
 
+        LOG.info("sleeping for 10s to let the features finish installing");
+        Thread.sleep(10000);
+
         addressStr = bundleContext.getProperty(SouthboundITConstants.SERVER_IPADDRESS);
         String portStr = bundleContext.getProperty(SouthboundITConstants.SERVER_PORT);
         try {
@@ -408,6 +404,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         }
 
         mdsalUtils = new MdsalUtils(dataBroker);
+        assertTrue("Did not find " + SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue(), getOvsdbTopology());
         final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
         final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
         dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
@@ -416,17 +413,10 @@ public class SouthboundIT extends AbstractMdsalTestBase {
                 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());
-        }
+        OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+        assertNotNull("The OvsdbNodeAugmentation cannot be null", ovsdbNodeAugmentation);
+        schemaVersion = Version.fromString(ovsdbNodeAugmentation.getDbVersion());
+        LOG.info("schemaVersion = {}", schemaVersion);
 
         // Let's count the test methods (we need to use this instead of @AfterClass on teardown() since the latter is
         // useless with pax-exam)
@@ -463,6 +453,30 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         }
     }
 
+    private Boolean getOvsdbTopology() {
+        LOG.info("getOvsdbTopology: looking for {}...", SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue());
+        Boolean found = false;
+        final TopologyId topologyId = SouthboundUtils.OVSDB_TOPOLOGY_ID;
+        InstanceIdentifier<Topology> path =
+                InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
+        for (int i = 0; i < 60; i++) {
+            Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
+            if (topology != null) {
+                LOG.info("getOvsdbTopology: found {}...", SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue());
+                found = true;
+                break;
+            } else {
+                LOG.info("getOvsdbTopology: still looking ({})...", i);
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    LOG.warn("Interrupted while waiting for {}", SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue(), e);
+                }
+            }
+        }
+        return found;
+    }
+
     /**
      * Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
      * 6640. This test will wait for incoming connections for {@link SouthboundITConstants#CONNECTION_INIT_TIMEOUT} ms.
@@ -669,6 +683,13 @@ public class SouthboundIT extends AbstractMdsalTestBase {
         assertNotNull(ovsdbNodeAugmentation.getOvsVersion());
     }
 
+    @Test
+    public void testOvsdbNodeDbVersion() throws InterruptedException {
+        OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+        Assert.assertNotNull(ovsdbNodeAugmentation);
+        assertNotNull(ovsdbNodeAugmentation.getDbVersion());
+    }
+
     @Test
     public void testOpenVSwitchOtherConfig() throws InterruptedException {
         OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIntegrationTestUtils.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIntegrationTestUtils.java
deleted file mode 100644 (file)
index 00993f8..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright © 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 java.io.IOException;
-import java.net.InetAddress;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-import org.opendaylight.ovsdb.lib.OvsdbClient;
-import org.opendaylight.ovsdb.lib.OvsdbConnection;
-import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
-import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
-import org.osgi.framework.Bundle;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Utilities for OVSDB Southbound integration tests.
- */
-public final class SouthboundIntegrationTestUtils {
-    public final static String OPEN_VSWITCH_SCHEMA = "Open_vSwitch";
-    public final static String HARDWARE_VTEP = "hardware_vtep";
-    private static final Logger LOG = LoggerFactory.getLogger(SouthboundIntegrationTestUtils.class);
-
-    /**
-     * Prevent instantiation of a utility class.
-     */
-    private SouthboundIntegrationTestUtils() {
-        // Nothing to do
-    }
-
-    public static OvsdbClient getTestConnection(BindingAwareProvider provider) throws IOException, InterruptedException, ExecutionException, TimeoutException {
-        Properties props = System.getProperties();
-        String addressStr = props.getProperty(SouthboundITConstants.SERVER_IPADDRESS);
-        String portStr = props.getProperty(SouthboundITConstants.SERVER_PORT, SouthboundITConstants.DEFAULT_SERVER_PORT);
-        String connectionType = props.getProperty(SouthboundITConstants.CONNECTION_TYPE, "active");
-        LOG.info("addressStr:{}, portStr:{}, connectionType:{}", addressStr, portStr, connectionType);
-
-        // If the connection type is active, controller connects to the ovsdb-server
-        if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_ACTIVE)) {
-            if (addressStr == null) {
-                throw new IllegalArgumentException(usage());
-            }
-
-            InetAddress address;
-            try {
-                address = InetAddress.getByName(addressStr);
-            } catch (Exception e) {
-                System.out.println("Unable to resolve " + addressStr);
-                e.printStackTrace();
-                return null;
-            }
-
-            Integer port;
-            try {
-                port = Integer.parseInt(portStr);
-            } catch (NumberFormatException e) {
-                System.out.println("Invalid port number : " + portStr);
-                e.printStackTrace();
-                return null;
-            }
-
-            OvsdbConnection connection = (OvsdbConnection) ServiceHelper.getGlobalInstance(OvsdbConnection.class, provider);
-            return connection.connect(address, port);
-        } else if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_PASSIVE)) {
-            ExecutorService executor = Executors.newFixedThreadPool(1);
-            Future<OvsdbClient> passiveConnection = executor.submit(new PassiveListener());
-            return passiveConnection.get(60, TimeUnit.SECONDS);
-        }
-        throw new IllegalArgumentException("Connection parameter (" + SouthboundITConstants.CONNECTION_TYPE + ") must be either active or passive");
-    }
-
-    public static String bundleStateToString(int state) {
-        switch (state) {
-            case Bundle.ACTIVE:
-                return "ACTIVE";
-            case Bundle.INSTALLED:
-                return "INSTALLED";
-            case Bundle.RESOLVED:
-                return "RESOLVED";
-            case Bundle.UNINSTALLED:
-                return "UNINSTALLED";
-            default:
-                return "Not CONVERTED";
-        }
-    }
-
-    private static String usage() {
-        return "Integration Test needs a valid connection configuration as follows :\n" +
-                "active connection : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"+
-                "passive connection : mvn -Pintegrationtest -Dovsdbserver.connection=passive verify\n";
-    }
-
-    private static class PassiveListener implements Callable<OvsdbClient>, OvsdbConnectionListener {
-        OvsdbClient client = null;
-        @Override
-        public OvsdbClient call() throws Exception {
-            OvsdbConnection connection = (OvsdbConnection)ServiceHelper.getGlobalInstance(OvsdbConnection.class, this);
-            connection.registerConnectionListener(this);
-            while (client == null) {
-                Thread.sleep(500);
-            }
-            return client;
-        }
-
-        @Override
-        public void connected(OvsdbClient client) {
-            this.client = client;
-        }
-
-        @Override
-        public void disconnected(OvsdbClient client) {
-            if (!Objects.equals(this.client.getConnectionInfo(), client.getConnectionInfo())) {
-                throw new IllegalStateException("disconnected unexpected client");
-            }
-            this.client = null;
-        }
-    }
-
-}