Avoid Bulk Topology Read During Reconciliation. 63/82563/11
authorChetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
Wed, 19 Jun 2019 06:12:32 +0000 (11:42 +0530)
committerAnil Vishnoi <vishnoianil@gmail.com>
Mon, 8 Jul 2019 19:15:35 +0000 (19:15 +0000)
Description:
During Reconciliation, The full config network-topology DS is queried
which is not efficient. Currently, only br-int is managed in
network-toplogy config DS(by genius) which will only be resynced.

Changes are done to query only the list of bridges for a given connected
switch (configurable vi param - bridges-reconciliation-inclusion-list) from
topology config instead of querying the full topology from config DS and
filtering the bridges specific to connected Switch.Following
implementation been provided(to keep the existing behaviour)

(1) Both "bridge-reconciliation-inclusion-list" and "bridge-reconciliation-exclusion-list" are empty.
    it means it will keep the default behavior of reconciling on all bridges.
(2) Only "bridge-reconciliation-inclusion-list" has list of bridge.
    than plugin will only reconcile specified bridges.
(3) Only "bridge-reconciliation-exclusion-list" has list of bridge.
    than plugin will reconcile all the bridge, except excluding the specified bridges.
(4) Both bridge-reconciliation-inclusion-list and bridge-reconciliation-exclusion-list has bridges specified.
    this is invalid scenario, so it should log the warning saying this is not valid configuration,
    but plugin will give priority to "bridge-reconciliation-exclusion-list" and reconcile all the bridges
    except the one specified in the exclusion-list.

JIRA: OVSDB-459

Change-Id: Ife8055bcc10bcb6deb2fd8e0b5444bdf194f1460
Signed-off-by: Chetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundConstants.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProviderConfigurator.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTask.java
southbound/southbound-impl/src/main/resources/OSGI-INF/blueprint/southbound.xml
southbound/southbound-impl/src/main/resources/initial/southbound.cfg
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTaskTest.java

index 1b7a03c44c100076277eae93ffcb658d242a897b..48e77ce02101dfb02c8ea4bfc04cc23fa281243c 100755 (executable)
@@ -84,6 +84,7 @@ public interface SouthboundConstants {
     String QOS_LINUX_CODEL = "linux-codel";
     String QOS_LINUX_FQ_CODEL = "linux-fq_codel";
     String QOS_EGRESS_POLICER = "egress-policer";
+    String URI_SEPERATOR = "/";
     ImmutableBiMap<Class<? extends QosTypeBase>,String> QOS_TYPE_MAP
         = new ImmutableBiMap.Builder<Class<? extends QosTypeBase>,String>()
             .put(QosTypeLinuxHtb.class,QOS_LINUX_HTB)
index 41f7d075de072b43d0a8d029d406c49edba3d438..3cc833b08f82fd4802c116e8a5f80509d194f6e2 100644 (file)
@@ -10,7 +10,9 @@ package org.opendaylight.ovsdb.southbound;
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.annotation.PostConstruct;
@@ -76,6 +78,8 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
     private final AtomicBoolean registered = new AtomicBoolean(false);
     private ListenerRegistration<SouthboundProvider> operTopologyRegistration;
     private final OvsdbDiagStatusProvider ovsdbStatusProvider;
+    private static List<String> reconcileBridgeInclusionList = new ArrayList<>();
+    private static List<String> reconcileBridgeExclusionList = new ArrayList<>();
 
     @Inject
     public SouthboundProvider(@Reference final DataBroker dataBroker,
@@ -232,4 +236,20 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener<Topol
             SouthboundConstants.SKIP_COLUMN_FROM_TABLE.get("Manager").remove("status");
         }
     }
+
+    public static void setBridgesReconciliationInclusionList(List<String> bridgeList) {
+        reconcileBridgeInclusionList = bridgeList;
+    }
+
+    public static void setBridgesReconciliationExclusionList(List<String> bridgeList) {
+        reconcileBridgeExclusionList = bridgeList;
+    }
+
+    public static List<String> getBridgesReconciliationInclusionList() {
+        return reconcileBridgeInclusionList;
+    }
+
+    public static List<String> getBridgesReconciliationExclusionList() {
+        return reconcileBridgeExclusionList;
+    }
 }
