2 * Copyright (C) 2014 EBay Software Foundation
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Ashwin Raveendran, Madhu Venugopal
11 package org.opendaylight.ovsdb.integrationtest.ovsdbclient;
13 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
15 import com.google.common.collect.ImmutableMap;
16 import com.google.common.collect.Sets;
17 import com.google.common.util.concurrent.ListenableFuture;
18 import java.io.IOException;
19 import java.lang.reflect.InvocationTargetException;
20 import java.util.List;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.TimeoutException;
24 import org.junit.After;
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.opendaylight.ovsdb.lib.OvsdbClient;
30 import org.opendaylight.ovsdb.lib.it.LibraryIntegrationTestBase;
31 import org.opendaylight.ovsdb.lib.it.LibraryIntegrationTestUtils;
32 import org.opendaylight.ovsdb.lib.notation.Mutator;
33 import org.opendaylight.ovsdb.lib.notation.UUID;
34 import org.opendaylight.ovsdb.lib.operations.OperationResult;
35 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
36 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
37 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
38 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
39 import org.opendaylight.ovsdb.lib.schema.TableSchema;
40 import org.ops4j.pax.exam.junit.PaxExam;
41 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
42 import org.ops4j.pax.exam.spi.reactors.PerSuite;
44 @RunWith(PaxExam.class)
45 @ExamReactorStrategy(PerSuite.class)
46 public class OvsdbClientTestTypedIT extends LibraryIntegrationTestBase {
49 DatabaseSchema dbSchema = null;
50 static String testBridgeName = "br_test";
51 static UUID testBridgeUuid = null;
54 * Test creation of statically typed bridge table as defined in
55 * ovs-vswitchd.conf.db with get/set for all relevant columns. The
56 * SETDATA methods for "name", "status" and "flood_vlans" columns
60 public void testTypedBridgeCreate() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
61 TestBridge rBridge = ovs.createTypedRowWrapper(TestBridge.class);
62 rBridge.setName(testBridgeName);
63 rBridge.setStatus(ImmutableMap.of("key","value"));
64 rBridge.setFloodVlans(Sets.newHashSet(34));
66 GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class);
67 ColumnSchema<GenericTableSchema, Set<UUID>> bridges = ovsTable.multiValuedColumn("bridges", UUID.class);
69 String namedUuid = "br_test";
70 int insertOperationIndex = 0;
72 TransactionBuilder transactionBuilder = ovs.transactBuilder(dbSchema)
73 .add(op.insert(rBridge)
75 .add(op.mutate(ovsTable)
76 .addMutation(bridges, Mutator.INSERT, Sets.newHashSet(new UUID(namedUuid))));
78 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
79 List<OperationResult> operationResults = results.get();
80 Assert.assertFalse(operationResults.isEmpty());
81 // Check if Results matches the number of operations in transaction
82 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
83 System.out.println("Insert & Update operation results = " + operationResults);
84 testBridgeUuid = operationResults.get(insertOperationIndex).getUuid();
87 public void testGetDBs() throws ExecutionException, InterruptedException {
88 ListenableFuture<List<String>> databases = ovs.getDatabases();
89 List<String> dbNames = databases.get();
90 Assert.assertNotNull(dbNames);
91 boolean hasOpenVswitchSchema = false;
92 for(String dbName : dbNames) {
93 if (dbName.equals(LibraryIntegrationTestUtils.OPEN_VSWITCH_SCHEMA)) {
94 hasOpenVswitchSchema = true;
98 Assert.assertTrue(LibraryIntegrationTestUtils.OPEN_VSWITCH_SCHEMA
99 + " schema is not supported by the switch", hasOpenVswitchSchema);
103 public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
107 ovs = LibraryIntegrationTestUtils.getTestConnection(this);
109 dbSchema = ovs.getSchema(LibraryIntegrationTestUtils.OPEN_VSWITCH_SCHEMA).get();
113 public void tearDown() throws InterruptedException, ExecutionException {
114 TableSchema<GenericTableSchema> bridge = dbSchema.table("Bridge", GenericTableSchema.class);
115 ColumnSchema<GenericTableSchema, String> name = bridge.column("name", String.class);
116 GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class);
117 ColumnSchema<GenericTableSchema, Set<UUID>> bridges = ovsTable.multiValuedColumn("bridges", UUID.class);
119 ListenableFuture<List<OperationResult>> results = ovs.transactBuilder(dbSchema)
120 .add(op.delete(bridge)
121 .where(name.opEqual(testBridgeName))
123 .add(op.mutate(ovsTable)
124 .addMutation(bridges, Mutator.DELETE, Sets.newHashSet(testBridgeUuid)))
125 .add(op.commit(true))
128 List<OperationResult> operationResults = results.get();
129 System.out.println("Delete operation results = " + operationResults);