From a384a1750100c715dafac7f1111a17569dad21b1 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Wed, 6 Dec 2023 16:09:21 +0100 Subject: [PATCH] Refactor tests + wait for namespace deletion in RM + prepare for upgrade --- pom.xml | 21 +++++++-- .../framework/manager/ResourceManager.java | 7 ++- .../manager/resources/NamespaceResource.java | 43 +++++++++++++++++++ ...usterIT.java => DataScienceClusterST.java} | 2 +- ...ojectIT.java => DataScienceProjectST.java} | 4 +- ...usterIT.java => DataScienceClusterST.java} | 35 ++------------- .../io/odh/test/e2e/standard/UpgradeST.java | 11 +++++ 7 files changed, 84 insertions(+), 39 deletions(-) create mode 100644 src/main/java/io/odh/test/framework/manager/resources/NamespaceResource.java rename src/test/java/io/odh/test/e2e/continuous/{DataScienceClusterIT.java => DataScienceClusterST.java} (99%) rename src/test/java/io/odh/test/e2e/continuous/{DataScienceProjectIT.java => DataScienceProjectST.java} (97%) rename src/test/java/io/odh/test/e2e/standard/{DataScienceClusterIT.java => DataScienceClusterST.java} (72%) create mode 100644 src/test/java/io/odh/test/e2e/standard/UpgradeST.java diff --git a/pom.xml b/pom.xml index 4354e587..8ad7397a 100644 --- a/pom.xml +++ b/pom.xml @@ -304,9 +304,9 @@ continuous false - - io.odh.test.e2e.continuous.*IT - + + continuous + @@ -315,8 +315,21 @@ false - io.odh.test.e2e.standard.*IT + io.odh.test.e2e.standard.*ST + + !upgrade + + + + + + upgrade + + false + + upgrade + diff --git a/src/main/java/io/odh/test/framework/manager/ResourceManager.java b/src/main/java/io/odh/test/framework/manager/ResourceManager.java index c2040eb6..5f340b78 100644 --- a/src/main/java/io/odh/test/framework/manager/ResourceManager.java +++ b/src/main/java/io/odh/test/framework/manager/ResourceManager.java @@ -5,6 +5,7 @@ package io.odh.test.framework.manager; import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.Namespace; import io.fabric8.kubernetes.api.model.admissionregistration.v1.ValidatingWebhookConfiguration; import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; import io.fabric8.kubernetes.api.model.apps.Deployment; @@ -13,6 +14,7 @@ import io.odh.test.TestConstants; import io.odh.test.TestUtils; import io.odh.test.framework.manager.resources.DataScienceClusterResource; +import io.odh.test.framework.manager.resources.NamespaceResource; import io.odh.test.framework.manager.resources.NotebookResource; import io.odh.test.framework.manager.resources.OperatorGroupResource; import io.odh.test.framework.manager.resources.SubscriptionResource; @@ -60,6 +62,7 @@ public static KubeCmdClient getKubeCmdClient() { } private final ResourceType[] resourceTypes = new ResourceType[]{ + new NamespaceResource(), new SubscriptionResource(), new OperatorGroupResource(), new DataScienceClusterResource(), @@ -194,7 +197,9 @@ public final boolean waitResourceCondition(T resource, R assertNotNull(resource.getMetadata().getName()); // cluster role binding and custom resource definition does not need namespace... - if (!(resource instanceof ClusterRoleBinding || resource instanceof CustomResourceDefinition || resource instanceof ClusterRole || resource instanceof ValidatingWebhookConfiguration || resource instanceof DataScienceCluster)) { + if (!(resource instanceof ClusterRoleBinding || resource instanceof CustomResourceDefinition + || resource instanceof ClusterRole || resource instanceof ValidatingWebhookConfiguration + || resource instanceof DataScienceCluster || resource instanceof Namespace)) { assertNotNull(resource.getMetadata().getNamespace()); } diff --git a/src/main/java/io/odh/test/framework/manager/resources/NamespaceResource.java b/src/main/java/io/odh/test/framework/manager/resources/NamespaceResource.java new file mode 100644 index 00000000..b0ed6250 --- /dev/null +++ b/src/main/java/io/odh/test/framework/manager/resources/NamespaceResource.java @@ -0,0 +1,43 @@ +/* + * Copyright Skodjob authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.odh.test.framework.manager.resources; + +import io.fabric8.kubernetes.api.model.Namespace; +import io.odh.test.framework.manager.ResourceManager; +import io.odh.test.framework.manager.ResourceType; + + +public class NamespaceResource implements ResourceType { + + @Override + public String getKind() { + return "Namespace"; + } + + @Override + public Namespace get(String namespace, String name) { + return ResourceManager.getClient().getClient().namespaces().withName(name).get(); + } + + @Override + public void create(Namespace resource) { + ResourceManager.getClient().getClient().resource(resource).create(); + } + + @Override + public void delete(Namespace resource) { + ResourceManager.getClient().getClient().namespaces().withName(resource.getMetadata().getName()).delete(); + } + + @Override + public void update(Namespace resource) { + ResourceManager.getClient().getClient().resource(resource).update(); + } + + @Override + public boolean waitForReadiness(Namespace resource) { + return resource != null; + } +} diff --git a/src/test/java/io/odh/test/e2e/continuous/DataScienceClusterIT.java b/src/test/java/io/odh/test/e2e/continuous/DataScienceClusterST.java similarity index 99% rename from src/test/java/io/odh/test/e2e/continuous/DataScienceClusterIT.java rename to src/test/java/io/odh/test/e2e/continuous/DataScienceClusterST.java index 2ba9faf0..9835d0d5 100644 --- a/src/test/java/io/odh/test/e2e/continuous/DataScienceClusterIT.java +++ b/src/test/java/io/odh/test/e2e/continuous/DataScienceClusterST.java @@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @Tag("continuous") -public class DataScienceClusterIT extends Abstract { +public class DataScienceClusterST extends Abstract { private static final String DS_CLUSTER_NAME = "default"; private static final String DS_DASHBOARD_CONFIG_NAME = "odh-dashboard-config"; diff --git a/src/test/java/io/odh/test/e2e/continuous/DataScienceProjectIT.java b/src/test/java/io/odh/test/e2e/continuous/DataScienceProjectST.java similarity index 97% rename from src/test/java/io/odh/test/e2e/continuous/DataScienceProjectIT.java rename to src/test/java/io/odh/test/e2e/continuous/DataScienceProjectST.java index ae14f314..0942dfd2 100644 --- a/src/test/java/io/odh/test/e2e/continuous/DataScienceProjectIT.java +++ b/src/test/java/io/odh/test/e2e/continuous/DataScienceProjectST.java @@ -25,8 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @Tag("continuous") -public class DataScienceProjectIT extends Abstract { - static final Logger LOGGER = LoggerFactory.getLogger(DataScienceProjectIT.class); +public class DataScienceProjectST extends Abstract { + static final Logger LOGGER = LoggerFactory.getLogger(DataScienceProjectST.class); MixedOperation, Resource> notebookCli; diff --git a/src/test/java/io/odh/test/e2e/standard/DataScienceClusterIT.java b/src/test/java/io/odh/test/e2e/standard/DataScienceClusterST.java similarity index 72% rename from src/test/java/io/odh/test/e2e/standard/DataScienceClusterIT.java rename to src/test/java/io/odh/test/e2e/standard/DataScienceClusterST.java index f234ebd3..4febd4f3 100644 --- a/src/test/java/io/odh/test/e2e/standard/DataScienceClusterIT.java +++ b/src/test/java/io/odh/test/e2e/standard/DataScienceClusterST.java @@ -4,10 +4,6 @@ */ package io.odh.test.e2e.standard; -import io.fabric8.kubernetes.api.model.KubernetesResourceList; -import io.fabric8.kubernetes.api.model.NamespaceBuilder; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.Resource; import io.odh.test.framework.manager.ResourceManager; import io.opendatahub.datasciencecluster.v1.DataScienceCluster; import io.opendatahub.datasciencecluster.v1.DataScienceClusterBuilder; @@ -22,44 +18,21 @@ import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.KserveBuilder; import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Workbenches; import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.WorkbenchesBuilder; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -@Tag("standard") -public class DataScienceClusterIT extends StandardAbstract { +@Tag("smoke") +public class DataScienceClusterST extends StandardAbstract { private static final String DS_PROJECT_NAME = "test-dsp"; - private static final String DS_PROJECT_NAMESPACE = "test-ns-ds"; - MixedOperation, Resource> cli; - - @BeforeAll - void init() { - cli = ResourceManager.getClient().dataScienceClusterClient(); - } - - @AfterAll - void clean() { - cli.inNamespace(DS_PROJECT_NAMESPACE).withName(DS_PROJECT_NAME).delete(); - ResourceManager.getClient().getClient().namespaces().withName(DS_PROJECT_NAMESPACE).delete(); - } @Test void createDataScienceCluster() { - if (!ResourceManager.getClient().namespaceExists(DS_PROJECT_NAMESPACE)) { - ResourceManager.getClient().getClient() - .namespaces() - .resource(new NamespaceBuilder().withNewMetadata().withName(DS_PROJECT_NAMESPACE).endMetadata().build()) - .create(); - } - DataScienceCluster c = new DataScienceClusterBuilder() .withNewMetadata() .withName(DS_PROJECT_NAME) - .withNamespace(DS_PROJECT_NAMESPACE) .endMetadata() .withNewSpec() .withComponents( @@ -83,9 +56,9 @@ void createDataScienceCluster() { .endSpec() .build(); - cli.resource(c).create(); + ResourceManager.getInstance().createResourceWithWait(c); - DataScienceCluster cluster = cli.inNamespace(DS_PROJECT_NAMESPACE).withName(DS_PROJECT_NAME).get(); + DataScienceCluster cluster = ResourceManager.getClient().dataScienceClusterClient().withName(DS_PROJECT_NAME).get(); assertEquals(Kserve.ManagementState.MANAGED, cluster.getSpec().getComponents().getKserve().getManagementState()); assertEquals(Codeflare.ManagementState.MANAGED, cluster.getSpec().getComponents().getCodeflare().getManagementState()); diff --git a/src/test/java/io/odh/test/e2e/standard/UpgradeST.java b/src/test/java/io/odh/test/e2e/standard/UpgradeST.java new file mode 100644 index 00000000..cad6f897 --- /dev/null +++ b/src/test/java/io/odh/test/e2e/standard/UpgradeST.java @@ -0,0 +1,11 @@ +/* + * Copyright Skodjob authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.odh.test.e2e.standard; + +import org.junit.jupiter.api.Tag; + +@Tag("upgrade") +public class UpgradeST extends StandardAbstract { +}