2 * Copyright (c) 2015 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.ovsdb.openstack.netvirt.it;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15 import static org.ops4j.pax.exam.CoreOptions.maven;
16 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
18 import com.google.common.base.Optional;
19 import com.google.common.util.concurrent.CheckedFuture;
20 import com.google.common.util.concurrent.FutureCallback;
21 import com.google.common.util.concurrent.Futures;
22 import com.google.common.util.concurrent.ListenableFuture;
23 import java.net.InetAddress;
24 import java.net.UnknownHostException;
25 import java.util.Properties;
26 import java.util.concurrent.ExecutionException;
27 import javax.inject.Inject;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
33 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
34 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
35 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
36 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
37 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
38 import org.opendaylight.ovsdb.openstack.netvirt.impl.MdsalConsumerImpl;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.ops4j.pax.exam.Configuration;
47 import org.ops4j.pax.exam.Option;
48 import org.ops4j.pax.exam.junit.PaxExam;
49 import org.ops4j.pax.exam.options.MavenUrlReference;
50 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
51 import org.ops4j.pax.exam.spi.reactors.PerClass;
52 import org.osgi.framework.Bundle;
53 import org.osgi.framework.BundleContext;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
58 * Integration tests for southbound-impl
60 * @author Sam Hague (shague@redhat.com)
62 @RunWith(PaxExam.class)
63 @ExamReactorStrategy(PerClass.class)
64 public class NetvirtIT extends AbstractMdsalTestBase {
65 private static final Logger LOG = LoggerFactory.getLogger(NetvirtIT.class);
66 private static final String NETVIRT = "org.opendaylight.ovsdb.openstack.net-virt";
67 private static final String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
68 private static final String SERVER_PORT = "ovsdbserver.port";
69 private static final String CONNECTION_TYPE = "ovsdbserver.connection";
70 private static final String CONNECTION_TYPE_ACTIVE = "active";
71 private static final String CONNECTION_TYPE_PASSIVE = "passive";
72 private static final int CONNECTION_INIT_TIMEOUT = 10000;
73 private static final String DEFAULT_SERVER_IPADDRESS = "127.0.0.1";
74 private static final String DEFAULT_SERVER_PORT = "6640";
75 private static Boolean writeStatus = false;
76 private static Boolean readStatus = false;
77 private static Boolean deleteStatus = false;
78 private static DataBroker dataBroker = null;
79 private static String addressStr;
80 private static String portStr;
81 private static String connectionType;
82 private static Boolean setup = false;
83 private static MdsalUtils mdsalUtils = null;
86 private BundleContext bc;
89 public Option[] config() {
90 return super.config();
94 public String getModuleName() {
95 return "southbound-impl";
99 public String getInstanceName() {
100 return "southbound-default";
104 public MavenUrlReference getFeatureRepo() {
106 .groupId("org.opendaylight.ovsdb")
107 .artifactId("features-ovsdb")
108 .classifier("features")
110 .versionAsInProject();
114 public String getFeatureName() {
115 return "odl-ovsdb-openstack";
118 protected String usage() {
119 return "Integration Test needs a valid connection configuration as follows :\n"
120 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
121 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
125 public Option[] getPropertiesOptions() {
126 Properties props = new Properties(System.getProperties());
127 String addressStr = props.getProperty(SERVER_IPADDRESS, DEFAULT_SERVER_IPADDRESS);
128 String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
129 String connectionType = props.getProperty(CONNECTION_TYPE, CONNECTION_TYPE_ACTIVE);
131 LOG.info("Using the following properties: mode= {}, ip:port= {}:{}",
132 connectionType, addressStr, portStr);
134 Option[] options = new Option[] {
135 editConfigurationFilePut(CUSTOM_PROPERTIES, SERVER_IPADDRESS, addressStr),
136 editConfigurationFilePut(CUSTOM_PROPERTIES, SERVER_PORT, portStr),
137 editConfigurationFilePut(CUSTOM_PROPERTIES, CONNECTION_TYPE, connectionType)
142 public void isBundleReady (BundleContext bc, String bundleName) throws InterruptedException {
143 boolean ready = false;
146 int state = Bundle.UNINSTALLED;
147 Bundle b[] = bc.getBundles();
148 for (Bundle element : b) {
149 if (element.getSymbolicName().equals(bundleName)) {
150 state = element.getState();
154 if (state != Bundle.ACTIVE) {
155 LOG.info(">>>>> bundle not ready");
162 LOG.info(">>>>> {} is ready", bundleName);
166 public void setUp() throws InterruptedException {
168 LOG.info("Skipping setUp, already initialized");
174 } catch (Exception e) {
177 //dataBroker = getSession().getSALService(DataBroker.class);
178 //Thread.sleep(3000);
179 //dataBroker = SouthboundProvider.getDb();
180 isBundleReady(bc, NETVIRT);
182 dataBroker = MdsalConsumerImpl.getDataBroker();
183 Assert.assertNotNull("db should not be null", dataBroker);
185 addressStr = bc.getProperty(SERVER_IPADDRESS);
186 portStr = bc.getProperty(SERVER_PORT);
187 connectionType = bc.getProperty(CONNECTION_TYPE);
189 LOG.info("Using the following properties: mode= {}, ip:port= {}:{}",
190 connectionType, addressStr, portStr);
191 if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
192 if (addressStr == null) {
197 mdsalUtils = new MdsalUtils(dataBroker);
202 public void getDataBroker() throws InterruptedException {
203 Assert.assertNotNull(dataBroker);