Fix: allow to obtains the added or removed internal on router event
Change-Id: I18bb5b361bf3c16d14cddec24ec9101812f3d4b9
diff --git a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java
index 7fd8958..d4d6b23 100644
--- a/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java
+++ b/apps/kubevirt-networking/api/src/main/java/org/onosproject/kubevirtnetworking/api/KubevirtRouterEvent.java
@@ -202,6 +202,33 @@
return podName;
}
+ /**
+ * Returns the internal of the router event.
+ *
+ * @return kubevirt internal network set, null if the event is not relevant to the internal
+ */
+ public Set<String> internal() {
+ return internal;
+ }
+
+ /**
+ * Returns the external IP address of the router event.
+ *
+ * @return external IP address, null if the event is not relevant to the external
+ */
+ public String externalIp() {
+ return externalIp;
+ }
+
+ /**
+ * Returns the external network of the router event.
+ *
+ * @return external network, null if the event is not relevant ot the external
+ */
+ public String externalNet() {
+ return externalNet;
+ }
+
@Override
public String toString() {
if (floatingIp == null) {
diff --git a/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java
index 2b90712..94b3161 100644
--- a/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java
+++ b/apps/kubevirt-networking/app/src/test/java/org/onosproject/kubevirtnetworking/impl/KubevirtRouterManagerTest.java
@@ -38,7 +38,9 @@
import org.onosproject.kubevirtnetworking.api.KubevirtRouterListener;
import org.onosproject.store.service.TestStorageService;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -96,6 +98,14 @@
.enableSnat(true)
.build();
+ private static final KubevirtRouter ROUTER_WITH_SINGLE_INTERNAL = DefaultKubevirtRouter.builder()
+ .name(ROUTER_NAME)
+ .description(ROUTER_NAME)
+ .internal(ImmutableSet.of("vxlan-1"))
+ .external(ImmutableMap.of())
+ .enableSnat(true)
+ .build();
+
private static final KubevirtRouter ROUTER_WITH_EXTERNAL = DefaultKubevirtRouter.builder()
.name(ROUTER_NAME)
.description(ROUTER_NAME)
@@ -236,6 +246,22 @@
KUBEVIRT_ROUTER_INTERNAL_NETWORKS_DETACHED);
}
+ @Test
+ public void testRouterInternalShrink() {
+ target.createRouter(ROUTER_WITH_INTERNAL);
+ assertEquals("Number of router did not match", 1, target.routers().size());
+ assertEquals("Router internal did not match", 2, target.router(ROUTER_NAME).internal().size());
+
+ target.updateRouter(ROUTER_WITH_SINGLE_INTERNAL);
+ assertEquals("Number of router did not match", 1, target.routers().size());
+ assertEquals("Router internal did not match", 1, target.router(ROUTER_NAME).internal().size());
+
+ validateEvents(KUBEVIRT_ROUTER_CREATED, KUBEVIRT_ROUTER_UPDATED,
+ KUBEVIRT_ROUTER_INTERNAL_NETWORKS_DETACHED);
+
+ validateInternalRemoval(ImmutableSet.of("vxlan-2"));
+ }
+
/**
* Tests router's external networks attached and detached.
*/
@@ -439,10 +465,18 @@
private static class TestKubevirtRouterListener implements KubevirtRouterListener {
private List<KubevirtRouterEvent> events = Lists.newArrayList();
+ private Set<String> internalAdded = new HashSet<>();
+ private Set<String> internalRemoved = new HashSet<>();
@Override
public void event(KubevirtRouterEvent event) {
events.add(event);
+ if (event.type() == KUBEVIRT_ROUTER_INTERNAL_NETWORKS_ATTACHED) {
+ internalAdded = event.internal();
+ }
+ if (event.type() == KUBEVIRT_ROUTER_INTERNAL_NETWORKS_DETACHED) {
+ internalRemoved = event.internal();
+ }
}
}
@@ -455,4 +489,14 @@
}
testListener.events.clear();
}
+
+ private void validateInternalAddition(Set<String> internal) {
+ assertEquals("internal addition entries", internal, testListener.internalAdded);
+ testListener.internalAdded.clear();
+ }
+
+ private void validateInternalRemoval(Set<String> internal) {
+ assertEquals("internal addition entries", internal, testListener.internalRemoved);
+ testListener.internalRemoved.clear();
+ }
}