2 * Copyright (c) 2016 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
9 package org.opendaylight.ovsdb.utils.ovsdb.it.utils;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
14 import java.util.List;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
17 import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerNotifyingDataChangeListener;
18 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * This class contains various utility methods used in OVSDB integration tests (IT).
29 public class OvsdbItUtils {
30 private static final Logger LOG = LoggerFactory.getLogger(OvsdbItUtils.class);
31 ControllerMdsalUtils mdsalUtils;
32 SouthboundUtils southboundUtils;
33 DataBroker dataBroker;
36 * Create a new OvsdbItUtils instance.
37 * @param dataBroker md-sal data broker
39 public OvsdbItUtils(DataBroker dataBroker) {
40 this.dataBroker = dataBroker;
41 mdsalUtils = new ControllerMdsalUtils(dataBroker);
42 southboundUtils = new SouthboundUtils(mdsalUtils);
46 * Get a NodeInfo instance initialized with this ItUtil's DataBroker.
47 * @param connectionInfo ConnectionInfo for the OVSDB server
48 * @param waitList For tracking outstanding md-sal events notifications
49 * @return a new NodeInfo object
51 public NodeInfo createNodeInfo(ConnectionInfo connectionInfo,
52 List<ControllerNotifyingDataChangeListener> waitList) {
53 return new NodeInfo(connectionInfo, this, waitList);
57 * Checks whether the OVSDB controller is connected. This method will retry 10 times and will through an
58 * AssertionError for any number of unexpected states.
59 * @param connectionInfo where to connect to
60 * @return true if connected
61 * @throws InterruptedException if interrupted while waiting for connection to appear
63 public boolean isControllerConnected(ConnectionInfo connectionInfo) throws InterruptedException {
64 LOG.info("isControllerConnected enter");
65 ControllerEntry controllerEntry;
66 Node ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
67 assertNotNull("ovsdb node not found", ovsdbNode);
69 String controllerTarget = southboundUtils.getControllersFromOvsdbNode(ovsdbNode).get(0);
70 assertNotNull("Failed to get controller target", controllerTarget);
72 for (int i = 0; i < 10; i++) {
73 LOG.info("isControllerConnected try {}: looking for controller: {}", i, controllerTarget);
74 OvsdbBridgeAugmentation bridge =
75 southboundUtils.getBridge(connectionInfo, "br-int");
76 if (bridge != null && bridge.getControllerEntry() != null) {
77 controllerEntry = bridge.getControllerEntry().iterator().next();
78 assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
79 if (controllerEntry.isIsConnected()) {
80 LOG.info("isControllerConnected exit: true {}", controllerTarget);
86 LOG.info("isControllerConnected exit: false {}", controllerTarget);