Fix: wait the security group to be installed before install the rule
Change-Id: I76aa58ca06ae2801aab27772a098486066a490e5
(cherry picked from commit a5ff9da3585bed51397f592fb1def8e2404d2b19)
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtSecurityGroupWatcher.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtSecurityGroupWatcher.java
index 2fb53a9..5a25db3 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtSecurityGroupWatcher.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtSecurityGroupWatcher.java
@@ -50,6 +50,7 @@
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.kubevirtnetworking.api.Constants.KUBEVIRT_NETWORKING_APP_ID;
import static org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.k8sClient;
+import static org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.waitFor;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -328,6 +329,13 @@
if (sgr != null) {
log.trace("Process Security Group Rule {} creating event from API server.", sgr.id());
+ KubevirtSecurityGroup sg = adminService.securityGroup(sgr.securityGroupId());
+ if (sg == null) {
+ log.warn("Security Group {} is not found, we wait 5 seconds until " +
+ "the group to be installed.", sgr.securityGroupId());
+ waitFor(5);
+ }
+
if (adminService.securityGroupRule(sgr.id()) == null) {
adminService.createSecurityGroupRule(sgr);
}