Skip to content

Commit af0a38e

Browse files
committed
Test Instascale machine set functionality
Co-authored-by: Karel Suta [email protected] Co-authored-by: Fiona Waters [email protected]
1 parent 2ed79fb commit af0a38e

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
. "github.com/project-codeflare/codeflare-operator/test/support"
10+
)
11+
12+
func TestInstascaleMachineSet(t *testing.T) {
13+
test := With(t)
14+
test.T().Parallel()
15+
16+
// TODO only run if using machine sets
17+
18+
namespace := test.NewTestNamespace()
19+
20+
// Test configuration
21+
testConfigData := map[string][]byte{
22+
// pip requirements
23+
"requirements.txt": ReadFile(test, "mnist_pip_requirements.txt"),
24+
// MNIST training script
25+
"mnist.py": ReadFile(test, "mnist.py"),
26+
}
27+
cm := CreateConfigMap(test, namespace.Name, testConfigData)
28+
29+
// look for machine set with aw name - expect to find it
30+
test.Expect(MachineSets(test)).Should(ContainElement(WithTransform(MachineSetId, Equal("test-instascale"))))
31+
// look for machine set replica - expect not to find it
32+
test.Expect(MachineExists(test)).Should(BeFalse())
33+
34+
// // Setup batch job and AppWrapper
35+
_, aw, err := createInstaScaleJobAppWrapper(test, namespace, cm)
36+
test.Expect(err).NotTo(HaveOccurred())
37+
38+
// assert that AppWrapper goes to "Running" state
39+
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutGpuProvisioning).
40+
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive)))
41+
42+
//look for machine set replica - expect to find it
43+
test.Eventually(MachineExists(test), TestTimeoutLong).Should(BeTrue())
44+
45+
// assert that the AppWrapper goes to "Completed" state
46+
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutShort).
47+
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateCompleted)))
48+
49+
// look for machine set replica - expect not to find it
50+
test.Eventually(MachineExists(test), TestTimeoutLong).Should(BeFalse())
51+
52+
}

test/support/client.go

+13
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ import (
2626
"k8s.io/client-go/tools/clientcmd"
2727

2828
imagev1 "github.com/openshift/client-go/image/clientset/versioned"
29+
machinev1 "github.com/openshift/client-go/machine/clientset/versioned"
2930
routev1 "github.com/openshift/client-go/route/clientset/versioned"
3031
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
3132
// to ensure that exec-entrypoint and run can make use of them.
3233
)
3334

3435
type Client interface {
3536
Core() kubernetes.Interface
37+
Machine() machinev1.Interface
3638
Route() routev1.Interface
3739
Image() imagev1.Interface
3840
MCAD() mcadclient.Interface
@@ -42,6 +44,7 @@ type Client interface {
4244

4345
type testClient struct {
4446
core kubernetes.Interface
47+
machine machinev1.Interface
4548
route routev1.Interface
4649
image imagev1.Interface
4750
mcad mcadclient.Interface
@@ -55,6 +58,10 @@ func (t *testClient) Core() kubernetes.Interface {
5558
return t.core
5659
}
5760

61+
func (t *testClient) Machine() machinev1.Interface {
62+
return t.machine
63+
}
64+
5865
func (t *testClient) Route() routev1.Interface {
5966
return t.route
6067
}
@@ -88,6 +95,11 @@ func newTestClient() (Client, error) {
8895
return nil, err
8996
}
9097

98+
machineClient, err := machinev1.NewForConfig(cfg)
99+
if err != nil {
100+
return nil, err
101+
}
102+
91103
routeClient, err := routev1.NewForConfig(cfg)
92104
if err != nil {
93105
return nil, err
@@ -115,6 +127,7 @@ func newTestClient() (Client, error) {
115127

116128
return &testClient{
117129
core: kubeClient,
130+
machine: machineClient,
118131
route: routeClient,
119132
image: imageClient,
120133
mcad: mcadClient,

test/support/machinesets.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package support
2+
3+
import (
4+
"github.com/onsi/gomega"
5+
6+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
8+
v1beta1 "github.com/openshift/api/machine/v1beta1"
9+
)
10+
11+
func MachineSets(t Test) ([]v1beta1.MachineSet, error) {
12+
ms, err := t.Client().Machine().MachineV1beta1().MachineSets("openshift-machine-api").List(t.Ctx(), v1.ListOptions{})
13+
t.Expect(err).NotTo(gomega.HaveOccurred())
14+
return ms.Items, err
15+
}
16+
17+
func MachineExists(t Test) (foundReplica bool) {
18+
machineSetList, err := MachineSets(t)
19+
t.Expect(err).NotTo(gomega.HaveOccurred())
20+
for _, ms := range machineSetList {
21+
if ms.Name == "test-instascale" && &ms.Status.AvailableReplicas == Ptr(int32(1)) {
22+
foundReplica = true
23+
}
24+
}
25+
return foundReplica
26+
}
27+
28+
func MachineSetId(machineSet v1beta1.MachineSet) string {
29+
return machineSet.Name
30+
}

0 commit comments

Comments
 (0)