Skip to content

Commit

Permalink
Fix odh default constants + store logs from containers
Browse files Browse the repository at this point in the history
  • Loading branch information
kornys committed Dec 13, 2023
1 parent 60807e9 commit 290c4c0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/odh/test/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class Environment {
/**
* Set values
*/
public static final String PRODUCT = getOrDefault(PRODUCT_ENV, PRODUCT_DEFAULT);
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);
Expand All @@ -74,7 +75,6 @@ public class Environment {
public static final String OLM_OPERATOR_VERSION = getOrDefault(OLM_OPERATOR_VERSION_ENV, OdhConstants.OLM_OPERATOR_VERSION);

public static final String OPERATOR_INSTALL_TYPE = getOrDefault(OPERATOR_INSTALL_TYPE_ENV, InstallTypes.BUNDLE.toString());
public static final String PRODUCT = getOrDefault(PRODUCT_ENV, PRODUCT_DEFAULT);

public static final Path LOG_DIR = getOrDefault(LOG_DIR_ENV, Paths::get, Paths.get(USER_PATH, "target", "logs")).resolve("test-run-" + DATE_FORMAT.format(LocalDateTime.now()));

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/io/odh/test/OdhConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
*/
package io.odh.test;

import java.util.Objects;

public class OdhConstants {
private OdhConstants() { }

// ODH
private static final String ODH_CONTROLLERS_NAMESPACE = "opendatahub";
private static final String ODH_DASHBOARD_ROUTE_NAME = "odh-dashboard";
private static final String ODH_DASHBOARD_CONTROLLER = "odh-dashboard";

private static final String ODH_BUNDLE_OPERATOR_NAME = "opendatahub-operator-system";

// ODH OLM
private static final String ODH_OLM_OPERATOR_NAME = "opendatahub-operator";
private static final String ODH_OLM_OPERATOR_NAMESPACE = "openshift-operators";
Expand Down Expand Up @@ -47,6 +53,7 @@ public class OdhConstants {
public static final String CONTROLLERS_NAMESPACE = getOdhOrRhoai(ODH_CONTROLLERS_NAMESPACE, RHOAI_CONTROLLERS_NAMESPACE);
public static final String DASHBOARD_ROUTE_NAME = getOdhOrRhoai(ODH_DASHBOARD_ROUTE_NAME, RHOAI_DASHBOARD_ROUTE_NAME);
public static final String DASHBOARD_CONTROLLER = getOdhOrRhoai(ODH_DASHBOARD_CONTROLLER, RHOAI_DASHBOARD_CONTROLLER);
public static final String BUNDLE_OPERATOR_NAMESPACE = getOdhOrRhoai(ODH_BUNDLE_OPERATOR_NAME, RHOAI_OLM_OPERATOR_NAME);
// OLM env variables
public static final String OLM_OPERATOR_NAME = getOdhOrRhoai(ODH_OLM_OPERATOR_NAME, RHOAI_OLM_OPERATOR_NAME);
public static final String OLM_OPERATOR_NAMESPACE = getOdhOrRhoai(ODH_OLM_OPERATOR_NAMESPACE, RHOAI_OLM_OPERATOR_NAMESPACE);
Expand All @@ -58,7 +65,7 @@ public class OdhConstants {

private static <T> T getOdhOrRhoai(T odhValue, T rhoaiValue) {
T returnValue = odhValue;
if (Environment.PRODUCT != Environment.PRODUCT_DEFAULT) {
if (!Objects.equals(Environment.PRODUCT, Environment.PRODUCT_DEFAULT)) {
returnValue = rhoaiValue;
}
return returnValue;
Expand Down
36 changes: 27 additions & 9 deletions src/main/java/io/odh/test/framework/logs/LogCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/
package io.odh.test.framework.logs;

import io.fabric8.kubernetes.api.model.PodStatus;
import io.odh.test.Environment;
import io.odh.test.OdhConstants;
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 org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
Expand All @@ -16,7 +17,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

public class LogCollector {
private static final Logger LOGGER = LoggerFactory.getLogger(LogCollector.class);
Expand All @@ -25,13 +25,6 @@ public class LogCollector {
* Calls storing cluster info for connected cluster
*/
public static void saveKubernetesState(ExtensionContext extensionContext, Throwable throwable) throws Throwable {
LOGGER.warn("Printing all pods on cluster");
ResourceManager.getClient().getClient().pods().inAnyNamespace().list().getItems().forEach(p ->
LOGGER.info("Pod: {} in ns: {} with phase: {}",
p.getMetadata().getName(),
p.getMetadata().getNamespace(),
Optional.ofNullable(p.getStatus()).map(PodStatus::getPhase).orElse("null")));

Path logPath = TestUtils.getLogPath(Environment.LOG_DIR.resolve("failedTest").toString(), extensionContext);
Files.createDirectories(logPath);
LOGGER.info("Storing cluster info into {}", logPath);
Expand All @@ -44,11 +37,36 @@ public static void saveKubernetesState(ExtensionContext extensionContext, Throwa
}

private static void saveClusterState(Path logpath) throws IOException {
KubeClient kube = ResourceManager.getClient();
KubeCmdClient cmdClient = ResourceManager.getKubeCmdClient();
Files.writeString(logpath.resolve("describe-cluster-nodes.log"), cmdClient.exec(false, false, "describe", "nodes").out());
Files.writeString(logpath.resolve("all-events.log"), cmdClient.exec(false, false, "get", "events", "--all-namespaces").out());
Files.writeString(logpath.resolve("pvs.log"), cmdClient.exec(false, false, "describe", "pv").out());
Files.writeString(logpath.resolve("dsc.yml"), cmdClient.exec(false, false, "get", "dsc", "-o", "yaml").out());
Files.writeString(logpath.resolve("dsci.yml"), cmdClient.exec(false, false, "get", "dsci", "-o", "yaml").out());
kube.listPodsByPrefixInName(OdhConstants.BUNDLE_OPERATOR_NAMESPACE, "opendatahub-operator-controller-manager").forEach(pod -> {
try {
LOGGER.debug("Get logs from pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
Files.writeString(logpath.resolve(pod.getMetadata().getName() + ".log"), kube.getLogs(OdhConstants.BUNDLE_OPERATOR_NAMESPACE, pod.getMetadata().getName()));
} catch (IOException e) {
LOGGER.warn("Cannot get logs for pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
}
});
kube.listPodsByPrefixInName(OdhConstants.OLM_OPERATOR_NAMESPACE, "opendatahub").forEach(pod -> {
try {
LOGGER.debug("Get logs from pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
Files.writeString(logpath.resolve(pod.getMetadata().getName() + ".log"), kube.getLogs(OdhConstants.OLM_OPERATOR_NAMESPACE, pod.getMetadata().getName()));
} catch (IOException e) {
LOGGER.warn("Cannot get logs for pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
}
});
kube.listPods(OdhConstants.CONTROLLERS_NAMESPACE).forEach(pod -> {
try {
LOGGER.debug("Get logs from pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
Files.writeString(logpath.resolve(pod.getMetadata().getName() + ".log"), kube.getLogs(OdhConstants.CONTROLLERS_NAMESPACE, pod.getMetadata().getName()));
} catch (IOException e) {
LOGGER.warn("Cannot get logs for pod {}/{}", pod.getMetadata().getNamespace(), pod.getMetadata().getName());
}
});
}
}
3 changes: 0 additions & 3 deletions src/test/java/io/odh/test/e2e/Abstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
import io.odh.test.framework.listeners.TestVisualSeparator;
import io.odh.test.framework.manager.ResourceManager;
import io.odh.test.framework.listeners.TestExceptionCallbackListener;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;

@DisplayNameGeneration(DisplayNameGenerator.IndicativeSentences.class)
@ExtendWith(TestExceptionCallbackListener.class)
@ExtendWith(ResourceManagerContextHandler.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand Down

0 comments on commit 290c4c0

Please sign in to comment.