/* * Copyright (C) 2014 EBay Software Foundation * * 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 * * Authors : Ashwin Raveendran, Madhu Venugopal */ package org.opendaylight.ovsdb.integrationtest.ovsdbclient; import static org.opendaylight.ovsdb.lib.operations.Operations.op; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import com.google.common.util.concurrent.ListenableFuture; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.opendaylight.ovsdb.lib.OvsdbClient; import org.opendaylight.ovsdb.lib.it.LibraryIntegrationTestBase; import org.opendaylight.ovsdb.lib.it.LibraryIntegrationTestUtils; import org.opendaylight.ovsdb.lib.notation.Mutator; import org.opendaylight.ovsdb.lib.notation.UUID; import org.opendaylight.ovsdb.lib.operations.OperationResult; import org.opendaylight.ovsdb.lib.operations.TransactionBuilder; import org.opendaylight.ovsdb.lib.schema.ColumnSchema; import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.lib.schema.TableSchema; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerSuite; @RunWith(PaxExam.class) @ExamReactorStrategy(PerSuite.class) public class OvsdbClientTestTypedIT extends LibraryIntegrationTestBase { OvsdbClient ovs; DatabaseSchema dbSchema = null; static String testBridgeName = "br_test"; static UUID testBridgeUuid = null; /** * Test creation of statically typed bridge table as defined in * ovs-vswitchd.conf.db with get/set for all relevant columns. The * SETDATA methods for "name", "status" and "flood_vlans" columns * are verified. */ @Test public void testTypedBridgeCreate() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { TestBridge rBridge = ovs.createTypedRowWrapper(TestBridge.class); rBridge.setName(testBridgeName); rBridge.setStatus(ImmutableMap.of("key","value")); rBridge.setFloodVlans(Sets.newHashSet(34)); GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class); ColumnSchema> bridges = ovsTable.multiValuedColumn("bridges", UUID.class); String namedUuid = "br_test"; int insertOperationIndex = 0; TransactionBuilder transactionBuilder = ovs.transactBuilder(dbSchema) .add(op.insert(rBridge) .withId(namedUuid)) .add(op.mutate(ovsTable) .addMutation(bridges, Mutator.INSERT, Sets.newHashSet(new UUID(namedUuid)))); ListenableFuture> results = transactionBuilder.execute(); List operationResults = results.get(); Assert.assertFalse(operationResults.isEmpty()); // Check if Results matches the number of operations in transaction Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size()); System.out.println("Insert & Update operation results = " + operationResults); testBridgeUuid = operationResults.get(insertOperationIndex).getUuid(); } public void testGetDBs() throws ExecutionException, InterruptedException { ListenableFuture> databases = ovs.getDatabases(); List dbNames = databases.get(); Assert.assertNotNull(dbNames); boolean hasOpenVswitchSchema = false; for(String dbName : dbNames) { if (dbName.equals(LibraryIntegrationTestUtils.OPEN_VSWITCH_SCHEMA)) { hasOpenVswitchSchema = true; break; } } Assert.assertTrue(LibraryIntegrationTestUtils.OPEN_VSWITCH_SCHEMA + " schema is not supported by the switch", hasOpenVswitchSchema); } @Before public void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException { if (ovs != null) { return; } ovs = LibraryIntegrationTestUtils.getTestConnection(this); testGetDBs(); dbSchema = ovs.getSchema(LibraryIntegrationTestUtils.OPEN_VSWITCH_SCHEMA).get(); } @After public void tearDown() throws InterruptedException, ExecutionException { TableSchema bridge = dbSchema.table("Bridge", GenericTableSchema.class); ColumnSchema name = bridge.column("name", String.class); GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class); ColumnSchema> bridges = ovsTable.multiValuedColumn("bridges", UUID.class); ListenableFuture> results = ovs.transactBuilder(dbSchema) .add(op.delete(bridge) .where(name.opEqual(testBridgeName)) .build()) .add(op.mutate(ovsTable) .addMutation(bridges, Mutator.DELETE, Sets.newHashSet(testBridgeUuid))) .add(op.commit(true)) .execute(); List operationResults = results.get(); System.out.println("Delete operation results = " + operationResults); ovs.disconnect(); } }