+ public void testSetOFControllers() throws Exception {
+ Thread.sleep(5000);
+ OvsdbConnectionService
+ connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+
+ // 1. Check for the ovsdb Connection as seen by the Plugin layer
+ assertNotNull(connectionService.getNodes());
+ assertTrue(connectionService.getNodes().size() > 0);
+ Node node = connectionService.getNodes().get(0);
+ Connection connection = connectionService.getConnection(node);
+ assertNotNull(connection);
+
+ // 2. Create a bridge with a valid parent_uuid & Assert to make sure the return status is success.
+ final StatusWithUuid status = insertBridge(connection, getOpenVSwitchTableUUID(connection));
+ assertTrue(status.isSuccess());
+
+ // Thread.sleep(3000); // wait for _real_ controller to be added to bridge... or not (see below **)
+
+ // 3. Test against bug 960: Add same controller multiple times and make sure we do not end up with duplicates.
+ ovsdbConfigurationService.setOFController(node, status.getUuid().toString());
+ ovsdbConfigurationService.setOFController(node, status.getUuid().toString());
+ ovsdbConfigurationService.setOFController(node, status.getUuid().toString());
+ ovsdbConfigurationService.setOFController(node, status.getUuid().toString());
+
+ Row bridgeRow = ovsdbConfigurationService.getRow(node,
+ ovsdbConfigurationService.getTableName(node, Bridge.class),
+ status.getUuid().toString());
+ assertNotNull(bridgeRow);
+ Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
+ assertTrue(bridge.getUuid().equals(status.getUuid()));
+
+ final int currControllersSize = bridge.getControllerColumn().getData().size();
+
+ log.debug("Bridge has " + bridge.getControllerColumn().getData().size() + " controllers");
+
+ // ** Note: we assert against 2 or less -- instead of 1 -- to account for the _real_ controller's connection
+ assertTrue( "Too few controllers added to bridge object. Is this bug 960?", currControllersSize >= 1 );
+ assertTrue( "Too many controllers added to bridge object. Is this bug 960?", currControllersSize <= 2 );
+
+ // Removal of bridge created in this test is done via tearDown(). It is done that way, so cleanup is ran
+ // even if test fails.
+ }
+
+ @After
+ public void tearDown() throws InterruptedException {
+ Thread.sleep(5000);
+ OvsdbConnectionService
+ connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+
+ if (connectionService.getNodes() == null) {
+ return; // no nodes: noop
+ }
+
+ int bridgesRemoved = 0;
+ List<Node> nodes = connectionService.getNodes();
+ for (Node node : nodes) {
+ Map<String, Row> bridgeRows =
+ ovsdbConfigurationService.getRows(node, ovsdbConfigurationService.getTableName(node, Bridge.class));
+ if (bridgeRows == null) {
+ continue;
+ }
+ for (Row bridgeRow : bridgeRows.values()) {
+ Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, bridgeRow);
+ log.trace("Test clean up removing Bridge " + bridge.getUuid());
+ Status delStatus = ovsdbConfigurationService.deleteRow(node,
+ bridge.getSchema().getName(),
+ bridge.getUuid().toString());
+ assertTrue(delStatus.isSuccess());
+ bridgesRemoved++;
+ }
+ }
+
+ if (bridgesRemoved > 0) {
+ log.debug("Test clean up removed " + bridgesRemoved + " bridges");
+ Thread.sleep(2000); // TODO : Remove this Sleep once the Select operation is resolved.
+ }
+ }
+
+ public void endToEndApiTest(Connection connection, String parentUuid) throws Exception {
+ // 1. Print Cache and Assert to make sure the bridge is not created yet.
+ printCache();
+
+ // 2. Create a bridge with a valid parent_uuid & Assert to make sure the return status is success.
+ StatusWithUuid status = insertBridge(connection, parentUuid);
+ assertTrue(status.isSuccess());
+
+ Thread.sleep(2000); // TODO : Remove this Sleep once the Select operation is resolved.
+
+ // 3. Assert to make sure the bridge is created with a valid Uuid.
+ printCache();
+ Bridge bridge = connection.getClient().getTypedRowWrapper(Bridge.class, null);
+ Row bridgeRow = ovsdbConfigurationService.getRow(node, bridge.getSchema().getName(), status.getUuid().toString());
+ assertNotNull(bridgeRow);
+ bridge = connection.getClient().getTypedRowWrapper(Bridge.class, bridgeRow);
+ assertEquals(bridge.getUuid(), status.getUuid());
+
+ // 4. Delete the bridge & Assert to make sure the return status is success.
+ Status delStatus = ovsdbConfigurationService.deleteRow(node, bridge.getSchema().getName(), status.getUuid().toString());
+ assertTrue(delStatus.isSuccess());
+ Thread.sleep(2000); // TODO : Remove this Sleep once the Select operation is resolved.
+
+ // 5. Assert to make sure the bridge is deleted
+ bridgeRow = ovsdbConfigurationService.getRow(node, bridge.getSchema().getName(), status.getUuid().toString());
+ assertNull(bridgeRow);
+ }
+
+ public StatusWithUuid insertBridge(Connection connection, String parentUuid) throws Exception {
+ Bridge bridge = connection.getClient().createTypedRowWrapper(Bridge.class);
+ bridge.setName("br_test1");
+ bridge.setStatus(ImmutableMap.of("key", "value"));
+ bridge.setFloodVlans(Sets.newHashSet(34L));
+ return ovsdbConfigurationService.insertRow(node, bridge.getSchema().getName(), parentUuid, bridge.getRow());
+ }
+
+ public String getOpenVSwitchTableUUID(Connection connection) throws Exception {
+ OpenVSwitch openVSwitch = connection.getClient().getTypedRowWrapper(OpenVSwitch.class, null);
+ ConcurrentMap<String, Row> row = ovsdbConfigurationService.getRows(node, openVSwitch.getSchema().getName());
+ if (row == null || row.size() == 0) return null;
+ return (String)row.keySet().toArray()[0];
+ }
+
+ public void printCache() throws Exception {
+ List<String> tables = ovsdbConfigurationService.getTables(node);