From: Stephen Kitt Date: Tue, 8 Dec 2015 08:08:17 +0000 (+0100) Subject: Use SouthboundUtils in SouthboundIT X-Git-Tag: release/beryllium~142^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F83%2F30983%2F2;p=ovsdb.git Use SouthboundUtils in SouthboundIT Change-Id: I2fd8466e650df77af031f75cfa36a04275847124 Signed-off-by: Stephen Kitt --- diff --git a/southbound/southbound-features/pom.xml b/southbound/southbound-features/pom.xml index bd899a502..a101bfe36 100644 --- a/southbound/southbound-features/pom.xml +++ b/southbound/southbound-features/pom.xml @@ -119,6 +119,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL southbound-api ${project.version} + + ${project.groupId} + utils.southbound-utils + ${project.version} + + + ${project.groupId} + utils.mdsal-utils + ${project.version} + ${project.groupId} library-features diff --git a/southbound/southbound-features/src/main/features/features.xml b/southbound/southbound-features/src/main/features/features.xml index 7e2b90b81..0fbba27f2 100644 --- a/southbound/southbound-features/src/main/features/features.xml +++ b/southbound/southbound-features/src/main/features/features.xml @@ -48,4 +48,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html odl-mdsal-apidocs odl-mdsal-xsql + + odl-ovsdb-southbound-impl + mvn:org.opendaylight.ovsdb/utils.mdsal-utils/{{VERSION}} + mvn:org.opendaylight.ovsdb/utils.southbound-utils/{{VERSION}} + diff --git a/southbound/southbound-it/pom.xml b/southbound/southbound-it/pom.xml index 0192b0150..47ad4b3a7 100644 --- a/southbound/southbound-it/pom.xml +++ b/southbound/southbound-it/pom.xml @@ -84,6 +84,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.controller config-util + + ${project.groupId} + utils.southbound-utils + ${project.version} + org.ops4j.pax.exam diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/MdsalUtils.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/MdsalUtils.java deleted file mode 100644 index 8aa7b614c..000000000 --- a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/MdsalUtils.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2015 Red Hat, Inc. and others. All rights reserved. - * - * 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 - */ -package org.opendaylight.ovsdb.southbound.it; - -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility class for mdsal transactions. - * - * @author Sam Hague (shague@redhat.com) - */ -public class MdsalUtils { - private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class); - private DataBroker databroker = null; - - /** - * Class constructor setting the data broker. - * - * @param dataBroker the {@link DataBroker} - */ - public MdsalUtils(DataBroker dataBroker) { - this.databroker = dataBroker; - } - - /** - * Executes delete as a blocking transaction. - * - * @param store {@link LogicalDatastoreType} which should be modified - * @param path {@link InstanceIdentifier} to read from - * @param the data object type - * @return the result of the request - */ - public boolean delete( - final LogicalDatastoreType store, final InstanceIdentifier path) { - boolean result = false; - final WriteTransaction transaction = databroker.newWriteOnlyTransaction(); - transaction.delete(store, path); - CheckedFuture future = transaction.submit(); - try { - future.checkedGet(); - result = true; - } catch (TransactionCommitFailedException e) { - LOG.warn("Failed to delete {} ", path, e); - } - return result; - } - - /** - * Executes merge as a blocking transaction. - * - * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified - * @param path {@link InstanceIdentifier} for path to read - * @param the data object type - * @return the result of the request - */ - public boolean merge( - final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier path, D data) { - boolean result = false; - final WriteTransaction transaction = databroker.newWriteOnlyTransaction(); - transaction.merge(logicalDatastoreType, path, data, true); - CheckedFuture future = transaction.submit(); - try { - future.checkedGet(); - result = true; - } catch (TransactionCommitFailedException e) { - LOG.warn("Failed to merge {} ", path, e); - } - return result; - } - - /** - * Executes put as a blocking transaction. - * - * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified - * @param path {@link InstanceIdentifier} for path to read - * @param the data object type - * @return the result of the request - */ - public boolean put( - final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier path, D data) { - boolean result = false; - final WriteTransaction transaction = databroker.newWriteOnlyTransaction(); - transaction.put(logicalDatastoreType, path, data, true); - CheckedFuture future = transaction.submit(); - try { - future.checkedGet(); - result = true; - } catch (TransactionCommitFailedException e) { - LOG.warn("Failed to put {} ", path, e); - } - return result; - } - - /** - * Executes read as a blocking transaction. - * - * @param store {@link LogicalDatastoreType} to read - * @param path {@link InstanceIdentifier} for path to read - * @param the data object type - * @return the result as the data object requested - */ - public D read( - final LogicalDatastoreType store, final InstanceIdentifier path) { - D result = null; - final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction(); - Optional optionalDataObject; - CheckedFuture, ReadFailedException> future = transaction.read(store, path); - try { - optionalDataObject = future.checkedGet(); - if (optionalDataObject.isPresent()) { - result = optionalDataObject.get(); - } else { - LOG.debug("{}: Failed to read {}", - Thread.currentThread().getStackTrace()[1], path); - } - } catch (ReadFailedException e) { - LOG.warn("Failed to read {} ", path, e); - } - transaction.close(); - return result; - } -} diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java index 4c71b499d..1f7f36546 100644 --- a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java +++ b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java @@ -12,16 +12,13 @@ import static org.junit.Assert.fail; import static org.ops4j.pax.exam.CoreOptions.composite; import static org.ops4j.pax.exam.CoreOptions.maven; import static org.ops4j.pax.exam.CoreOptions.vmOption; -import static org.ops4j.pax.exam.CoreOptions.when; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; -import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import java.io.File; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; @@ -48,6 +45,8 @@ import org.opendaylight.ovsdb.southbound.SouthboundConstants; import org.opendaylight.ovsdb.southbound.SouthboundMapper; import org.opendaylight.ovsdb.southbound.SouthboundProvider; import org.opendaylight.ovsdb.southbound.SouthboundUtil; +import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils; +import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; @@ -60,7 +59,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbFailModeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbPortInterfaceAttributes.VlanMode; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation; @@ -108,7 +106,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; import org.ops4j.pax.exam.karaf.options.LogLevelOption; import org.ops4j.pax.exam.options.MavenUrlReference; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; @@ -137,12 +134,6 @@ public class SouthboundIT extends AbstractMdsalTestBase { private static MdsalUtils mdsalUtils = null; private static Node ovsdbNode; - // TODO Constants copied from AbstractConfigTestBase, need to be removed (see TODO below) - private static final String PAX_EXAM_UNPACK_DIRECTORY = "target/exam"; - private static final String KARAF_DEBUG_PORT = "5005"; - private static final String KARAF_DEBUG_PROP = "karaf.debug"; - private static final String KEEP_UNPACK_DIRECTORY_PROP = "karaf.keep.unpack"; - @Inject private BundleContext bundleContext; @@ -198,16 +189,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { @Configuration public Option[] config() { - // TODO Figure out how to use the parent Karaf setup, then just use super.config() - Option[] options = new Option[] { - when(Boolean.getBoolean(KARAF_DEBUG_PROP)) - .useOptions(KarafDistributionOption.debugConfiguration(KARAF_DEBUG_PORT, true)), - karafDistributionConfiguration().frameworkUrl(getKarafDistro()) - .unpackDirectory(new File(PAX_EXAM_UNPACK_DIRECTORY)) - .useDeployFolder(false), - when(Boolean.getBoolean(KEEP_UNPACK_DIRECTORY_PROP)).useOptions(keepRuntimeFolder()), - // Works only if we don't specify the feature repo and name - getLoggingOption()}; + Option[] options = super.config(); Option[] propertyOptions = getPropertiesOptions(); Option[] otherOptions = getOtherOptions(); Option[] combinedOptions = new Option[options.length + propertyOptions.length + otherOptions.length]; @@ -257,7 +239,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { @Override public String getFeatureName() { - return "odl-ovsdb-southbound-impl-ui"; + return "odl-ovsdb-southbound-test"; } protected String usage() { @@ -334,7 +316,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { mdsalUtils = new MdsalUtils(dataBroker); final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber); - final InstanceIdentifier iid = createInstanceIdentifier(connectionInfo); + final InstanceIdentifier iid = SouthboundUtils.createInstanceIdentifier(connectionInfo); dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, iid, CONFIGURATION_LISTENER, AsyncDataBroker.DataChangeScope.SUBTREE); dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, @@ -378,11 +360,6 @@ public class SouthboundIT extends AbstractMdsalTestBase { return connectionInfo; } - private static String connectionInfoToString(final ConnectionInfo connectionInfo) { - return String.valueOf( - connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue(); - } - @Test public void testNetworkTopology() throws InterruptedException { NetworkTopology networkTopology = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, @@ -412,21 +389,14 @@ public class SouthboundIT extends AbstractMdsalTestBase { topology); } - private static InstanceIdentifier createInstanceIdentifier(ConnectionInfo connectionInfo) { - return InstanceIdentifier - .create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)) - .child(Node.class, - createNodeKey(connectionInfo.getRemoteIp(), connectionInfo.getRemotePort())); - } - private Node connectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException { - final InstanceIdentifier iid = createInstanceIdentifier(connectionInfo); - Assert.assertTrue(mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, iid, createNode(connectionInfo))); + final InstanceIdentifier iid = SouthboundUtils.createInstanceIdentifier(connectionInfo); + Assert.assertTrue( + mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, iid, SouthboundUtils.createNode(connectionInfo))); waitForOperationalCreation(iid); Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, iid); Assert.assertNotNull(node); - LOG.info("Connected to {}", connectionInfoToString(connectionInfo)); + LOG.info("Connected to {}", SouthboundUtils.connectionInfoToString(connectionInfo)); return node; } @@ -467,12 +437,12 @@ public class SouthboundIT extends AbstractMdsalTestBase { } private static void disconnectOvsdbNode(final ConnectionInfo connectionInfo) throws InterruptedException { - final InstanceIdentifier iid = createInstanceIdentifier(connectionInfo); + final InstanceIdentifier iid = SouthboundUtils.createInstanceIdentifier(connectionInfo); Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid)); waitForOperationalDeletion(iid); Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, iid); Assert.assertNull(node); - LOG.info("Disconnected from {}", connectionInfoToString(connectionInfo)); + LOG.info("Disconnected from {}", SouthboundUtils.connectionInfoToString(connectionInfo)); } @Test @@ -497,9 +467,9 @@ public class SouthboundIT extends AbstractMdsalTestBase { LOG.info("dp type is {}", dpTypeStr); if (dpTypeStr.equals(NETDEV_DP_TYPE)) { LOG.info("Found a DPDK node; adding a corresponding netdev device"); - InstanceIdentifier bridgeIid = createInstanceIdentifier(connectionInfo, + InstanceIdentifier bridgeIid = SouthboundUtils.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(SouthboundITConstants.BRIDGE_NAME)); - NodeId bridgeNodeId = createManagedNodeId(bridgeIid); + NodeId bridgeNodeId = SouthboundUtils.createManagedNodeId(bridgeIid); try (TestBridge testBridge = new TestBridge(connectionInfo, bridgeIid, SouthboundITConstants.BRIDGE_NAME, bridgeNodeId, false, null, true, dpType, null, null, null)) { @@ -615,7 +585,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { private static void setManagedBy(final OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder, final ConnectionInfo connectionInfo) { - InstanceIdentifier connectionNodePath = createInstanceIdentifier(connectionInfo); + InstanceIdentifier connectionNodePath = SouthboundUtils.createInstanceIdentifier(connectionInfo); ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath)); } @@ -708,7 +678,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { this.bridgeName = bridgeName; NodeBuilder bridgeNodeBuilder = new NodeBuilder(); if (bridgeIid == null) { - bridgeIid = createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName)); + bridgeIid = SouthboundUtils.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName)); } if (bridgeNodeId == null) { bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid); @@ -746,7 +716,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { @Override public void close() { final InstanceIdentifier iid = - createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName)); + SouthboundUtils.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName)); Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid)); try { Thread.sleep(OVSDB_UPDATE_TIMEOUT); @@ -802,8 +772,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { */ private Node getBridgeNode(ConnectionInfo connectionInfo, String bridgeName, LogicalDatastoreType store) { InstanceIdentifier bridgeIid = - createInstanceIdentifier(connectionInfo, - new OvsdbBridgeName(bridgeName)); + SouthboundUtils.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName)); return mdsalUtils.read(store, bridgeIid); } @@ -831,8 +800,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { } private InstanceIdentifier getTpIid(ConnectionInfo connectionInfo, OvsdbBridgeAugmentation bridge) { - return createInstanceIdentifier(connectionInfo, - bridge.getBridgeName()); + return SouthboundUtils.createInstanceIdentifier(connectionInfo, bridge.getBridgeName()); } /** @@ -866,7 +834,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); LOG.info("bridge: {}", bridge); - NodeId nodeId = SouthboundMapper.createManagedNodeId(createInstanceIdentifier( + NodeId nodeId = SouthboundMapper.createManagedNodeId(SouthboundUtils.createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); @@ -911,7 +879,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) { OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); - NodeId nodeId = createManagedNodeId(createInstanceIdentifier( + NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); @@ -943,9 +911,8 @@ public class SouthboundIT extends AbstractMdsalTestBase { } // UPDATE- Not Applicable. From the OpenVSwitch documentation: - // "A client should ideally set this column’s value in the same database transaction that it uses to create - - // the interface. " + // "A client should ideally set this column’s value in the same database transaction that it uses to + // create the interface. " // DELETE handled by TestBridge } @@ -989,8 +956,9 @@ public class SouthboundIT extends AbstractMdsalTestBase { try (TestBridge testBridge = new TestBridge(connectionInfo, null, testBridgeAndPortName, null, true, SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null, null, null)) { - NodeId testBridgeNodeId = createManagedNodeId(createInstanceIdentifier( - connectionInfo, new OvsdbBridgeName(testBridgeAndPortName))); + NodeId testBridgeNodeId = SouthboundUtils.createManagedNodeId( + SouthboundUtils.createInstanceIdentifier(connectionInfo, + new OvsdbBridgeName(testBridgeAndPortName))); OvsdbTerminationPointAugmentationBuilder tpCreateAugmentationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); tpCreateAugmentationBuilder.setName(testBridgeAndPortName); @@ -1024,7 +992,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { helper.writeValues(tpUpdateAugmentationBuilder, updateToTestCase.inputValues); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); - NodeId portUpdateNodeId = createManagedNodeId(portIid); + NodeId portUpdateNodeId = SouthboundUtils.createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(testBridgeAndPortName))); @@ -1130,7 +1098,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) { OvsdbBridgeAugmentation bridge = getBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME); Assert.assertNotNull(bridge); - NodeId nodeId = createManagedNodeId(createInstanceIdentifier( + NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); @@ -1163,7 +1131,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { tpUpdateAugmentationBuilder.setVlanTag(new VlanId(UPDATED_VLAN_ID)); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); - NodeId portUpdateNodeId = createManagedNodeId(portIid); + NodeId portUpdateNodeId = SouthboundUtils.createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(portName))); @@ -1203,7 +1171,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) { OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); - NodeId nodeId = createManagedNodeId(createInstanceIdentifier( + NodeId nodeId = SouthboundUtils.createManagedNodeId(SouthboundUtils.createInstanceIdentifier( connectionInfo, bridge.getBridgeName())); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); @@ -1233,7 +1201,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { tpUpdateAugmentationBuilder.setVlanMode(UPDATED_VLAN_MODE); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); - NodeId portUpdateNodeId = createManagedNodeId(portIid); + NodeId portUpdateNodeId = SouthboundUtils.createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(portName))); @@ -1294,8 +1262,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) { OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); Assert.assertNotNull(bridge); - NodeId nodeId = createManagedNodeId(createInstanceIdentifier( - connectionInfo, bridge.getBridgeName())); + NodeId nodeId = SouthboundUtils.createManagedNodeId(connectionInfo, bridge.getBridgeName()); OvsdbTerminationPointAugmentationBuilder ovsdbTerminationBuilder = createGenericOvsdbTerminationPointAugmentationBuilder(); String portName = "testTerminationPointVlanTrunks" + testCase; @@ -1328,7 +1295,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { tpUpdateAugmentationBuilder.setTrunks(UPDATED_TRUNKS); InstanceIdentifier portIid = SouthboundMapper.createInstanceIdentifier(testBridgeNodeId); NodeBuilder portUpdateNodeBuilder = new NodeBuilder(); - NodeId portUpdateNodeId = createManagedNodeId(portIid); + NodeId portUpdateNodeId = SouthboundUtils.createManagedNodeId(portIid); portUpdateNodeBuilder.setNodeId(portUpdateNodeId); TerminationPointBuilder tpUpdateBuilder = new TerminationPointBuilder(); tpUpdateBuilder.setKey(new TerminationPointKey(new TpId(portName))); @@ -1365,7 +1332,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)); Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, topologyPath); - InstanceIdentifier expectedNodeIid = createInstanceIdentifier(connectionInfo); + InstanceIdentifier expectedNodeIid = SouthboundUtils.createInstanceIdentifier(connectionInfo); NodeId expectedNodeId = expectedNodeIid.firstKeyOf(Node.class, NodeKey.class).getNodeId(); Node foundNode = null; Assert.assertNotNull("Expected to find topology: " + topologyPath, topology); @@ -1407,7 +1374,8 @@ public class SouthboundIT extends AbstractMdsalTestBase { // CREATE: Create the test bridge final OvsdbBridgeName ovsdbBridgeName = new OvsdbBridgeName(testBridgeName); - final InstanceIdentifier bridgeIid = createInstanceIdentifier(connectionInfo, ovsdbBridgeName); + final InstanceIdentifier bridgeIid = + SouthboundUtils.createInstanceIdentifier(connectionInfo, ovsdbBridgeName); final NodeId bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid); final NodeBuilder bridgeCreateNodeBuilder = new NodeBuilder(); bridgeCreateNodeBuilder.setNodeId(bridgeNodeId); @@ -1475,48 +1443,6 @@ public class SouthboundIT extends AbstractMdsalTestBase { new BridgeExternalIdsSouthboundHelper()); } - public static InstanceIdentifier createInstanceIdentifier(ConnectionInfo key,OvsdbBridgeName bridgeName) { - return SouthboundMapper.createInstanceIdentifier(createManagedNodeId(key, bridgeName)); - } - - public static NodeId createManagedNodeId(ConnectionInfo key, OvsdbBridgeName bridgeName) { - return createManagedNodeId(key.getRemoteIp(), key.getRemotePort(), bridgeName); - } - - public static NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) { - return new NodeId(createNodeId(ip,port).getValue() - + "/" + SouthboundConstants.BRIDGE_URI_PREFIX + "/" + bridgeName.getValue()); - } - - public static NodeId createNodeId(IpAddress ip, PortNumber port) { - String uriString = SouthboundConstants.OVSDB_URI_PREFIX + "://" - + String.valueOf(ip.getValue()) + ":" + port.getValue(); - Uri uri = new Uri(uriString); - return new NodeId(uri); - } - - public static NodeKey createNodeKey(IpAddress ip, PortNumber port) { - return new NodeKey(createNodeId(ip,port)); - } - - public static Node createNode(ConnectionInfo key) { - NodeBuilder nodeBuilder = new NodeBuilder(); - nodeBuilder.setNodeId(createNodeId(key.getRemoteIp(),key.getRemotePort())); - nodeBuilder.addAugmentation(OvsdbNodeAugmentation.class, createOvsdbAugmentation(key)); - return nodeBuilder.build(); - } - - public static OvsdbNodeAugmentation createOvsdbAugmentation(ConnectionInfo key) { - OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder(); - ovsdbNodeBuilder.setConnectionInfo(key); - return ovsdbNodeBuilder.build(); - } - - public static NodeId createManagedNodeId(InstanceIdentifier iid) { - NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class); - return nodeKey.getNodeId(); - } - /** *

* Representation of a southbound test case. Each test case has a name, a list of input values and a list of diff --git a/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java b/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java index 978c5223b..e3eb3a29c 100644 --- a/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java +++ b/utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java @@ -84,31 +84,31 @@ public class SouthboundUtils { .put("dpdkvhostuser", InterfaceTypeDpdkvhostuser.class) .build(); - public NodeId createNodeId(IpAddress ip, PortNumber port) { + public static NodeId createNodeId(IpAddress ip, PortNumber port) { String uriString = SouthboundConstants.OVSDB_URI_PREFIX + "://" + String.valueOf(ip.getValue()) + ":" + port.getValue(); Uri uri = new Uri(uriString); return new NodeId(uri); } - public Node createNode(ConnectionInfo key) { + public static Node createNode(ConnectionInfo key) { NodeBuilder nodeBuilder = new NodeBuilder(); nodeBuilder.setNodeId(createNodeId(key.getRemoteIp(), key.getRemotePort())); nodeBuilder.addAugmentation(OvsdbNodeAugmentation.class, createOvsdbAugmentation(key)); return nodeBuilder.build(); } - public OvsdbNodeAugmentation createOvsdbAugmentation(ConnectionInfo key) { + public static OvsdbNodeAugmentation createOvsdbAugmentation(ConnectionInfo key) { OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder(); ovsdbNodeBuilder.setConnectionInfo(key); return ovsdbNodeBuilder.build(); } - public InstanceIdentifier createInstanceIdentifier(ConnectionInfo key) { + public static InstanceIdentifier createInstanceIdentifier(ConnectionInfo key) { return createInstanceIdentifier(key.getRemoteIp(), key.getRemotePort()); } - public InstanceIdentifier createInstanceIdentifier(IpAddress ip, PortNumber port) { + public static InstanceIdentifier createInstanceIdentifier(IpAddress ip, PortNumber port) { InstanceIdentifier path = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)) @@ -117,7 +117,7 @@ public class SouthboundUtils { return path; } - public InstanceIdentifier createInstanceIdentifier(ConnectionInfo key,OvsdbBridgeName bridgeName) { + public static InstanceIdentifier createInstanceIdentifier(ConnectionInfo key,OvsdbBridgeName bridgeName) { return SouthboundMapper.createInstanceIdentifier(createManagedNodeId(key, bridgeName)); } @@ -133,20 +133,25 @@ public class SouthboundUtils { return terminationPointPath; } - public NodeKey createNodeKey(IpAddress ip, PortNumber port) { + public static NodeKey createNodeKey(IpAddress ip, PortNumber port) { return new NodeKey(createNodeId(ip, port)); } - public NodeId createManagedNodeId(ConnectionInfo key, OvsdbBridgeName bridgeName) { + public static NodeId createManagedNodeId(ConnectionInfo key, OvsdbBridgeName bridgeName) { return createManagedNodeId(key.getRemoteIp(), key.getRemotePort(), bridgeName); } - public NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) { + public static NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) { return new NodeId(createNodeId(ip,port).getValue() + "/" + SouthboundConstants.BRIDGE_URI_PREFIX + "/" + bridgeName.getValue()); } - public ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) { + public static NodeId createManagedNodeId(InstanceIdentifier iid) { + NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class); + return nodeKey.getNodeId(); + } + + public static ConnectionInfo getConnectionInfo(final String addressStr, final String portStr) { InetAddress inetAddress = null; try { inetAddress = InetAddress.getByName(addressStr); @@ -167,7 +172,7 @@ public class SouthboundUtils { .build(); } - public String connectionInfoToString(final ConnectionInfo connectionInfo) { + public static String connectionInfoToString(final ConnectionInfo connectionInfo) { return String.valueOf( connectionInfo.getRemoteIp().getValue()) + ":" + connectionInfo.getRemotePort().getValue(); }