Skip to content

Commit

Permalink
Fixes v2
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Stejskal <[email protected]>
  • Loading branch information
Frawless committed Dec 11, 2023
1 parent debf524 commit db27aee
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/odh/test/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class TestConstants {
public static final String ODH_NAMESPACE = "opendatahub";
public static final String ODH_DASHBOARD_ROUTE_NAME = "odh-dashboard";
public static final String DEFAULT_NAMESPACE = "default";

public static final String SUBSCRIPTION = "Subscription";
Expand All @@ -20,7 +21,7 @@ public class TestConstants {
public static final long GLOBAL_POLL_INTERVAL_MEDIUM = Duration.ofSeconds(5).toMillis();
public static final long GLOBAL_POLL_INTERVAL_SHORT = Duration.ofSeconds(1).toMillis();
public static final long GLOBAL_TIMEOUT = Duration.ofMinutes(5).toMillis();
public static final long GLOBAL_STABILITY_TIME = Duration.ofMinutes(2).toSeconds();
public static final long GLOBAL_STABILITY_TIME = Duration.ofMinutes(1).toSeconds();

private TestConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.openshift.client.OpenShiftClient;
import io.odh.test.TestConstants;
import io.odh.test.TestUtils;
import io.odh.test.framework.manager.ResourceManager;
import io.odh.test.framework.manager.ResourceType;
Expand Down Expand Up @@ -58,6 +60,13 @@ public static Notebook loadDefaultNotebook(String namespace, String name) throws
InputStream is = TestUtils.getFileFromResourceAsStream(NOTEBOOK_TEMPLATE_PATH);
String notebookString = IOUtils.toString(is, "UTF-8");
notebookString = notebookString.replace("my-project", namespace).replace("my-workbench", name);
// Set new Route url
String routeHost = ResourceManager.getClient().getClient().adapt(OpenShiftClient.class).routes().inNamespace(TestConstants.ODH_NAMESPACE).withName(TestConstants.ODH_DASHBOARD_ROUTE_NAME).get().getSpec().getHost();
notebookString = notebookString.replace("odh_dashboard_route", "https://" + routeHost);
// Set correct username
String username = ResourceManager.getKubeCmdClient().getUsername().strip();
notebookString = notebookString.replace("odh_user", username);

return TestUtils.configFromYaml(notebookString, Notebook.class);
}
}
12 changes: 6 additions & 6 deletions src/main/java/io/odh/test/platform/KubeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,15 @@ public InstallPlan getInstallPlan(String namespaceName, String installPlanName)
}

