Skip to content

Commit

Permalink
Refactor odh-e2e to use test-frame and avoid duplication of code
Browse files Browse the repository at this point in the history
Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys committed May 3, 2024
1 parent 77ea3f7 commit d87259c
Show file tree
Hide file tree
Showing 56 changed files with 474 additions and 2,753 deletions.
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<aspectj.version>1.9.21.2</aspectj.version>
<allure.version>2.25.0</allure.version>
<allure.maven.version>2.12.0</allure.maven.version>
<test-frame.version>0.1.0-SNAPSHOT</test-frame.version>
</properties>

<repositories>
Expand All @@ -71,6 +72,11 @@
<name>GitHub Apache Maven Packages</name>
<url>https://maven.pkg.github.com/skodjob/opendatahub-crds</url>
</repository>
<repository>
<id>test-frame</id>
<name>GitHub Apache Maven Packages</name>
<url>https://maven.pkg.github.com/skodjob/test-frame</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
Expand All @@ -93,6 +99,21 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-frame-common</artifactId>
<version>${test-frame.version}</version>
</dependency>
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-frame-kubernetes</artifactId>
<version>${test-frame.version}</version>
</dependency>
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-frame-openshift</artifactId>
<version>${test-frame.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package io.odh.test.framework.listeners;

import io.odh.test.Environment;
import io.odh.test.platform.KubeUtils;
import io.odh.test.platform.KubernetesUtils;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

Expand All @@ -14,7 +14,7 @@ public class OdhResourceCleaner implements AfterAllCallback {
@Override
public void afterAll(ExtensionContext extensionContext) {
if (!Environment.SKIP_INSTALL_OPERATOR && !Environment.SKIP_DEPLOY_DSCI_DSC) {
KubeUtils.clearOdhRemainingResources();
KubernetesUtils.clearOdhRemainingResources();
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

31 changes: 16 additions & 15 deletions src/main/java/io/odh/test/framework/logs/LogCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import io.odh.test.OdhConstants;
import io.odh.test.TestConstants;
import io.odh.test.TestUtils;
import io.odh.test.framework.manager.ResourceManager;
import io.odh.test.platform.KubeClient;
import io.odh.test.platform.cmdClient.KubeCmdClient;
import io.skodjob.testframe.clients.KubeClient;
import io.skodjob.testframe.clients.cmdClient.KubeCmdClient;
import io.skodjob.testframe.resources.KubeResourceManager;
import io.skodjob.testframe.utils.KubeUtils;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -31,12 +32,12 @@ public static void saveKubernetesState(ExtensionContext extensionContext, Throwa
Path logPath = TestUtils.getLogPath(Environment.LOG_DIR.resolve("failedTest").toString(), extensionContext);
Files.createDirectories(logPath);
try {
ResourceManager.addNamespaceForLogCollect(OdhConstants.BUNDLE_OPERATOR_NAMESPACE);
ResourceManager.addNamespaceForLogCollect(OdhConstants.OLM_OPERATOR_NAMESPACE);
ResourceManager.addNamespaceForLogCollect(OdhConstants.CONTROLLERS_NAMESPACE);
ResourceManager.addNamespaceForLogCollect(OdhConstants.MONITORING_NAMESPACE);
ResourceManager.addNamespaceForLogCollect(OdhConstants.ISTIO_SYSTEM_NAMESPACE);
ResourceManager.addNamespaceForLogCollect(OdhConstants.KNATIVE_SERVING_NAMESPACE);
KubeUtils.labelNamespace(OdhConstants.BUNDLE_OPERATOR_NAMESPACE, TestConstants.LOG_COLLECT_LABEL, "true");
KubeUtils.labelNamespace(OdhConstants.OLM_OPERATOR_NAMESPACE, TestConstants.LOG_COLLECT_LABEL, "true");
KubeUtils.labelNamespace(OdhConstants.CONTROLLERS_NAMESPACE, TestConstants.LOG_COLLECT_LABEL, "true");
KubeUtils.labelNamespace(OdhConstants.MONITORING_NAMESPACE, TestConstants.LOG_COLLECT_LABEL, "true");
KubeUtils.labelNamespace(OdhConstants.ISTIO_SYSTEM_NAMESPACE, TestConstants.LOG_COLLECT_LABEL, "true");
KubeUtils.labelNamespace(OdhConstants.KNATIVE_SERVING_NAMESPACE, TestConstants.LOG_COLLECT_LABEL, "true");
} catch (Exception ignored) {
LOGGER.warn("Cannot label namespaces for collect logs");
}
Expand All @@ -59,7 +60,7 @@ private static void writeLogsFromPods(Path logpath, Pod pod) {
try {
LOGGER.debug("Get logs from pod {}/{} container {}", pod.getMetadata().getNamespace(), pod.getMetadata().getName(), container.getName());
Files.writeString(logpath.resolve(pod.getMetadata().getNamespace()).resolve(pod.getMetadata().getName() + "-" + container.getName() + ".log"),
ResourceManager.getKubeClient().getLogsFromContainer(pod.getMetadata().getNamespace(), pod.getMetadata().getName(), container.getName()));
KubeResourceManager.getKubeClient().getLogsFromContainer(pod.getMetadata().getNamespace(), pod.getMetadata().getName(), container.getName()));
} catch (Exception e) {
LOGGER.warn("Cannot get logs for pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
}
Expand All @@ -75,7 +76,7 @@ private static void writePodsDescription(Path logpath, Pod pod) {
try {
LOGGER.debug("Get description of pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
Files.writeString(logpath.resolve(pod.getMetadata().getNamespace()).resolve(pod.getMetadata().getName() + ".describe.log"),
ResourceManager.getKubeCmdClient().namespace(pod.getMetadata().getNamespace()).describe(pod.getKind(), pod.getMetadata().getName()));
KubeResourceManager.getKubeCmdClient().namespace(pod.getMetadata().getNamespace()).describe(pod.getKind(), pod.getMetadata().getName()));
} catch (Exception e) {
LOGGER.warn("Cannot get description of pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
}
Expand All @@ -90,16 +91,16 @@ private static void writeDeployments(Path logpath, Deployment deployment) {
try {
LOGGER.debug("Get deployment {}/{}", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName());
Files.writeString(logpath.resolve(deployment.getMetadata().getNamespace()).resolve("deployment-" + deployment.getMetadata().getName() + ".yaml"),
ResourceManager.getKubeCmdClient().exec(false, false, "get", "deployment", deployment.getMetadata().getName(),
KubeResourceManager.getKubeCmdClient().exec(false, false, "get", "deployment", deployment.getMetadata().getName(),
"-n", deployment.getMetadata().getNamespace(), "-o", "yaml").out());
} catch (Exception e) {
LOGGER.warn("Cannot get deployment of pod {}/{}", deployment.getMetadata().getNamespace(), deployment.getMetadata().getName());
}
}

private static void saveClusterState(Path logpath) throws IOException {
KubeClient kube = ResourceManager.getKubeClient();
KubeCmdClient<?> cmdClient = ResourceManager.getKubeCmdClient();
KubeClient kube = KubeResourceManager.getKubeClient();
KubeCmdClient<?> cmdClient = KubeResourceManager.getKubeCmdClient();

// Collecting cluster wide resources and CRs
Files.writeString(logpath.resolve("describe-cluster-nodes.log"), cmdClient.exec(false, false, "describe", "nodes").out());
Expand All @@ -114,7 +115,7 @@ private static void saveClusterState(Path logpath) throws IOException {

kube.getClient().namespaces().withLabel(TestConstants.LOG_COLLECT_LABEL).list().getItems().forEach(ns -> {
LOGGER.debug("Listing pods in {}", ns.getMetadata().getName());
kube.listPods(ns.getMetadata().getName()).forEach(pod -> {
kube.getClient().pods().inNamespace(ns.getMetadata().getName()).list().getItems().forEach(pod -> {
writeLogsFromPods(logpath, pod);
writePodsDescription(logpath, pod);
});
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/io/odh/test/framework/manager/ResourceCondition.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/main/java/io/odh/test/framework/manager/ResourceItem.java

This file was deleted.

Loading

0 comments on commit d87259c

Please sign in to comment.