From 66184ba073edf6cb2df0f54bbfb54171246af2b6 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Fri, 15 Mar 2019 12:37:01 +0530 Subject: [PATCH] Minor changes in tests according to changes + Wait till resource is deleted from cluster in failing tests --- .../test/java/io/fabric8/commons/DeleteEntity.java | 12 ++++++++++++ .../io/fabric8/kubernetes/ClusterRoleBindingIT.java | 9 ++++++++- .../java/io/fabric8/kubernetes/ClusterRoleIT.java | 10 +++++++++- .../java/io/fabric8/kubernetes/NetworkPolicyIT.java | 6 +++++- .../io/fabric8/kubernetes/PodSecurityPolicyIT.java | 9 +++++++++ .../java/io/fabric8/kubernetes/RoleBindingIT.java | 12 ++++++++++-- .../src/test/java/io/fabric8/kubernetes/RoleIT.java | 11 ++++++++++- .../openshift/SecurityContextConstraintsIT.java | 10 ++++++++-- 8 files changed, 71 insertions(+), 8 deletions(-) diff --git a/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java b/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java index 99dab60154a..e260ec4455e 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java +++ b/kubernetes-itests/src/test/java/io/fabric8/commons/DeleteEntity.java @@ -65,6 +65,18 @@ public Boolean call() { return this.client.apps().replicaSets().inNamespace(this.namespace).list().getItems().size() == 0; case "NetworkPolicy": return this.client.network().networkPolicies().inNamespace(this.namespace).list().getItems().size() == 0; + case "SecurityContextConstraints": + return ((OpenShiftClient)this.client).securityContextConstraints().withName(this.name).get() == null; + case "ClusterRoleBinding": + return this.client.rbac().clusterRoleBindings().withName(this.name).get() == null; + case "ClusterRole": + return this.client.rbac().clusterRoles().withName(this.name).get() == null; + case "RoleBinding": + return this.client.rbac().roleBindings().inNamespace(this.namespace).withName(this.name).get() == null; + case "Role": + return this.client.rbac().roles().inNamespace(this.namespace).withName(this.name).get() == null; + case "PodSecurityPolicy": + return this.client.extensions().podSecurityPolicies().withName(this.name).get() == null; default: return false; } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java index a13831a967c..55219f06864 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleBindingIT.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingBuilder; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBindingList; @@ -31,6 +32,9 @@ import org.junit.Test; import org.junit.runner.RunWith; +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -179,8 +183,11 @@ public void delete() { ClusterRoleBindingList clusterRoleBindingListBefore = client.rbac().clusterRoleBindings().list(); boolean deleted = client.rbac().clusterRoleBindings().withName("read-nodes").delete(); - assertTrue(deleted); + + DeleteEntity clusterRoleBindingDeleteEntity = new DeleteEntity<>(ClusterRoleBinding.class, client, "read-nodes", null); + await().atMost(30, TimeUnit.SECONDS).until(clusterRoleBindingDeleteEntity); + ClusterRoleBindingList clusterRoleBindingListAfter = client.rbac().clusterRoleBindings().list(); assertEquals(clusterRoleBindingListBefore.getItems().size()-1,clusterRoleBindingListAfter.getItems().size()); diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java index 3b47b37d838..49ed4c4a3e0 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/ClusterRoleIT.java @@ -16,7 +16,9 @@ package io.fabric8.kubernetes; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.ClusterRole; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleList; import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBuilder; @@ -31,6 +33,7 @@ import org.junit.Test; import org.junit.After; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -202,8 +205,11 @@ public void delete() { ClusterRoleList clusterRoleListBefore = client.rbac().clusterRoles().list(); boolean deleted = client.rbac().clusterRoles().withName("node-reader").delete(); - assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(ClusterRole.class, client, "node-reader", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + ClusterRoleList clusterRoleListAfter = client.rbac().clusterRoles().list(); assertEquals(clusterRoleListBefore.getItems().size()-1,clusterRoleListAfter.getItems().size()); } @@ -211,6 +217,8 @@ public void delete() { @After public void cleanup() { client.rbac().clusterRoles().withName("node-reader").delete(); + DeleteEntity deleteEntity = new DeleteEntity<>(ClusterRole.class, client, "node-reader", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); } } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java index 675a5700f28..4ea0876fdfa 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/NetworkPolicyIT.java @@ -170,12 +170,16 @@ public void delete(){ boolean deleted = client.network().networkPolicies().delete(networkPolicy); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(NetworkPolicy.class, client, "networkpolicy", currentNamespace); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + NetworkPolicyList networkPolicyList = client.network().networkPolicies().list(); assertEquals(0,networkPolicyList.getItems().size()); } @After - public void cleanup() throws InterruptedException { + public void cleanup() { if (client.network().networkPolicies().list().getItems().size()!= 0) { client.network().networkPolicies().delete(); } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java index d553227c1b8..ecd1e7cae65 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PodSecurityPolicyIT.java @@ -16,6 +16,7 @@ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicy; import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicyBuilder; import io.fabric8.kubernetes.api.model.extensions.PodSecurityPolicyList; @@ -24,6 +25,8 @@ import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; import org.arquillian.cube.requirement.ArquillianConditionalRunner; import org.jboss.arquillian.test.api.ArquillianResource; + +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; @@ -34,6 +37,7 @@ import org.junit.runner.RunWith; import java.util.Collections; +import java.util.concurrent.TimeUnit; @RunWith(ArquillianConditionalRunner.class) @RequiresKubernetes @@ -124,6 +128,9 @@ public void update(){ public void delete(){ boolean deleted = client.extensions().podSecurityPolicies().delete(podSecurityPolicy); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(PodSecurityPolicy.class, client, "test-example", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); PodSecurityPolicyList podSecurityPolicyList = client.extensions().podSecurityPolicies().list(); assertEquals(0,podSecurityPolicyList.getItems().size()); } @@ -131,5 +138,7 @@ public void delete(){ @After public void cleanup() { client.extensions().podSecurityPolicies().withName("test-example").delete(); + DeleteEntity deleteEntity = new DeleteEntity<>(PodSecurityPolicy.class, client, "test-example", null); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); } } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java index e4b4a2d73b1..2adae97f1e1 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleBindingIT.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.RoleBinding; import io.fabric8.kubernetes.api.model.rbac.RoleBindingList; import io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder; @@ -31,7 +32,9 @@ import org.junit.runner.RunWith; import java.util.Collections; +import java.util.concurrent.TimeUnit; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -170,11 +173,16 @@ public void update() { @Test public void delete() { - boolean deleted = client.rbac().roleBindings().inNamespace(currentNamespace).delete(); + Integer initialCountBeforeDeletion = client.rbac().roleBindings().inNamespace(currentNamespace).list().getItems().size(); + boolean deleted = client.rbac().roleBindings().inNamespace(currentNamespace).withName("read-jobs").delete(); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(RoleBinding.class, client, "read-jobs", currentNamespace); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + RoleBindingList roleBindingList = client.rbac().roleBindings().inNamespace(currentNamespace).list(); - assertEquals(0,roleBindingList.getItems().size()); + assertEquals(initialCountBeforeDeletion - 1,roleBindingList.getItems().size()); } @After diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java index 2c65d8f2e82..193d858a244 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/RoleIT.java @@ -15,6 +15,7 @@ */ package io.fabric8.kubernetes; +import io.fabric8.commons.DeleteEntity; import io.fabric8.kubernetes.api.model.rbac.Role; import io.fabric8.kubernetes.api.model.rbac.RoleList; import io.fabric8.kubernetes.api.model.rbac.RoleBuilder; @@ -29,6 +30,9 @@ import org.junit.Test; import org.junit.After; +import java.util.concurrent.TimeUnit; + +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -196,11 +200,16 @@ public void update() { @Test public void delete() { + Integer countBeforeDeletion = client.rbac().roles().inNamespace(currentNamespace).list().getItems().size(); boolean deleted = client.rbac().roles().inNamespace(currentNamespace).delete(); assertTrue(deleted); + + DeleteEntity deleteEntity = new DeleteEntity<>(Role.class, client, "job-reader", currentNamespace); + await().atMost(30, TimeUnit.SECONDS).until(deleteEntity); + RoleList roleList = client.rbac().roles().inNamespace(currentNamespace).list(); - assertEquals(0,roleList.getItems().size()); + assertEquals(countBeforeDeletion - 1,roleList.getItems().size()); } @After diff --git a/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java b/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java index cee0f4834ac..bd6ca22ede5 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/openshift/SecurityContextConstraintsIT.java @@ -16,6 +16,7 @@ package io.fabric8.openshift; +import io.fabric8.commons.DeleteEntity; import io.fabric8.openshift.api.model.SecurityContextConstraints; import io.fabric8.openshift.api.model.SecurityContextConstraintsBuilder; import io.fabric8.openshift.api.model.SecurityContextConstraintsList; @@ -29,7 +30,9 @@ import org.junit.runner.RunWith; import java.util.Collections; +import java.util.concurrent.TimeUnit; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.*; @RunWith(ArquillianConditionalRunner.class) @@ -152,11 +155,14 @@ public void delete(){ assertFalse(sccList.getItems().contains(scc)); } - @After public void cleanup() { + if (client.securityContextConstraints().list().getItems().size()!= 0) { + client.securityContextConstraints().withName("test-scc").delete(); + } - client.securityContextConstraints().withName("test-scc").delete(); + DeleteEntity sccDelete = new DeleteEntity<>(SecurityContextConstraints.class, client, "test-scc", null); + await().atMost(30, TimeUnit.SECONDS).until(sccDelete); } }