[VOL-4497] Do not update cpStatus map if the cp has been removed during device cleanup
Change-Id: I6c97ccb04dcf8879a297f620629bd7a117a8ed3b
diff --git a/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java b/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java
index c9bad5f..39f764e 100644
--- a/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java
+++ b/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java
@@ -77,9 +77,11 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
+import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.ERROR;
import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.NONE;
import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.ADDED;
import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.PENDING_ADD;
+import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.PENDING_REMOVE;
import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.REMOVED;
import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID_DEFAULT;
@@ -171,6 +173,38 @@
Assert.assertEquals(NONE, updated.dhcpStatus);
}
+ /**
+ * If the flow status is PENDING_REMOVE or ERROR and there is no
+ * previous state in the map that don't update it.
+ * In case of a device disconnection we immediately wipe out the status,
+ * but then flows might update the cpStatus map. That result
+ */
+ @Test
+ public void doNotUpdateConnectPointStatus() {
+ DeviceId deviceId = DeviceId.deviceId("test-device");
+ ProviderId pid = new ProviderId("of", "foo");
+ Device device =
+ new DefaultDevice(pid, deviceId, Device.Type.OLT, "", "", "", "", null);
+ Port port1 = new DefaultPort(device, PortNumber.portNumber(1), true,
+ DefaultAnnotations.builder().set(PORT_NAME, "port-1").build());
+
+ ServiceKey sk1 = new ServiceKey(new AccessDevicePort(port1), new UniTagInformation());
+
+ // cpStatus map for the test
+ oltFlowService.cpStatus = oltFlowService.storageService.
+ <ServiceKey, OltPortStatus>consistentMapBuilder().build().asJavaMap();
+
+ // check that an entry is not created if the only status is pending remove
+ oltFlowService.updateConnectPointStatus(sk1, null, null, PENDING_REMOVE);
+ OltPortStatus entry = oltFlowService.cpStatus.get(sk1);
+ Assert.assertNull(entry);
+
+ // check that an entry is not created if the only status is ERROR
+ oltFlowService.updateConnectPointStatus(sk1, null, null, ERROR);
+ entry = oltFlowService.cpStatus.get(sk1);
+ Assert.assertNull(entry);
+ }
+
@Test
public void testHasDefaultEapol() {
DeviceId deviceId = DeviceId.deviceId("test-device");