-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test Instascale machine set functionality #322
Changes from all commits
aa3026d
77e0f91
c8ec148
3e187a3
da8c04c
457c533
9ab7a79
ea9ee6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "github.com/project-codeflare/codeflare-operator/test/support" | ||
) | ||
|
||
func TestInstascaleMachineSet(t *testing.T) { | ||
test := With(t) | ||
test.T().Parallel() | ||
|
||
// skip test if not using machine sets | ||
clusterType := GetClusterType(test) | ||
if clusterType != OcpCluster { | ||
test.T().Skipf("Skipping test as not running on an OCP cluster, resolved cluster type: %s", clusterType) | ||
} | ||
|
||
namespace := test.NewTestNamespace() | ||
|
||
// Test configuration | ||
cm := CreateConfigMap(test, namespace.Name, map[string][]byte{ | ||
// pip requirements | ||
"requirements.txt": ReadFile(test, "mnist_pip_requirements.txt"), | ||
// MNIST training script | ||
"mnist.py": ReadFile(test, "mnist.py"), | ||
}) | ||
|
||
// // Setup batch job and AppWrapper | ||
aw := instaScaleJobAppWrapper(test, namespace, cm) | ||
|
||
// look for machine set with aw name - expect to find it | ||
test.Expect(GetMachineSets(test)).Should(ContainElement(WithTransform(MachineSetId, Equal(aw.Name)))) | ||
// look for machine belonging to the machine set, there should be none | ||
test.Expect(GetMachines(test, aw.Name)).Should(BeEmpty()) | ||
|
||
// apply AppWrapper to cluster | ||
_, err := test.Client().MCAD().WorkloadV1beta1().AppWrappers(namespace.Name).Create(test.Ctx(), aw, metav1.CreateOptions{}) | ||
test.Expect(err).NotTo(HaveOccurred()) | ||
|
||
// assert that AppWrapper goes to "Running" state | ||
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutGpuProvisioning). | ||
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive))) | ||
|
||
// look for machine belonging to the machine set - expect to find it | ||
test.Eventually(Machines(test, aw.Name), TestTimeoutLong).Should(HaveLen(1)) | ||
|
||
// assert that the AppWrapper goes to "Completed" state | ||
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutMedium). | ||
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateCompleted))) | ||
|
||
// look for machine belonging to the machine set - there should be none | ||
test.Eventually(Machines(test, aw.Name), TestTimeoutLong).Should(BeEmpty()) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package support | ||
|
||
import ( | ||
"github.com/onsi/gomega" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
machinev1beta1 "github.com/openshift/api/machine/v1beta1" | ||
) | ||
|
||
func GetMachineSets(t Test) ([]machinev1beta1.MachineSet, error) { | ||
ms, err := t.Client().Machine().MachineV1beta1().MachineSets("openshift-machine-api").List(t.Ctx(), metav1.ListOptions{}) | ||
t.Expect(err).NotTo(gomega.HaveOccurred()) | ||
return ms.Items, err | ||
} | ||
|
||
func Machines(t Test, machineSetName string) func(g gomega.Gomega) []machinev1beta1.Machine { | ||
return func(g gomega.Gomega) []machinev1beta1.Machine { | ||
machine, err := t.Client().Machine().MachineV1beta1().Machines("openshift-machine-api").List(t.Ctx(), metav1.ListOptions{LabelSelector: "machine.openshift.io/cluster-api-machineset=" + machineSetName}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could passing the label selector as argument instead be useful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if we can access the machine label easily in the test to pass it in. Could this work, or what would be the benefit of passing it as an argument? maybe it can be one variable instead of 2 also since these shouldn't change.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, probably bette to keep it that way for now. |
||
g.Expect(err).NotTo(gomega.HaveOccurred()) | ||
return machine.Items | ||
} | ||
} | ||
|
||
func GetMachines(t Test, machineSetName string) []machinev1beta1.Machine { | ||
t.T().Helper() | ||
return Machines(t, machineSetName)(t) | ||
} | ||
|
||
func MachineSetId(machineSet machinev1beta1.MachineSet) string { | ||
return machineSet.Name | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK to have
openshift-machine-api
hard-coded?