Skip to content

Commit

Permalink
Add tests for continuous AI testing + Init tests for CRUD AI (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornys authored Nov 13, 2023
1 parent e35a01f commit ec954c4
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 48 deletions.
13 changes: 13 additions & 0 deletions src/main/java/io/odh/test/platform/KubeUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.odh.test.platform;


import io.opendatahub.datasciencecluster.v1.datascienceclusterstatus.Conditions;

import java.util.List;

public class KubeUtils {

public static Conditions getDscConditionByType(List<Conditions> conditions, String type) {
return conditions.stream().filter(c -> c.getType().equals(type)).findFirst().orElseGet(null);
}
}
6 changes: 1 addition & 5 deletions src/test/java/io/odh/test/e2e/Abstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class Abstract implements TestSeparator {
protected KubeClient kubeClient;
protected KubeClient kubeClient = new KubeClient(TestConstants.ODH_NAMESPACE);

@BeforeAll
void init() {
kubeClient = new KubeClient(TestConstants.ODH_NAMESPACE);
}
}
67 changes: 67 additions & 0 deletions src/test/java/io/odh/test/e2e/continuous/DataScienceClusterIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.continuous;

import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.odh.test.TestConstants;
import io.odh.test.e2e.Abstract;
import io.odh.test.platform.KubeUtils;
import io.opendatahub.datasciencecluster.v1.DataScienceCluster;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Codeflare;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Dashboard;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Datasciencepipelines;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Kserve;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Modelmeshserving;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Ray;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Trustyai;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Workbenches;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class DataScienceClusterIT extends Abstract {

private final String DS_PROJECT_NAME = "default";
MixedOperation<DataScienceCluster, KubernetesResourceList<DataScienceCluster>, Resource<DataScienceCluster>> cli;

@BeforeAll
void init() {
cli = kubeClient.dataScienceClusterClient();
}

@Test
void checkDataScienceClusterExists() {
DataScienceCluster cluster = cli.inNamespace(TestConstants.ODH_NAMESPACE).withName(DS_PROJECT_NAME).get();

assertEquals(Kserve.ManagementState.MANAGED, cluster.getSpec().getComponents().getKserve().getManagementState());
assertEquals(Codeflare.ManagementState.MANAGED, cluster.getSpec().getComponents().getCodeflare().getManagementState());
assertEquals(Dashboard.ManagementState.MANAGED, cluster.getSpec().getComponents().getDashboard().getManagementState());
assertEquals(Ray.ManagementState.MANAGED, cluster.getSpec().getComponents().getRay().getManagementState());
assertEquals(Modelmeshserving.ManagementState.MANAGED, cluster.getSpec().getComponents().getModelmeshserving().getManagementState());
assertEquals(Datasciencepipelines.ManagementState.MANAGED, cluster.getSpec().getComponents().getDatasciencepipelines().getManagementState());
assertEquals(Trustyai.ManagementState.MANAGED, cluster.getSpec().getComponents().getTrustyai().getManagementState());
assertEquals(Workbenches.ManagementState.MANAGED, cluster.getSpec().getComponents().getWorkbenches().getManagementState());
}

@Test
void checkDataScienceClusterStatus() {
DataScienceCluster cluster = cli.inNamespace(TestConstants.ODH_NAMESPACE).withName(DS_PROJECT_NAME).get();

assertEquals("Ready", cluster.getStatus().getPhase());
assertNull(cluster.getStatus().getErrorMessage());

assertEquals("True", KubeUtils.getDscConditionByType(cluster.getStatus().getConditions(), "dashboardReady").getStatus());
//assertEquals("True", KubeUtils.getDscConditionByType(cluster.getStatus().getConditions(), "workbenchesReady").getStatus());
//assertEquals("True", KubeUtils.getDscConditionByType(cluster.getStatus().getConditions(), "data-science-pipelines-operatorReady").getStatus());
//assertEquals("True", KubeUtils.getDscConditionByType(cluster.getStatus().getConditions(), "kserveReady").getStatus());
//assertEquals("True", KubeUtils.getDscConditionByType(cluster.getStatus().getConditions(), "codeflareReady").getStatus());
//assertEquals("True", KubeUtils.getDscConditionByType(cluster.getStatus().getConditions(), "model-meshReady").getStatus());
//assertEquals("True", KubeUtils.getDscConditionByType(cluster.getStatus().getConditions(), "trustyaiReady").getStatus());
}
}
43 changes: 0 additions & 43 deletions src/test/java/io/odh/test/e2e/deployed/DataScienceClusterIT.java

This file was deleted.

100 changes: 100 additions & 0 deletions src/test/java/io/odh/test/e2e/standard/DataScienceClusterIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.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.TestConstants;
import io.odh.test.e2e.Abstract;
import io.odh.test.platform.KubeUtils;
import io.opendatahub.datasciencecluster.v1.DataScienceCluster;
import io.opendatahub.datasciencecluster.v1.DataScienceClusterBuilder;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.ComponentsBuilder;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Codeflare;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.CodeflareBuilder;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Dashboard;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.DashboardBuilder;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Datasciencepipelines;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.DatasciencepipelinesBuilder;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Kserve;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.KserveBuilder;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Modelmeshserving;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Ray;
import io.opendatahub.datasciencecluster.v1.datascienceclusterspec.components.Trustyai;
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.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class DataScienceClusterIT extends Abstract {

private final String DS_PROJECT_NAME = "test-dsp";
private final String DS_PROJECT_NAMESPACE = "test-ns-ds";
MixedOperation<DataScienceCluster, KubernetesResourceList<DataScienceCluster>, Resource<DataScienceCluster>> cli;

@BeforeAll
void init() {
cli = kubeClient.dataScienceClusterClient();
}

@AfterAll
void clean() {
cli.inNamespace(DS_PROJECT_NAMESPACE).withName(DS_PROJECT_NAME).delete();
kubeClient.getClient().namespaces().withName(DS_PROJECT_NAMESPACE).delete();
}

@Test
void checkDataScienceClusterExists() {
if (!kubeClient.namespaceExists(DS_PROJECT_NAMESPACE)) {
kubeClient.getClient()
.namespaces()
.resource(new NamespaceBuilder().withNewMetadata().withName(DS_PROJECT_NAMESPACE).endMetadata().build())
.create();
}

DataScienceCluster c = new DataScienceClusterBuilder()
.withNewMetadata()
.withName("test-dsp")
.withNamespace("test-ns")
.endMetadata()
.withNewSpec()
.withComponents(
new ComponentsBuilder()
.withWorkbenches(
new WorkbenchesBuilder().withManagementState(Workbenches.ManagementState.MANAGED).build()
)
.withDashboard(
new DashboardBuilder().withManagementState(Dashboard.ManagementState.MANAGED).build()
)
.withKserve(
new KserveBuilder().withManagementState(Kserve.ManagementState.MANAGED).build()
)
.withCodeflare(
new CodeflareBuilder().withManagementState(Codeflare.ManagementState.MANAGED).build()
)
.withDatasciencepipelines(
new DatasciencepipelinesBuilder().withManagementState(Datasciencepipelines.ManagementState.MANAGED).build()
)
.build())
.endSpec()
.build();

cli.resource(c).create();

DataScienceCluster cluster = cli.inNamespace(DS_PROJECT_NAMESPACE).withName(DS_PROJECT_NAME).get();

assertEquals(Kserve.ManagementState.MANAGED, cluster.getSpec().getComponents().getKserve().getManagementState());
assertEquals(Codeflare.ManagementState.MANAGED, cluster.getSpec().getComponents().getCodeflare().getManagementState());
assertEquals(Dashboard.ManagementState.MANAGED, cluster.getSpec().getComponents().getDashboard().getManagementState());
assertEquals(Datasciencepipelines.ManagementState.MANAGED, cluster.getSpec().getComponents().getDatasciencepipelines().getManagementState());
assertEquals(Workbenches.ManagementState.MANAGED, cluster.getSpec().getComponents().getWorkbenches().getManagementState());
}
}

0 comments on commit ec954c4

Please sign in to comment.