Fix: resolve a NPE if the VM is not attached with any interfaces
Change-Id: Ia9bf16e0e9871dc0deb18b80947231b5405ad55f
(cherry picked from commit a7c909adc6571db794b8df893748e2cccaed9715)
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtVmWatcher.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtVmWatcher.java
index e48bb18..69f1956 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtVmWatcher.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtVmWatcher.java
@@ -18,6 +18,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
@@ -382,6 +383,10 @@
JsonNode spec = json.get(SPEC).get(TEMPLATE).get(SPEC);
ArrayNode interfaces = (ArrayNode) spec.get(DOMAIN).get(DEVICES).get(INTERFACES);
+ // if the VM is not associated with any network, we skip parsing MAC address
+ if (interfaces == null) {
+ return ImmutableMap.of();
+ }
Map<MacAddress, String> result = new HashMap<>();
for (JsonNode intf : interfaces) {
String network = intf.get(NAME).asText();