Fixes the NPE case when router is removed in Kubevirt networking app.
Change-Id: Icbbf9cad5857e74211b94862996009a1830959fc
(cherry picked from commit 7aed950e0e9f49384878e761b0e7fd57bfcdc0e8)
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java
index e73bd01..f5fcd43 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingSnatHandler.java
@@ -666,26 +666,29 @@
if (!isRelevantHelper()) {
return;
}
- if (!router.external().isEmpty() && router.peerRouter() != null) {
+
+
+ if (!router.external().isEmpty() && router.peerRouter() != null && router.electedGateway() != null) {
initGatewayNodeSnatForRouter(router, router.electedGateway(), false);
- }
- KubevirtNode gatewayNode = kubevirtNodeService.node(router.electedGateway());
- router.internal()
- .stream()
- .filter(networkId -> kubevirtNetworkService.network(networkId) != null)
- .map(kubevirtNetworkService::network)
- .forEach(network -> {
- String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
- if (routerSnatIp == null) {
- return;
- }
+ KubevirtNode gatewayNode = kubevirtNodeService.node(router.electedGateway());
- kubevirtPortService.ports(network.networkId()).forEach(kubevirtPort -> {
- setStatefulSnatDownStreamRuleForKubevirtPort(router,
- gatewayNode, kubevirtPort, false);
+ router.internal()
+ .stream()
+ .filter(networkId -> kubevirtNetworkService.network(networkId) != null)
+ .map(kubevirtNetworkService::network)
+ .forEach(network -> {
+ String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
+ if (routerSnatIp == null) {
+ return;
+ }
+
+ kubevirtPortService.ports(network.networkId()).forEach(kubevirtPort -> {
+ setStatefulSnatDownStreamRuleForKubevirtPort(router,
+ gatewayNode, kubevirtPort, false);
+ });
});
- });
+ }
}
private void processRouterUpdate(KubevirtRouter router) {