Removing the Open_vSwitch schema hardcoding in OvsDBClient. 70/7470/1
authorMadhu Venugopal <mavenugo@gmail.com>
Wed, 28 May 2014 22:26:27 +0000 (15:26 -0700)
committerMadhu Venugopal <mavenugo@gmail.com>
Wed, 28 May 2014 22:26:27 +0000 (15:26 -0700)
Though it is an harmless constant string, it goes against the motivation of the library redesign to be
schema independent. Hence moving the schema string to a more appropriate place (to the applications),
in this case, to the Integration Test files.
Also, modified the initialize functionality to include a test to check for the list_dbs to contain Open_vSwitch
schema as all the tests in this file are based on Open_vSwitch schema tables.

Change-Id: I3210abf1fa18b5707a27b719f7d481b5de76d6be
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
library/src/main/java/org/opendaylight/ovsdb/lib/OvsDBClient.java
library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestIT.java
library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestITTyped.java
library/src/test/java/org/opendaylight/ovsdb/lib/OvsdbTestBase.java
library/src/test/java/org/opendaylight/ovsdb/lib/schema/temp/SchemaObjs.java

index 404f5e6b6f253832b1042b78e5c5f0887168ec81..1ae226184afcb97911f90829f1633cf203bcd8eb 100644 (file)
@@ -12,7 +12,8 @@
 
 package org.opendaylight.ovsdb.lib;
 
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.List;
+
 import org.opendaylight.ovsdb.lib.message.MonitorRequest;
 import org.opendaylight.ovsdb.lib.operations.Operation;
 import org.opendaylight.ovsdb.lib.operations.OperationResult;
@@ -20,7 +21,7 @@ import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.TableSchema;
 
-import java.util.List;
+import com.google.common.util.concurrent.ListenableFuture;
 
 /**
  * The main interface to interact with a device speaking ovsdb protocol in an asynchronous fashion and hence most
@@ -28,11 +29,6 @@ import java.util.List;
  */
 public interface OvsDBClient {
 
-    /**
-     * Represents the Open Vswitch Schema
-     */
-    String OPEN_VSWITCH_SCHEMA = "Open_vSwitch";
-
     /**
      * Gets the list of database names exposed by this ovsdb capable device
      * @return list of database names
index 2a25b22a64f68462590fa7afbbc1ba44380f3283..0980493c9b4268043f8db9d7d7f13f744ae96348 100644 (file)
@@ -52,7 +52,7 @@ public class OvsDBClientTestIT extends OvsdbTestBase {
     @Test
     public void testTransact() throws IOException, InterruptedException, ExecutionException {
 
-        ListenableFuture<DatabaseSchema> schema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true);
+        ListenableFuture<DatabaseSchema> schema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true);
         TableSchema<GenericTableSchema> bridge = schema.get().table("Bridge", GenericTableSchema.class);
 
         for (Map.Entry<String, ColumnSchema> names : bridge.getColumnSchemas().entrySet()) {
@@ -142,7 +142,7 @@ public class OvsDBClientTestIT extends OvsdbTestBase {
     @Test
     public void testMonitorRequest() throws ExecutionException, InterruptedException {
 
-        DatabaseSchema dbSchema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get();
+        DatabaseSchema dbSchema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get();
         GenericTableSchema bridge = dbSchema.table("Bridge", GenericTableSchema.class);
 
         List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
@@ -182,16 +182,22 @@ public class OvsDBClientTestIT extends OvsdbTestBase {
         Assert.assertNotNull(bridgeUpdate);
     }
 
-    @Test
     public void testGetDBs() throws ExecutionException, InterruptedException {
         ListenableFuture<List<String>> databases = ovs.getDatabases();
         List<String> dbNames = databases.get();
         Assert.assertNotNull(dbNames);
-        Assert.assertTrue(dbNames.size() > 0);
+        boolean hasOpenVswitchSchema = false;
+        for(String dbName : dbNames) {
+           if (dbName.equals(OPEN_VSWITCH_SCHEMA)) {
+                hasOpenVswitchSchema = true;
+                break;
+           }
+        }
+        Assert.assertTrue(OPEN_VSWITCH_SCHEMA+" schema is not supported by the switch", hasOpenVswitchSchema);
     }
 
     @Before
-    public  void initalize() throws IOException {
+    public  void initalize() throws IOException, ExecutionException, InterruptedException {
         if (ovs != null) {
             return;
         }
@@ -201,6 +207,7 @@ public class OvsDBClientTestIT extends OvsdbTestBase {
         }
         ExecutorService executorService = Executors.newFixedThreadPool(3);
         ovs = new OvsDBClientImpl(rpc, executorService);
+        testGetDBs();
     }
 
 
index d52ae593211d2190789462a633812ba0893fd826..d104ea62e9011cffb30cfb5d387bc8111cd01b20 100644 (file)
@@ -65,7 +65,7 @@ public class OvsDBClientTestITTyped extends OvsdbTestBase {
     public void test() throws IOException, InterruptedException, ExecutionException {
         OvsDBClientImpl ovs = getVswitch();
 
-        Bridge bridge = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class);
+        Bridge bridge = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class);
 
         ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
                 .add(op.insert(bridge).value(bridge.name(), "br-int"))
index c70f79a0543f35777f4b2f04aaedf80a5ea85e10..7d7ba63900cabdeaa98806d1ee92883fe6b4129b 100644 (file)
@@ -42,6 +42,11 @@ public abstract class OvsdbTestBase implements OvsdbRPC.Callback{
     private final static String SERVER_PORT = "ovsdbserver.port";
     private final static String DEFAULT_SERVER_PORT = "6640";
 
+    /**
+     * Represents the Open Vswitch Schema
+     */
+    public final static String OPEN_VSWITCH_SCHEMA = "Open_vSwitch";
+
     public Properties loadProperties() {
         Properties props = new Properties(System.getProperties());
         return props;
index a93ba0bf3f499ef0d51979f99e4ca05a9ff84f86..7b114f5abb654c3ecb5ee8f73d3546de75628bac 100644 (file)
@@ -9,17 +9,16 @@
  */
 package org.opendaylight.ovsdb.lib.schema.temp;
 
-import org.opendaylight.ovsdb.lib.OvsDBClient;
+import java.util.concurrent.ExecutionException;
+
 import org.opendaylight.ovsdb.lib.OvsDBClientImpl;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.OvsdbTestBase;
 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.TableSchema;
 
-import java.util.concurrent.ExecutionException;
-
 
 public class SchemaObjs {
-
     public static class Bridge extends TableSchema<Bridge> {
         public static String NAME = "Bridge";
         TableSchema target;
@@ -54,7 +53,7 @@ public class SchemaObjs {
     public static void main(String[] args) throws ExecutionException, InterruptedException {
 
         OvsDBClientImpl ovs = new OvsDBClientImpl(null, null);
-        DatabaseSchema db = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get();
+        DatabaseSchema db = ovs.getSchema(OvsdbTestBase.OPEN_VSWITCH_SCHEMA, true).get();
         Bridge bridge = db.table(Bridge.NAME, Bridge.class);
         Port port = db.table(Port.NAME, Port.class);