diff --git a/pom.xml b/pom.xml index 0097e170..4ca83af9 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,35 @@ odh-e2e 1.0-SNAPSHOT + OpenDataHub e2e + https://github.com/ExcelentProject/odh-e2e + Test suite for testing opendatahub + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + kornys + David Kornel + kornys@outlook.com + + + Frawless + Jakub Stejskal + xstejs24@gmail.com + + + + + https://github.com/ExcelentProject/odh-e2e + + 17 17 diff --git a/src/main/java/io/odh/test/Environment.java b/src/main/java/io/odh/test/Environment.java new file mode 100644 index 00000000..02759fa5 --- /dev/null +++ b/src/main/java/io/odh/test/Environment.java @@ -0,0 +1,61 @@ +/* + * Copyright Tealc authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.odh.test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +/** + * Class which holds environment variables for system tests. + */ +public class Environment { + + private static final Logger LOGGER = LoggerFactory.getLogger(Environment.class); + private static final Map VALUES = new HashMap<>(); + + private static final String USERNAME_ENV = "KUBE_USERNAME"; + private static final String PASSWORD_ENV = "KUBE_PASSWORD"; + private static final String TOKEN_ENV = "KUBE_TOKEN"; + private static final String URL_ENV = "KUBE_URL"; + + /** + * Set values + */ + public static final String RUN_USER = getOrDefault("USER", null); + public static final String KUBE_USERNAME = getOrDefault(USERNAME_ENV, null); + public static final String KUBE_PASSWORD = getOrDefault(PASSWORD_ENV, null); + public static final String KUBE_TOKEN = getOrDefault(TOKEN_ENV, null); + public static final String KUBE_URL = getOrDefault(URL_ENV, null); + + private Environment() { } + + static { + String debugFormat = "{}: {}"; + LOGGER.info("Used environment variables:"); + VALUES.entrySet().stream() + .sorted(Map.Entry.comparingByKey()) + .forEach(entry -> LOGGER.info(debugFormat, entry.getKey(), entry.getValue())); + } + + public static void print() { } + + private static String getOrDefault(String varName, String defaultValue) { + return getOrDefault(varName, String::toString, defaultValue); + } + + private static T getOrDefault(String var, Function converter, T defaultValue) { + String value = System.getenv(var); + T returnValue = defaultValue; + if (value != null) { + returnValue = converter.apply(value); + } + VALUES.put(var, String.valueOf(returnValue)); + return returnValue; + } +} diff --git a/src/main/java/io/odh/test/TestConstants.java b/src/main/java/io/odh/test/TestConstants.java index dc1475f0..1a2b17c4 100644 --- a/src/main/java/io/odh/test/TestConstants.java +++ b/src/main/java/io/odh/test/TestConstants.java @@ -1,3 +1,7 @@ +/* + * Copyright Tealc authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ package io.odh.test; public class TestConstants { diff --git a/src/main/java/io/odh/test/framework/ExecutionListener.java b/src/main/java/io/odh/test/framework/ExecutionListener.java new file mode 100644 index 00000000..342e908e --- /dev/null +++ b/src/main/java/io/odh/test/framework/ExecutionListener.java @@ -0,0 +1,32 @@ +/* + * Copyright Tealc authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ +package io.odh.test.framework; + +import io.odh.test.Environment; +import org.junit.platform.launcher.TestExecutionListener; +import org.junit.platform.launcher.TestPlan; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ExecutionListener implements TestExecutionListener { + Logger LOGGER = LoggerFactory.getLogger(TestSeparator.class); + + public void testPlanExecutionStarted(TestPlan testPlan) { + LOGGER.info("======================================================================="); + LOGGER.info("======================================================================="); + LOGGER.info(" Test run started"); + LOGGER.info("======================================================================="); + LOGGER.info("======================================================================="); + Environment.print(); + } + + public void testPlanExecutionFinished(TestPlan testPlan) { + LOGGER.info("======================================================================="); + LOGGER.info("======================================================================="); + LOGGER.info(" Test run finished"); + LOGGER.info("======================================================================="); + LOGGER.info("======================================================================="); + } +} diff --git a/src/main/java/io/odh/test/separator/ExtensionContextParameterResolver.java b/src/main/java/io/odh/test/framework/ExtensionContextParameterResolver.java similarity index 96% rename from src/main/java/io/odh/test/separator/ExtensionContextParameterResolver.java rename to src/main/java/io/odh/test/framework/ExtensionContextParameterResolver.java index b9870631..703e9581 100644 --- a/src/main/java/io/odh/test/separator/ExtensionContextParameterResolver.java +++ b/src/main/java/io/odh/test/framework/ExtensionContextParameterResolver.java @@ -2,7 +2,7 @@ * Copyright Tealc authors. * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). */ -package io.odh.test.separator; +package io.odh.test.framework; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ParameterContext; diff --git a/src/main/java/io/odh/test/separator/TestSeparator.java b/src/main/java/io/odh/test/framework/TestSeparator.java similarity index 97% rename from src/main/java/io/odh/test/separator/TestSeparator.java rename to src/main/java/io/odh/test/framework/TestSeparator.java index f4396df5..88ab2785 100644 --- a/src/main/java/io/odh/test/separator/TestSeparator.java +++ b/src/main/java/io/odh/test/framework/TestSeparator.java @@ -2,7 +2,7 @@ * Copyright Tealc authors. * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). */ -package io.odh.test.separator; +package io.odh.test.framework; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; diff --git a/src/main/java/io/odh/test/platform/KubeClient.java b/src/main/java/io/odh/test/platform/KubeClient.java index 212026f6..1ec47c22 100644 --- a/src/main/java/io/odh/test/platform/KubeClient.java +++ b/src/main/java/io/odh/test/platform/KubeClient.java @@ -1,3 +1,7 @@ +/* + * Copyright Tealc authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ package io.odh.test.platform; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -12,12 +16,14 @@ import io.fabric8.kubernetes.api.model.batch.v1.JobList; import io.fabric8.kubernetes.api.model.batch.v1.JobStatus; import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; import io.fabric8.openshift.client.OpenShiftClient; +import io.odh.test.Environment; import io.opendatahub.datasciencecluster.v1.DataScienceCluster; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +39,7 @@ public class KubeClient { public KubeClient(String namespace) { LOGGER.debug("Creating client in namespace: {}", namespace); - Config config = Config.autoConfigure(System.getenv().getOrDefault("KUBE_CONTEXT", null)); + Config config = getConfig(); this.client = new KubernetesClientBuilder() .withConfig(config) @@ -74,6 +80,31 @@ public KubeClient inNamespace(String namespace) { return this; } + private Config getConfig() { + if (Environment.KUBE_PASSWORD != null && + Environment.KUBE_PASSWORD != null && + Environment.KUBE_URL != null) { + return new ConfigBuilder() + .withUsername(Environment.KUBE_USERNAME) + .withPassword(Environment.KUBE_PASSWORD) + .withMasterUrl(Environment.KUBE_URL) + .withDisableHostnameVerification(true) + .withTrustCerts(true) + .build(); + } else if (Environment.KUBE_URL != null && + Environment.KUBE_TOKEN != null) { + return new ConfigBuilder() + .withOauthToken(Environment.KUBE_TOKEN) + .withMasterUrl(Environment.KUBE_URL) + .withDisableHostnameVerification(true) + .withTrustCerts(true) + .build(); + } else { + return Config.autoConfigure(System.getenv() + .getOrDefault("KUBE_CONTEXT", null)); + } + } + public String getNamespace() { return namespace; } @@ -123,6 +154,7 @@ public List listPods(String namespaceName) { /** * Returns list of pods by prefix in pod name + * * @param namespaceName Namespace name * @param podNamePrefix prefix with which the name should begin * @return List of pods @@ -265,7 +297,7 @@ public List listJobs(String namePrefix) { .filter(job -> job.getMetadata().getName().startsWith(namePrefix)).collect(Collectors.toList()); } - public MixedOperation, Resource> dataScienceClusterClient() { + public MixedOperation, Resource> dataScienceClusterClient() { return client.resources(DataScienceCluster.class); } diff --git a/src/test/java/io/odh/test/e2e/Abstract.java b/src/test/java/io/odh/test/e2e/Abstract.java index 0ebfaf53..71b2d45a 100644 --- a/src/test/java/io/odh/test/e2e/Abstract.java +++ b/src/test/java/io/odh/test/e2e/Abstract.java @@ -1,8 +1,12 @@ +/* + * Copyright Tealc authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ package io.odh.test.e2e; import io.odh.test.platform.KubeClient; import io.odh.test.TestConstants; -import io.odh.test.separator.TestSeparator; +import io.odh.test.framework.TestSeparator; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestInstance; diff --git a/src/test/java/io/odh/test/e2e/deployed/DataScienceClusterIT.java b/src/test/java/io/odh/test/e2e/deployed/DataScienceClusterIT.java index d3a48617..74e736de 100644 --- a/src/test/java/io/odh/test/e2e/deployed/DataScienceClusterIT.java +++ b/src/test/java/io/odh/test/e2e/deployed/DataScienceClusterIT.java @@ -1,3 +1,7 @@ +/* + * Copyright Tealc authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ package io.odh.test.e2e.deployed; import io.fabric8.kubernetes.api.model.KubernetesResourceList; diff --git a/src/test/java/io/odh/test/unit/UnitTests.java b/src/test/java/io/odh/test/unit/UnitTests.java index 0114c9a5..64f7949a 100644 --- a/src/test/java/io/odh/test/unit/UnitTests.java +++ b/src/test/java/io/odh/test/unit/UnitTests.java @@ -1,3 +1,7 @@ +/* + * Copyright Tealc authors. + * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). + */ package io.odh.test.unit; import io.fabric8.kubernetes.api.model.KubernetesResourceList; @@ -6,7 +10,7 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.odh.test.separator.TestSeparator; +import io.odh.test.framework.TestSeparator; import io.opendatahub.datasciencecluster.v1.DataScienceCluster; import io.opendatahub.datasciencecluster.v1.DataScienceClusterBuilder; import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.ComponentsBuilder; diff --git a/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener new file mode 100644 index 00000000..07fe8432 --- /dev/null +++ b/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener @@ -0,0 +1 @@ +io.odh.test.framework.ExecutionListener \ No newline at end of file