Fix CSIT regression due to BGPCEP-878 fix 30/86430/1
authorAjay Lele <ajayslele@gmail.com>
Sat, 14 Dec 2019 04:09:13 +0000 (20:09 -0800)
committerRobert Varga <nite@hq.sk>
Mon, 16 Dec 2019 13:14:23 +0000 (13:14 +0000)
Handle scenario in BGPClusterSingletonService#restartNeighbors()
where BgpPeer#restart() is called after BgpPeer#closeServiceInstance()
without BgpPeer#restart() getting called in between.

JIRA: BGPCEP-878
Signed-off-by: Ajay Lele <ajayslele@gmail.com>
Change-Id: I5f8ac4ac4992e4641769243c91fac03bd0a96094
(cherry picked from commit a0281358d14e627b4e718d8b016e149ce8ed749f)

bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeer.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/config/BgpPeerTest.java

index 199aa548952d77cca6a12a44cd928c8b9c32cc3e..120cfa209eaf2429febb7dc9c4d994131ceff89d 100644 (file)
@@ -146,6 +146,10 @@ public class BgpPeer implements PeerBean, BGPPeerStateConsumer {
     public synchronized void restart(final RIB rib, final InstanceIdentifier<Bgp> bgpIid,
             final PeerGroupConfigLoader peerGroupLoader, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
         Preconditions.checkState(this.currentConfiguration != null);
+        if (this.bgpPeerSingletonService != null) {
+            this.bgpPeerSingletonService.closeServiceInstance();
+            this.bgpPeerSingletonService = null;
+        }
         start(rib, this.currentConfiguration, bgpIid, peerGroupLoader, tableTypeRegistry);
     }
 
index 4e39252368026e6478123061777ab26b000942b0..8a7811b47db27b5766bb5c5c54cddab381971d08 100644 (file)
@@ -158,16 +158,18 @@ public class BgpPeerTest extends AbstractConfig {
         verify(this.serviceRegistration).unregister();
 
         this.bgpPeer.restart(this.rib, null, this.peerGroupLoader, this.tableTypeRegistry);
-        this.bgpPeer.instantiateServiceInstance();
         verify(this.rib, times(2)).createPeerDOMChain(any());
         verify(this.rib, times(4)).getLocalAs();
         verify(this.rib, times(2)).getLocalTables();
+        this.bgpPeer.instantiateServiceInstance();
+        verify(this.bgpPeerRegistry, times(2)).addPeer(any(), any(), any());
+        verify(this.dispatcher, times(2)).createReconnectingClient(any(InetSocketAddress.class),
+                any(), anyInt(), any(KeyMapping.class));
 
         final Neighbor neighborExpected = createNeighborExpected(NEIGHBOR_ADDRESS);
         assertTrue(this.bgpPeer.containsEqualConfiguration(neighborExpected));
         assertFalse(this.bgpPeer.containsEqualConfiguration(createNeighborExpected(
                 new IpAddress(new Ipv4Address("127.0.0.2")))));
-        verify(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
 
         this.bgpPeer.closeServiceInstance();
         verify(this.bgpPeerRegistry, times(2)).removePeer(any());
@@ -181,6 +183,19 @@ public class BgpPeerTest extends AbstractConfig {
         this.bgpPeer.closeServiceInstance();
         verify(this.bgpPeerRegistry, times(3)).removePeer(any());
         verify(this.future, times(3)).cancel(true);
+        verify(this.rib, times(3)).createPeerDOMChain(any());
+
+        this.bgpPeer.restart(this.rib, null, this.peerGroupLoader, this.tableTypeRegistry);
+        verify(this.rib, times(4)).createPeerDOMChain(any());
+        verify(this.rib, times(6)).getLocalAs();
+        verify(this.rib, times(3)).getLocalTables();
+        this.bgpPeer.instantiateServiceInstance();
+        verify(this.bgpPeerRegistry, times(4)).addPeer(any(), any(), any());
+        verify(this.dispatcher, times(4)).createReconnectingClient(any(InetSocketAddress.class),
+                any(), anyInt(), any(KeyMapping.class));
+        this.bgpPeer.closeServiceInstance();
+        verify(this.bgpPeerRegistry, times(4)).removePeer(any());
+        verify(this.future, times(4)).cancel(true);
         this.bgpPeer.close();
         verify(this.serviceRegistration).unregister();