OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder();
- setVersion(ovsdbNodeBuilder, openVSwitch);
+ setDbVersion(ovsdbNodeBuilder, openVSwitch);
+ setOvsVersion(ovsdbNodeBuilder, openVSwitch);
setDataPathTypes(ovsdbNodeBuilder, openVSwitch);
setInterfaceTypes(ovsdbNodeBuilder, openVSwitch);
OpenVSwitch oldEntry = deletedOpenVSwitchRows.get(entry.getKey());
}
}
- private void setVersion(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder,
- OpenVSwitch openVSwitch) {
+ private void setOvsVersion(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder, OpenVSwitch openVSwitch) {
try {
ovsdbNodeBuilder.setOvsVersion(openVSwitch.getOvsVersionColumn().getData().iterator().next());
} catch (NoSuchElementException e) {
}
}
+ private void setDbVersion(OvsdbNodeAugmentationBuilder ovsdbNodeBuilder, OpenVSwitch openVSwitch) {
+ try {
+ ovsdbNodeBuilder.setDbVersion(openVSwitch.getDbVersionColumn().getData().iterator().next());
+ } catch (NoSuchElementException e) {
+ LOG.debug("db_version is not set for this switch",e);
+ }
+ }
+
private InstanceIdentifier<Node> getInstanceIdentifier(OpenVSwitch ovs) {
if (ovs.getExternalIdsColumn() != null
&& ovs.getExternalIdsColumn().getData() != null
PowerMockito.whenNew(OvsdbNodeAugmentationBuilder.class).withNoArguments().thenReturn(ovsdbNodeBuilder);
//suppress the setter methods of the class
- MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setVersion",
+ MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setOvsVersion",
+ OvsdbNodeAugmentationBuilder.class, OpenVSwitch.class));
+ MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setDbVersion",
OvsdbNodeAugmentationBuilder.class, OpenVSwitch.class));
MemberModifier.suppress(MemberMatcher.method(OpenVSwitchUpdateCommand.class, "setDataPathTypes",
OvsdbNodeAugmentationBuilder.class, OpenVSwitch.class));
@Test
@SuppressWarnings("unchecked")
- public void testSetVersion() throws Exception {
+ public void testSetOvsVersion() throws Exception {
OpenVSwitch openVSwitch = mock(OpenVSwitch.class);
Column<GenericTableSchema, Set<String>> column = mock(Column.class);
when(openVSwitch.getOvsVersionColumn()).thenReturn(column);
OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = mock(OvsdbNodeAugmentationBuilder.class);
when(ovsdbNodeBuilder.setOvsVersion(anyString())).thenReturn(ovsdbNodeBuilder);
- Whitebox.invokeMethod(openVSwitchUpdateCommand, "setVersion", ovsdbNodeBuilder, openVSwitch);
+ Whitebox.invokeMethod(openVSwitchUpdateCommand, "setOvsVersion", ovsdbNodeBuilder, openVSwitch);
verify(ovsdbNodeBuilder).setOvsVersion(anyString());
verify(openVSwitch).getOvsVersionColumn();
+ }
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testSetDbVersion() throws Exception {
+ OpenVSwitch openVSwitch = mock(OpenVSwitch.class);
+ Column<GenericTableSchema, Set<String>> column = mock(Column.class);
+ when(openVSwitch.getDbVersionColumn()).thenReturn(column);
+ Set<String> set = new HashSet<>();
+ set.add("7.6.1");
+ when(column.getData()).thenReturn(set);
+ OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = mock(OvsdbNodeAugmentationBuilder.class);
+ when(ovsdbNodeBuilder.setOvsVersion(anyString())).thenReturn(ovsdbNodeBuilder);
+ Whitebox.invokeMethod(openVSwitchUpdateCommand, "setDbVersion", ovsdbNodeBuilder, openVSwitch);
+ verify(ovsdbNodeBuilder).setDbVersion(anyString());
+ verify(openVSwitch).getDbVersionColumn();
}
}
\ No newline at end of file
package org.opendaylight.ovsdb.southbound.it;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
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.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import com.google.common.collect.ImmutableBiMap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.List;
import java.util.Properties;
import java.util.Set;
-
import javax.annotation.Nullable;
import javax.inject.Inject;
-
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
-import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.lib.notation.Version;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
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.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.TrunksBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.ops4j.pax.exam.options.MavenUrlReference;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
/**
* Integration tests for southbound-impl
*
private static MdsalUtils mdsalUtils = null;
private static Node ovsdbNode;
private static int testMethodsRemaining;
- private static DataBroker dataBroker;
private static Version schemaVersion;
- private static OvsdbClient ovsdbClient;
- private static DatabaseSchema dbSchema;
+ @Inject @Filter(timeout=60000)
+ private static DataBroker dataBroker = null;
@Inject
private BundleContext bundleContext;
} catch (Exception e) {
LOG.warn("Failed to setup test", e);
}
- //dataBroker = getSession().getSALService(DataBroker.class);
- Thread.sleep(3000);
- dataBroker = SouthboundProvider.getDb();
Assert.assertNotNull("db should not be null", dataBroker);
+ LOG.info("sleeping for 10s to let the features finish installing");
+ Thread.sleep(10000);
+
addressStr = bundleContext.getProperty(SouthboundITConstants.SERVER_IPADDRESS);
String portStr = bundleContext.getProperty(SouthboundITConstants.SERVER_PORT);
try {
}
mdsalUtils = new MdsalUtils(dataBroker);
+ assertTrue("Did not find " + SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue(), getOvsdbTopology());
final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
iid, OPERATIONAL_LISTENER, AsyncDataBroker.DataChangeScope.SUBTREE);
ovsdbNode = connectOvsdbNode(connectionInfo);
- try {
- ovsdbClient = SouthboundIntegrationTestUtils.getTestConnection(this);
- assertNotNull("Invalid Client. Check connection params", ovsdbClient);
-
- dbSchema = ovsdbClient.getSchema(SouthboundIntegrationTestUtils.OPEN_VSWITCH_SCHEMA).get();
- assertNotNull("Invalid dbSchema.", dbSchema);
- schemaVersion = dbSchema.getVersion();
- LOG.info("{} schema version = {}", SouthboundIntegrationTestUtils.OPEN_VSWITCH_SCHEMA, schemaVersion);
- } catch (Exception e) {
- fail("Error accessing schemaVersion in SouthboundIT setUp()." + usage());
- }
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+ assertNotNull("The OvsdbNodeAugmentation cannot be null", ovsdbNodeAugmentation);
+ schemaVersion = Version.fromString(ovsdbNodeAugmentation.getDbVersion());
+ LOG.info("schemaVersion = {}", schemaVersion);
// Let's count the test methods (we need to use this instead of @AfterClass on teardown() since the latter is
// useless with pax-exam)
}
}
+ private Boolean getOvsdbTopology() {
+ LOG.info("getOvsdbTopology: looking for {}...", SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue());
+ Boolean found = false;
+ final TopologyId topologyId = SouthboundUtils.OVSDB_TOPOLOGY_ID;
+ InstanceIdentifier<Topology> path =
+ InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
+ for (int i = 0; i < 60; i++) {
+ Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
+ if (topology != null) {
+ LOG.info("getOvsdbTopology: found {}...", SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue());
+ found = true;
+ break;
+ } else {
+ LOG.info("getOvsdbTopology: still looking ({})...", i);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for {}", SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue(), e);
+ }
+ }
+ }
+ return found;
+ }
+
/**
* Test passive connection mode. The southbound starts in a listening mode waiting for connections on port
* 6640. This test will wait for incoming connections for {@link SouthboundITConstants#CONNECTION_INIT_TIMEOUT} ms.
assertNotNull(ovsdbNodeAugmentation.getOvsVersion());
}
+ @Test
+ public void testOvsdbNodeDbVersion() throws InterruptedException {
+ OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+ Assert.assertNotNull(ovsdbNodeAugmentation);
+ assertNotNull(ovsdbNodeAugmentation.getDbVersion());
+ }
+
@Test
public void testOpenVSwitchOtherConfig() throws InterruptedException {
OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+++ /dev/null
-/*
- * Copyright © 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 java.io.IOException;
-import java.net.InetAddress;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-import org.opendaylight.ovsdb.lib.OvsdbClient;
-import org.opendaylight.ovsdb.lib.OvsdbConnection;
-import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
-import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
-import org.osgi.framework.Bundle;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Utilities for OVSDB Southbound integration tests.
- */
-public final class SouthboundIntegrationTestUtils {
- public final static String OPEN_VSWITCH_SCHEMA = "Open_vSwitch";
- public final static String HARDWARE_VTEP = "hardware_vtep";
- private static final Logger LOG = LoggerFactory.getLogger(SouthboundIntegrationTestUtils.class);
-
- /**
- * Prevent instantiation of a utility class.
- */
- private SouthboundIntegrationTestUtils() {
- // Nothing to do
- }
-
- public static OvsdbClient getTestConnection(BindingAwareProvider provider) throws IOException, InterruptedException, ExecutionException, TimeoutException {
- Properties props = System.getProperties();
- String addressStr = props.getProperty(SouthboundITConstants.SERVER_IPADDRESS);
- String portStr = props.getProperty(SouthboundITConstants.SERVER_PORT, SouthboundITConstants.DEFAULT_SERVER_PORT);
- String connectionType = props.getProperty(SouthboundITConstants.CONNECTION_TYPE, "active");
- LOG.info("addressStr:{}, portStr:{}, connectionType:{}", addressStr, portStr, connectionType);
-
- // If the connection type is active, controller connects to the ovsdb-server
- if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_ACTIVE)) {
- if (addressStr == null) {
- throw new IllegalArgumentException(usage());
- }
-
- InetAddress address;
- try {
- address = InetAddress.getByName(addressStr);
- } catch (Exception e) {
- System.out.println("Unable to resolve " + addressStr);
- e.printStackTrace();
- return null;
- }
-
- Integer port;
- try {
- port = Integer.parseInt(portStr);
- } catch (NumberFormatException e) {
- System.out.println("Invalid port number : " + portStr);
- e.printStackTrace();
- return null;
- }
-
- OvsdbConnection connection = (OvsdbConnection) ServiceHelper.getGlobalInstance(OvsdbConnection.class, provider);
- return connection.connect(address, port);
- } else if (connectionType.equalsIgnoreCase(SouthboundITConstants.CONNECTION_TYPE_PASSIVE)) {
- ExecutorService executor = Executors.newFixedThreadPool(1);
- Future<OvsdbClient> passiveConnection = executor.submit(new PassiveListener());
- return passiveConnection.get(60, TimeUnit.SECONDS);
- }
- throw new IllegalArgumentException("Connection parameter (" + SouthboundITConstants.CONNECTION_TYPE + ") must be either active or passive");
- }
-
- public static String bundleStateToString(int state) {
- switch (state) {
- case Bundle.ACTIVE:
- return "ACTIVE";
- case Bundle.INSTALLED:
- return "INSTALLED";
- case Bundle.RESOLVED:
- return "RESOLVED";
- case Bundle.UNINSTALLED:
- return "UNINSTALLED";
- default:
- return "Not CONVERTED";
- }
- }
-
- private static String usage() {
- return "Integration Test needs a valid connection configuration as follows :\n" +
- "active connection : mvn -Pintegrationtest -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"+
- "passive connection : mvn -Pintegrationtest -Dovsdbserver.connection=passive verify\n";
- }
-
- private static class PassiveListener implements Callable<OvsdbClient>, OvsdbConnectionListener {
- OvsdbClient client = null;
- @Override
- public OvsdbClient call() throws Exception {
- OvsdbConnection connection = (OvsdbConnection)ServiceHelper.getGlobalInstance(OvsdbConnection.class, this);
- connection.registerConnectionListener(this);
- while (client == null) {
- Thread.sleep(500);
- }
- return client;
- }
-
- @Override
- public void connected(OvsdbClient client) {
- this.client = client;
- }
-
- @Override
- public void disconnected(OvsdbClient client) {
- if (!Objects.equals(this.client.getConnectionInfo(), client.getConnectionInfo())) {
- throw new IllegalStateException("disconnected unexpected client");
- }
- this.client = null;
- }
- }
-
-}