public void approveInstallPlan(String namespaceName, String installPlanName) throws InterruptedException {
InstallPlan installPlan = new InstallPlanBuilder(this.getInstallPlan(namespaceName, installPlanName))
.editSpec()
.withApproved()
.endSpec()
.build();

LOGGER.debug("Approving InstallPlan {}", installPlanName);
TestUtils.waitFor("InstallPlan approval", TestConstants.GLOBAL_POLL_INTERVAL_SHORT, 15_000, () -> {
try {
InstallPlan installPlan = new InstallPlanBuilder(this.getInstallPlan(namespaceName, installPlanName))
.editSpec()
.withApproved()
.endSpec()
.build();

client.adapt(OpenShiftClient.class).operatorHub().installPlans().inNamespace(namespaceName).withName(installPlanName).patch(installPlan);
return true;
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,4 @@ public K process(Map<String, String> parameters, String file, Consumer<String> c
c.accept(exec.out());
return (K) this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,6 @@ default String logs(String pod) {
String cmd();

K process(Map<String, String> domain, String file, Consumer<String> c);

String getUsername();
}
6 changes: 6 additions & 0 deletions src/main/java/io/odh/test/platform/cmdClient/Kubectl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ public String defaultOlmNamespace() {
public String cmd() {
return KUBECTL;
}

@Override
public String getUsername() {
// TODO - implement this!
return null;
}
}
5 changes: 5 additions & 0 deletions src/main/java/io/odh/test/platform/cmdClient/Oc.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ public Oc newApp(String template, Map<String, String> params) {
public String cmd() {
return OC;
}

@Override
public String getUsername() {
return Exec.exec(cmd(), "whoami").out();
}
}
13 changes: 8 additions & 5 deletions src/main/java/io/odh/test/utils/PodUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,23 @@ public static void verifyThatPodsAreStable(String namespaceName, LabelSelector l
int[] stabilityCounter = {0};
String phase = "Running";

List<Pod> runningPods = ResourceManager.getClient().listPods(namespaceName, labelSelector);

TestUtils.waitFor(String.format("Pods in namespace '%s' with LabelSelector %s stability in phase %s", namespaceName, labelSelector, phase), TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT,
() -> {
List<Pod> runningPods = ResourceManager.getClient().listPods(namespaceName, labelSelector);
List<Pod> actualPods = runningPods.stream().map(p -> ResourceManager.getClient().getPod(namespaceName, p.getMetadata().getName())).toList();
LOGGER.debug("Working with the following pods: {}", actualPods.stream().map(p -> p.getMetadata().getName()).toList());

for (Pod pod : actualPods) {
if (pod == null) {
continue;
}
if (pod.getStatus().getPhase().equals(phase)) {
LOGGER.info("Pod: {}/{} is in the {} state. Remaining seconds Pod to be stable {}",
LOGGER.debug("Pod: {}/{} is in the {} state. Remaining seconds for Pod to be stable {}",
namespaceName, pod.getMetadata().getName(), pod.getStatus().getPhase(),
TestConstants.GLOBAL_STABILITY_TIME - stabilityCounter[0]);
} else {
LOGGER.info("Pod: {}/{} is not stable in phase following phase {} reset the stability counter from {} to {}",
namespaceName, pod.getMetadata().getName(), pod.getStatus().getPhase(), stabilityCounter[0], 0);
LOGGER.warn("Pod: {}/{} is not stable in phase following phase {} ({}) reset the stability counter from {}s to {}s",
namespaceName, pod.getMetadata().getName(), pod.getStatus().getPhase(), phase, stabilityCounter[0], 0);
stabilityCounter[0] = 0;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/notebook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
--ServerApp.password=''
--ServerApp.base_url=/notebook/my-project/my-workbench
--ServerApp.quit_button=False
--ServerApp.tornado_settings={"user":"","hub_host":"odh_dashboard_route","hub_prefix":"/projects/my-project"}
--ServerApp.tornado_settings={"user":"odh_user","hub_host":"odh_dashboard_route","hub_prefix":"/projects/my-project"}
- name: JUPYTER_IMAGE
value: image-registry.openshift-image-registry.svc:5000/opendatahub/jupyter-pytorch-notebook:2023.2
image: image-registry.openshift-image-registry.svc:5000/opendatahub/jupyter-pytorch-notebook:2023.2
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/io/odh/test/e2e/upgrade/OlmUpgradeST.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.odh.test.utils.DeploymentUtils;
import io.odh.test.utils.PodUtils;
import io.odh.test.utils.UpgradeUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand All @@ -29,9 +30,10 @@ public class OlmUpgradeST extends UpgradeAbstract {
private static final Logger LOGGER = LoggerFactory.getLogger(OlmUpgradeST.class);
private static final String DS_PROJECT_NAME = "upgrade-dsc";

private final String startingVersion = "2.3.0";
private final String startingVersion = "2.4.0";

@Test
@Disabled("Tested only for upgrades from 2.4+ so we are waiting for 2.5 release")
void testUpgradeOlm() throws IOException, InterruptedException {
String ntbName = "test-odh-notebook";
String ntbNamespace = "test-odh-notebook-upgrade";
Expand Down

0 comments on commit db27aee

Please sign in to comment.