index 6111f19d43cbb5fbf2afd45e5876a12c2fe67710..2eac4361374af41985fd6a959344e983dde52091 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.ovsdb.southbound;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -21,6 +24,8 @@ public class SouthboundProviderConfigurator {
     private static final Logger LOG = LoggerFactory.getLogger(SouthboundProviderConfigurator.class);
 
     private static final String SKIP_MONITORING_MANAGER_STATUS_PARAM = "skip-monitoring-manager-status";
+    private static final String BRIDGES_RECONCILIATION_INCLUSION_LIST_PARAM = "bridges-reconciliation-inclusion-list";
+    private static final String BRIDGES_RECONCILIATION_EXCLUSION_LIST_PARAM = "bridges-reconciliation-exclusion-list";
 
     private final SouthboundProvider southboundProvider;
 
@@ -32,6 +37,28 @@ public class SouthboundProviderConfigurator {
         southboundProvider.setSkipMonitoringManagerStatus(flag);
     }
 
+    public void setBridgesReconciliationInclusionList(String bridgeListStr) {
+        if (bridgeListStr != null && !bridgeListStr.equals("")) {
+            southboundProvider.setBridgesReconciliationInclusionList(getBridgesList(bridgeListStr));
+        }
+    }
+
+    public void setBridgesReconciliationExclusionList(String bridgeListStr) {
+        if (bridgeListStr != null && !bridgeListStr.equals("")) {
+            southboundProvider.setBridgesReconciliationExclusionList(getBridgesList(bridgeListStr));
+        }
+    }
+
+    private List<String> getBridgesList(final String bridgeListStr) {
+        List<String> bridgeList = new ArrayList<>();
+        StringTokenizer tokenizer = new StringTokenizer(bridgeListStr, ",");
+        while (tokenizer.hasMoreTokens()) {
+            bridgeList.add(tokenizer.nextToken());
+        }
+        return bridgeList;
+
+    }
+
     public void updateConfigParameter(Map<String, Object> configParameters) {
         if (configParameters != null && !configParameters.isEmpty()) {
             LOG.debug("Config parameters received : {}", configParameters.entrySet());
@@ -39,7 +66,16 @@ public class SouthboundProviderConfigurator {
                 if (paramEntry.getKey().equalsIgnoreCase(SKIP_MONITORING_MANAGER_STATUS_PARAM)) {
                     southboundProvider
                             .setSkipMonitoringManagerStatus(Boolean.parseBoolean((String) paramEntry.getValue()));
-                    break;
+                } else if (paramEntry.getKey().equalsIgnoreCase(BRIDGES_RECONCILIATION_INCLUSION_LIST_PARAM)) {
+                    String bridgeListStr = (String)paramEntry.getValue();
+                    if (bridgeListStr != null && !bridgeListStr.equals("")) {
+                        southboundProvider.setBridgesReconciliationInclusionList(getBridgesList(bridgeListStr));
+                    }
+                } else if (paramEntry.getKey().equalsIgnoreCase(BRIDGES_RECONCILIATION_EXCLUSION_LIST_PARAM)) {
+                    String bridgeListStr = (String)paramEntry.getValue();
+                    if (bridgeListStr != null && !bridgeListStr.equals("")) {
+                        southboundProvider.setBridgesReconciliationExclusionList(getBridgesList(bridgeListStr));
+                    }
                 }
             }
         }
index 4de54198bcceaad6b1dcc7ca930d9f31752c7d87..6c14db8f71de467d347a304d0f24f5a880682dc9 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
 import org.opendaylight.ovsdb.southbound.OvsdbConnectionManager;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.ovsdb.southbound.SouthboundProvider;
 import org.opendaylight.ovsdb.southbound.ovsdb.transact.BridgeOperationalState;
 import org.opendaylight.ovsdb.southbound.ovsdb.transact.DataChangeEvent;
 import org.opendaylight.ovsdb.southbound.ovsdb.transact.DataChangesManagedByOvsdbNodeEvent;
@@ -40,6 +41,7 @@ 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.ovsdb.bridge.attributes.ControllerEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryKey;
+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.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -67,58 +69,146 @@ public class BridgeConfigReconciliationTask extends ReconciliationTask {
         this.instanceIdentifierCodec = instanceIdentifierCodec;
     }
 
+
     @Override
     public boolean reconcileConfiguration(final OvsdbConnectionManager connectionManagerOfDevice) {
-        CheckedFuture<Optional<Topology>, ReadFailedException> readTopologyFuture;
-        InstanceIdentifier<Topology> topologyInstanceIdentifier = SouthboundMapper.createTopologyInstanceIdentifier();
-        try (ReadOnlyTransaction tx = reconciliationManager.getDb().newReadOnlyTransaction()) {
-            // find all bridges of the specific device in the config data store
-            // TODO: this query is not efficient. It retrieves all the Nodes in the datastore, loop over them and look
-            // for the bridges of specific device. It is mre efficient if MDSAL allows query nodes using wildcard on
-            // node id (ie: ovsdb://uuid/<device uuid>/bridge/*) r attributes
-            readTopologyFuture = tx.read(CONFIGURATION, topologyInstanceIdentifier);
+
+        String nodeIdVal = nodeIid.firstKeyOf(Node.class).getNodeId().getValue();
+        List<String> bridgeReconcileIncludeList = getNodeIdForBridges(nodeIdVal,
+            SouthboundProvider.getBridgesReconciliationInclusionList());
+        List<String> bridgeReconcileExcludeList = getNodeIdForBridges(nodeIdVal,
+            SouthboundProvider.getBridgesReconciliationExclusionList());
+
+        LOG.trace("bridgeReconcileIncludeList : {}", bridgeReconcileIncludeList);
+        LOG.trace("bridgeReconcileExcludeList : {}", bridgeReconcileExcludeList);
+        // (1) Both "bridge-reconciliation-inclusion-list" and "bridge-reconciliation-exclusion-list" are empty.
+        // it means it will keep the default behavior of reconciling on all bridges.
+        // (2) Only "bridge-reconciliation-inclusion-list" has list of bridge.
+        // than plugin will only reconcile specified bridges.
+        // (3) Only "bridge-reconciliation-exclusion-list" has list of bridge.
+        // than plugin will reconcile all the bridge, except excluding the specified bridges.
+        // (4) Both bridge-reconciliation-inclusion-list and bridge-reconciliation-exclusion-list has bridges specified.
+        // this is invalid scenario, so it should log the warning saying this is not valid configuration,
+        // but plugin will give priority to "bridge-reconciliation-exclusion-list" and reconcile all the bridges
+        // except the one specified in the exclusion-list.
+
+        Boolean reconcileAllBridges = Boolean.FALSE;
+        if ((bridgeReconcileIncludeList.isEmpty() && bridgeReconcileExcludeList.isEmpty())
+            || (bridgeReconcileIncludeList.isEmpty() && !bridgeReconcileExcludeList.isEmpty())) {
+            // Case 1 & 3
+            reconcileAllBridges = Boolean.TRUE;
+        } else if (!bridgeReconcileIncludeList.isEmpty() && !bridgeReconcileExcludeList.isEmpty()) {
+            // Case 4
+            LOG.warn(
+                "Not a valid case of having both inclusion list : {} and exclusion list : {} for reconcile."
+                    + "OvsDb Plugin will reconcile all the bridge excluding exclusion list bridges",
+                bridgeReconcileIncludeList, bridgeReconcileExcludeList);
+            reconcileAllBridges = Boolean.TRUE;
         }
-        Futures.addCallback(readTopologyFuture, new FutureCallback<Optional<Topology>>() {
-            @Override
-            public void onSuccess(@Nullable Optional<Topology> optionalTopology) {
-                if (optionalTopology != null && optionalTopology.isPresent()) {
-                    @SuppressWarnings("unchecked")
-                    InstanceIdentifier<Node> ndIid = (InstanceIdentifier<Node>) nodeIid;
-                    Topology topology = optionalTopology.get();
-                    if (topology.getNode() != null) {
-                        final Map<InstanceIdentifier<?>, DataObject> brChanges = new HashMap<>();
-                        final List<Node> tpChanges = new ArrayList<>();
-                        for (Node node : topology.getNode()) {
-                            LOG.debug("Reconcile Configuration for node {}", node.getNodeId());
-                            OvsdbBridgeAugmentation bridge = node.augmentation(OvsdbBridgeAugmentation.class);
-                            if (bridge != null && bridge.getManagedBy() != null
-                                    && bridge.getManagedBy().getValue().equals(ndIid)) {
-                                brChanges.putAll(extractBridgeConfigurationChanges(node, bridge));
-                                tpChanges.add(node);
-                            } else if (node.key().getNodeId().getValue().startsWith(
-                                    nodeIid.firstKeyOf(Node.class).getNodeId().getValue())
-                                    && node.getTerminationPoint() != null && !node.getTerminationPoint().isEmpty()) {
-                                tpChanges.add(node);
+
+        List<Node> bridgeNodeList = new ArrayList<>();
+
+        if (reconcileAllBridges) {
+            // case 1, 3 & 4
+            LOG.trace("Reconciling all bridges with exclusion list {}", bridgeReconcileExcludeList);
+            CheckedFuture<Optional<Topology>, ReadFailedException> readTopologyFuture;
+            InstanceIdentifier<Topology> topologyInstanceIdentifier = SouthboundMapper
+                .createTopologyInstanceIdentifier();
+            try (ReadOnlyTransaction tx = reconciliationManager.getDb().newReadOnlyTransaction()) {
+                // find all bridges of the specific device in the config data store
+                // TODO: this query is not efficient. It retrieves all the Nodes in the datastore, loop over them and
+                // look for the bridges of specific device. It is mre efficient if MDSAL allows query nodes using
+                // wildcard on node id (ie: ovsdb://uuid/<device uuid>/bridge/*) r attributes
+                readTopologyFuture = tx.read(CONFIGURATION, topologyInstanceIdentifier);
+            }
+            Futures.addCallback(readTopologyFuture, new FutureCallback<Optional<Topology>>() {
+                @Override
+                public void onSuccess(@Nullable Optional<Topology> optionalTopology) {
+                    if (optionalTopology != null && optionalTopology.isPresent()) {
+                        @SuppressWarnings("unchecked")
+                        Topology topology = optionalTopology.get();
+                        if (topology.getNode() != null) {
+                            for (Node node : topology.getNode()) {
+                                String bridgeNodeIid = node.getNodeId().getValue();
+                                LOG.trace("bridgeNodeIid : {}", bridgeNodeIid);
+                                if (bridgeReconcileExcludeList.contains(bridgeNodeIid)) {
+                                    LOG.trace(
+                                        "Ignoring reconcilation on bridge:{} as its part of exclusion list",
+                                        bridgeNodeIid);
+                                    continue;
+                                }
+                                bridgeNodeList.add(node);
                             }
                         }
-                        if (!brChanges.isEmpty()) {
-                            reconcileBridgeConfigurations(brChanges);
-                        }
-                        if (!tpChanges.isEmpty()) {
-                            reconciliationManager.reconcileTerminationPoints(
-                                    connectionManagerOfDevice, connectionInstance, tpChanges);
-                        }
                     }
                 }
-            }
 
-            @Override
-            public void onFailure(Throwable throwable) {
-                LOG.warn("Read Config/DS for Topology failed! {}", nodeIid, throwable);
+                @Override
+                public void onFailure(Throwable throwable) {
+                    LOG.warn("Read Config/DS for Topology failed! {}", nodeIid, throwable);
+                }
+
+            }, MoreExecutors.directExecutor());
+        } else {
+            // Case 3
+            // Reconciling Specific set of bridges in order to avoid full Topology Read.
+            CheckedFuture<Optional<Node>, ReadFailedException> readNodeFuture;
+            LOG.trace("Reconcile Bridge from InclusionList {} only", bridgeReconcileIncludeList);
+            for (String bridgeNodeIid : bridgeReconcileIncludeList) {
+                try (ReadOnlyTransaction tx = reconciliationManager.getDb().newReadOnlyTransaction()) {
+                    InstanceIdentifier<Node> nodeInstanceIdentifier =
+                        SouthboundMapper.createInstanceIdentifier(new NodeId(bridgeNodeIid));
+                    readNodeFuture = tx.read(CONFIGURATION, nodeInstanceIdentifier);
+                }
+                Futures.addCallback(readNodeFuture, new FutureCallback<Optional<Node>>() {
+                    @Override
+                    public void onSuccess(@Nullable Optional<Node> optionalTopology) {
+                        if (optionalTopology != null && optionalTopology.isPresent()) {
+                            @SuppressWarnings("unchecked")
+
+                            Node node = optionalTopology.get();
+                            if (node != null) {
+                                bridgeNodeList.add(node);
+                            }
+                        } else {
+                            LOG.info("Reconciliation of bridge {} missing in network-topology config DataStore",
+                                bridgeNodeIid);
+                        }
+                    }
+
+                    @Override
+                    public void onFailure(Throwable throwable) {
+                        LOG.warn("Read Config/DS for Topology failed! {}", bridgeNodeIid, throwable);
+                    }
+                }, MoreExecutors.directExecutor());
             }
+        }
 
-        }, MoreExecutors.directExecutor());
+        final Map<InstanceIdentifier<?>, DataObject> brChanges = new HashMap<>();
+        final List<Node> tpChanges = new ArrayList<>();
+        for (Node node : bridgeNodeList) {
+            InstanceIdentifier<Node> ndIid = (InstanceIdentifier<Node>) nodeIid;
+            OvsdbBridgeAugmentation bridge = node.augmentation(OvsdbBridgeAugmentation.class);
+            if (bridge != null && bridge.getManagedBy() != null
+                && bridge.getManagedBy().getValue().equals(ndIid)) {
+                brChanges.putAll(extractBridgeConfigurationChanges(node, bridge));
+                tpChanges.add(node);
+            } else if (node.key().getNodeId().getValue().startsWith(
+                nodeIid.firstKeyOf(Node.class).getNodeId().getValue())
+                && node.getTerminationPoint() != null && !node.getTerminationPoint().isEmpty()) {
+                tpChanges.add(node);
+            } else {
+                LOG.trace("Ignoring Reconcilation of Bridge: {}", node.key().getNodeId().getValue());
+            }
+        }
 
+        if (!brChanges.isEmpty()) {
+            reconcileBridgeConfigurations(brChanges);
+        }
+        if (!tpChanges.isEmpty()) {
+            reconciliationManager.reconcileTerminationPoints(
+                    connectionManagerOfDevice, connectionInstance, tpChanges);
+        }
         return true;
     }
 
@@ -199,4 +289,15 @@ public class BridgeConfigReconciliationTask extends ReconciliationTask {
     public long retryDelayInMills() {
         return 0;
     }
+
+    private List<String> getNodeIdForBridges(String nodeIdVal, List<String> bridgeList) {
+        List<String> nodeIdBridgeList = new ArrayList<>();
+        for (String bridge : bridgeList) {
+            String bridgeNodeIid = new StringBuilder().append(nodeIdVal)
+                .append(SouthboundConstants.URI_SEPERATOR).append(SouthboundConstants.BRIDGE_URI_PREFIX)
+                .append(SouthboundConstants.URI_SEPERATOR).append(bridge).toString();
+            nodeIdBridgeList.add(bridgeNodeIid);
+        }
+        return nodeIdBridgeList;
+    }
 }
index 2693703f070334e4b4afe509ac8c85cdac9dbb98..d4b0b05bf089b36e7980524d633066eb415b716a 100644 (file)
@@ -7,6 +7,8 @@
     <cm:property-placeholder persistent-id="org.opendaylight.ovsdb.southbound" update-strategy="none">
     <cm:default-properties>
       <cm:property name="skip-monitoring-manager-status" value="false"/>
+      <cm:property name="bridge-reconciliation-inclusion-list" value=""/>
+      <cm:property name="bridge-reconciliation-exclusion-list" value=""/>
     </cm:default-properties>
   </cm:property-placeholder>
 
@@ -17,6 +19,8 @@
                            update-method="updateConfigParameter"/>
     <argument ref="southboundProvider" />
     <property name="skipMonitoringManagerStatus" value="${skip-monitoring-manager-status}"/>
+    <property name="bridgesReconciliationInclusionList" value="${bridge-reconciliation-inclusion-list}"/>
+    <property name="bridgesReconciliationExclusionList" value="${bridge-reconciliation-exclusion-list}"/>
   </bean>
 
 </blueprint>
index 576d50148190612db4a476284f1db5dceb11682b..d6b4bc2cd2dfbb3f4a4b09b9c7493e2927510d9f 100644 (file)
 # setup. So please use this option when you are running OVSDB
 # southbound plugin in single node and want to achieve better
 # performance.
-#skip-monitoring-manager-status = false
\ No newline at end of file
+#skip-monitoring-manager-status = false
+
+# Setting bridge-reconciliation-inclusion-list and bridge-reconciliation-exclusion-list value
+# with a list of comma seperated bridges. During Reconciliation, this parameter will be read by
+# reconcilation manager and trigger reconcilation as below
+# (1) Both "bridge-reconciliation-inclusion-list" and "bridge-reconciliation-exclusion-list" are empty : it means it will keep the default behavior of reconciling on all bridges.
+# (2) Only "bridge-reconciliation-inclusion-list" has list of bridge : than plugin will only reconcile specified bridges.
+# (3) Only "bridge-reconciliation-exclusion-list" has list of bridge : than plugin will reconcile all the bridge, except excluding the specified bridges.
+# (4) Both "bridge-reconciliation-inclusion-list" and "bridge-reconcliation-exclusion-list" has bridges specified : this is invalid scenario, so it should log the warning saying this is not valid configuration, but plugin will give priority to "bridge-reconciliation-exclusion-list" and reconcile all the bridges except the one specified in the exclusion-list.
+# Ex : bridge-reconciliation-inclusion-list = "br-int,br-tun"
+bridge-reconciliation-inclusion-list = ""
+bridge-reconciliation-exclusion-list = ""
index f14d6b37a3d6f060db93583130b5957fc381b0f5..54410de40b42cd4c3037063ad2e7d93dfe25b666 100644 (file)
@@ -19,6 +19,7 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -38,6 +39,7 @@ import org.opendaylight.ovsdb.southbound.InstanceIdentifierCodec;
 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
 import org.opendaylight.ovsdb.southbound.OvsdbConnectionManager;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.ovsdb.southbound.SouthboundProvider;
 import org.opendaylight.ovsdb.southbound.reconciliation.ReconciliationManager;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
@@ -59,8 +61,7 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 
 @RunWith(MockitoJUnitRunner.class)
 public class BridgeConfigReconciliationTaskTest {
-    private static final String BR01 = "br01";
-    private static final String BR02 = "br02";
+    private static final String BR_INT = "br-int";
     private static final String NODE_ID = "ovsdb://uuid/6ff3d0cf-4102-429d-b41c-f8027a0fd7f4";
     private BridgeConfigReconciliationTask configurationReconciliationTask;
     @Mock private OvsdbConnectionManager ovsdbConnectionManager;
@@ -69,29 +70,26 @@ public class BridgeConfigReconciliationTaskTest {
     @Mock private ReconciliationManager reconciliationManager;
     @Mock private Topology topology;
     @Mock private InstanceIdentifier<Node> iid;
+    @Mock private SouthboundProvider provider;
 
     @Before
     public void setUp() throws Exception {
         NodeKey nodeKey = new NodeKey(new NodeId(new Uri(NODE_ID)));
         List<Node> bridgeNodes = new ArrayList<>();
 
-
+        iid = SouthboundMapper.createInstanceIdentifier(nodeKey.getNodeId());
         when(topology.getNode()).thenReturn(bridgeNodes);
-
-        Optional<Topology> topologyOptional = Optional.of(topology);
-        CheckedFuture<Optional<Topology>, ReadFailedException> readTopologyFuture =
-                Futures.immediateCheckedFuture(topologyOptional);
-
+        SouthboundProvider.setBridgesReconciliationInclusionList(Arrays.asList(BR_INT));
+        Node brIntNode = createBridgeNode(NODE_ID + "/bridge/" + BR_INT);
+        Optional<Node> nodeOptional = Optional.of(brIntNode);
+        CheckedFuture<Optional<Node>, ReadFailedException> readNodeFuture =
+                Futures.immediateCheckedFuture(nodeOptional);
         when(reconciliationManager.getDb()).thenReturn(db);
         ReadOnlyTransaction tx = mock(ReadOnlyTransaction.class);
         Mockito.when(db.newReadOnlyTransaction()).thenReturn(tx);
         Mockito.when(tx.read(any(LogicalDatastoreType.class),any(InstanceIdentifier.class)))
-                .thenReturn(readTopologyFuture);
-
-        when(topology.getNode()).thenReturn(bridgeNodes);
-        when(ovsdbConnectionInstance.getNodeKey()).thenReturn(nodeKey);
-        bridgeNodes.add(createBridgeNode(BR01));
-        bridgeNodes.add(createBridgeNode(BR02));
+                .thenReturn(readNodeFuture);
+        bridgeNodes.add(brIntNode);
 
         configurationReconciliationTask =
                 new BridgeConfigReconciliationTask(reconciliationManager, ovsdbConnectionManager, iid,
@@ -112,8 +110,7 @@ public class BridgeConfigReconciliationTaskTest {
 
     private Node createBridgeNode(final String bridgeName) {
         Node bridgeNode = mock(Node.class);
-        String nodeString = ovsdbConnectionInstance.getNodeKey().getNodeId().getValue()
-                + "/bridge/" + bridgeName;
+        String nodeString = bridgeName;
         when(bridgeNode.getNodeId()).thenReturn(new NodeId(new Uri(nodeString)));
         OvsdbBridgeAugmentation ovsdbBridgeAugmentation = mock(OvsdbBridgeAugmentation.class);
         OvsdbNodeRef ovsdbNodeRef = mock(OvsdbNodeRef.class);