Skip to content

Commit ceb4e78

Browse files
committed
instascale hypershift/nodepool e2e test
1 parent 06d724f commit ceb4e78

File tree

3 files changed

+93
-6
lines changed

3 files changed

+93
-6
lines changed

test/e2e/instascale_nodepool_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package e2e
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/gomega"
7+
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
8+
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
11+
. "github.com/project-codeflare/codeflare-operator/test/support"
12+
)
13+
14+
func TestInstascaleNodepool(t *testing.T) {
15+
16+
test := With(t)
17+
test.T().Parallel()
18+
19+
clusterType := GetClusterType(test)
20+
if clusterType != HypershiftCluster {
21+
test.T().Skipf("Skipping test as not running on an Hypershift cluster, resolved cluster type: %s", clusterType)
22+
}
23+
24+
namespace := test.NewTestNamespace()
25+
26+
// Test configuration
27+
cm := CreateConfigMap(test, namespace.Name, map[string][]byte{
28+
// pip requirements
29+
"requirements.txt": ReadFile(test, "mnist_pip_requirements.txt"),
30+
// MNIST training script
31+
"mnist.py": ReadFile(test, "mnist.py"),
32+
})
33+
34+
//create OCM connection
35+
connection := CreateOCMConnection(test)
36+
defer connection.Close()
37+
38+
// check existing cluster resources
39+
// look for node pool with aw name - expect not to find it
40+
test.Expect(GetNodePools(test, connection)).
41+
ShouldNot(ContainElement(WithTransform(NodePoolId, Equal("test-instascale-g4dn-xlarge"))))
42+
43+
// Setup batch job and AppWrapper
44+
aw := instaScaleJobAppWrapper(test, namespace, cm)
45+
46+
// apply AppWrapper to cluster
47+
_, err := test.Client().MCAD().WorkloadV1beta1().AppWrappers(namespace.Name).Create(test.Ctx(), aw, metav1.CreateOptions{})
48+
test.Expect(err).NotTo(HaveOccurred())
49+
test.T().Logf("AppWrapper created successfully %s/%s", aw.Namespace, aw.Name)
50+
51+
// assert that AppWrapper goes to "Running" state
52+
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutGpuProvisioning).
53+
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive)))
54+
55+
// look for node pool with aw name - expect to find it
56+
test.Eventually(NodePools(test, connection), TestTimeoutLong).
57+
Should(ContainElement(WithTransform(NodePoolId, Equal("test-instascale-g4dn-xlarge"))))
58+
59+
// assert that the AppWrapper goes to "Completed" state
60+
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutShort).
61+
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateCompleted)))
62+
63+
// look for node pool with aw name - expect not to find it
64+
test.Eventually(NodePools(test, connection), TestTimeoutLong).
65+
ShouldNot(ContainElement(WithTransform(NodePoolId, Equal("test-instascale-g4dn-xlarge"))))
66+
67+
}

test/support/environment.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ const (
3636
// The namespace where a secret containing InstaScale OCM token is stored and the secret name.
3737
InstaScaleOcmSecret = "INSTASCALE_OCM_SECRET"
3838

39-
// Cluster ID for OSD cluster used in tests, used for testing InstaScale
40-
OsdClusterID = "CLUSTERID"
39+
// Cluster ID for OSD and OCP clusters used in tests, used for testing InstaScale
40+
ClusterID = "CLUSTERID"
4141

4242
// Type of cluster test is run on
4343
ClusterTypeEnvVar = "CLUSTER_TYPE"
@@ -73,8 +73,8 @@ func GetInstascaleOcmSecret() (string, string) {
7373
return res[0], res[1]
7474
}
7575

76-
func GetOsdClusterId() (string, bool) {
77-
return os.LookupEnv(OsdClusterID)
76+
func GetClusterId() (string, bool) {
77+
return os.LookupEnv(ClusterID)
7878
}
7979

8080
func GetClusterType(t Test) ClusterType {

test/support/ocm.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func buildOCMConnection(secret string) (*ocmsdk.Connection, error) {
5454
}
5555

5656
func MachinePools(t Test, connection *ocmsdk.Connection) func(g gomega.Gomega) []*cmv1.MachinePool {
57-
osdClusterId, found := GetOsdClusterId()
57+
clusterId, found := GetClusterId()
5858
t.Expect(found).To(gomega.BeTrue(), "OSD cluster id not found, please configure environment properly")
5959

6060
return func(g gomega.Gomega) []*cmv1.MachinePool {
61-
machinePoolsListResponse, err := connection.ClustersMgmt().V1().Clusters().Cluster(osdClusterId).MachinePools().List().Send()
61+
machinePoolsListResponse, err := connection.ClustersMgmt().V1().Clusters().Cluster(clusterId).MachinePools().List().Send()
6262
g.Expect(err).NotTo(gomega.HaveOccurred())
6363
return machinePoolsListResponse.Items().Slice()
6464
}
@@ -72,3 +72,23 @@ func GetMachinePools(t Test, connection *ocmsdk.Connection) []*cmv1.MachinePool
7272
func MachinePoolId(machinePool *cmv1.MachinePool) string {
7373
return machinePool.ID()
7474
}
75+
76+
func NodePools(t Test, connection *ocmsdk.Connection) func(g gomega.Gomega) []*cmv1.NodePool {
77+
clusterId, found := GetClusterId()
78+
t.Expect(found).To(gomega.BeTrue(), "Cluster id not found, please configure environment properly")
79+
80+
return func(g gomega.Gomega) []*cmv1.NodePool {
81+
nodePoolsListResponse, err := connection.ClustersMgmt().V1().Clusters().Cluster(clusterId).NodePools().List().Send()
82+
g.Expect(err).NotTo(gomega.HaveOccurred())
83+
return nodePoolsListResponse.Items().Slice()
84+
}
85+
}
86+
87+
func GetNodePools(t Test, connection *ocmsdk.Connection) []*cmv1.NodePool {
88+
t.T().Helper()
89+
return NodePools(t, connection)(t)
90+
}
91+
92+
func NodePoolId(nodePool *cmv1.NodePool) string {
93+
return nodePool.ID()
94+
}

0 commit comments

Comments
 (0)