+ public void apiTests() throws Exception {
+ Thread.sleep(5000);
+ IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
+
+ // 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);
+ OvsdbConnectionInfo connectionInfo = connection.getClient().getConnectionInfo();
+ String identifier = IDENTIFIER;
+ if (connectionInfo.getType().equals(OvsdbConnectionInfo.ConnectionType.PASSIVE)) {
+ identifier = connectionInfo.getRemoteAddress().getHostAddress()+":"+connectionInfo.getRemotePort();
+ }
+ assertEquals(Node.fromString("OVS|"+identifier), connectionService.getNodes().get(0));
+ System.out.println("Nodes = "+ connectionService.getNodes());
+ /*
+ * Test sequence :
+ * 1. Print Cache and Assert to make sure the bridge is not created yet.
+ * 2. Create a bridge with a valid parent_uuid & Assert to make sure the return status is success.
+ * 3. Assert to make sure the bridge is created with a valid Uuid.
+ * 4. Delete the bridge & Assert to make sure the return status is success.
+ * 5. Assert to make sure the bridge is deleted
+ */
+
+ this.endToEndApiTest(connection, getOpenVSwitchTableUUID(connection));
+
+ /*
+ * Repeat all of the above tests without the parent_uuid
+ */
+
+ this.endToEndApiTest(connection, null);
+ }
+
+ 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 = ovsdbConfigService.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 = ovsdbConfigService.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 = ovsdbConfigService.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 ovsdbConfigService.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 = ovsdbConfigService.getRows(node, openVSwitch.getSchema().getName());
+ if (row == null || row.size() == 0) return null;
+ return (String)row.keySet().toArray()[0];
+ }
+
+ public void printCache() throws Exception {