Skip to content

Commit c8ec148

Browse files
sutaakarFiona-Waters
authored andcommitted
Use generic function to retrieve machines
1 parent 77e0f91 commit c8ec148

File tree

3 files changed

+50
-48
lines changed

3 files changed

+50
-48
lines changed

test/e2e/instascale_machineset_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func TestInstascaleMachineSet(t *testing.T) {
3232
})
3333

3434
// look for machine set with aw name - expect to find it
35-
test.Expect(MachineSets(test)).Should(ContainElement(WithTransform(MachineSetId, Equal("test-instascale"))))
36-
// look for machine set replica - expect not to find it
37-
test.Expect(MachineExists(test)).Should(BeFalse())
35+
test.Expect(GetMachineSets(test)).Should(ContainElement(WithTransform(MachineSetId, Equal("test-instascale"))))
36+
// look for machine belonging to the machine set, there should be none
37+
test.Expect(GetMachines(test, "test-instascale")).Should(BeEmpty())
3838

3939
// // Setup batch job and AppWrapper
4040
_, aw, err := createInstaScaleJobAppWrapper(test, namespace, cm)
@@ -44,14 +44,14 @@ func TestInstascaleMachineSet(t *testing.T) {
4444
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutGpuProvisioning).
4545
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateActive)))
4646

47-
//look for machine set replica - expect to find it
48-
test.Eventually(MachineExists(test), TestTimeoutLong).Should(BeTrue())
47+
// look for machine belonging to the machine set - expect to find it
48+
test.Eventually(Machines(test, "test-instascale"), TestTimeoutLong).Should(HaveLen(1))
4949

5050
// assert that the AppWrapper goes to "Completed" state
51-
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutShort).
51+
test.Eventually(AppWrapper(test, namespace, aw.Name), TestTimeoutMedium).
5252
Should(WithTransform(AppWrapperState, Equal(mcadv1beta1.AppWrapperStateCompleted)))
5353

54-
// look for machine set replica - expect not to find it
55-
test.Eventually(MachineExists(test), TestTimeoutLong).Should(BeFalse())
54+
// look for machine belonging to the machine set - there should be none
55+
test.Eventually(Machines(test, "test-instascale"), TestTimeoutLong).Should(BeEmpty())
5656

5757
}

test/support/machine.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package support
2+
3+
import (
4+
"github.com/onsi/gomega"
5+
6+
"k8s.io/apimachinery/pkg/api/errors"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
9+
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
10+
)
11+
12+
func GetMachineSets(t Test) ([]machinev1beta1.MachineSet, error) {
13+
ms, err := t.Client().Machine().MachineV1beta1().MachineSets("openshift-machine-api").List(t.Ctx(), metav1.ListOptions{})
14+
t.Expect(err).NotTo(gomega.HaveOccurred())
15+
return ms.Items, err
16+
}
17+
18+
func Machines(t Test, machineSetName string) func(g gomega.Gomega) []machinev1beta1.Machine {
19+
return func(g gomega.Gomega) []machinev1beta1.Machine {
20+
machine, err := t.Client().Machine().MachineV1beta1().Machines("openshift-machine-api").List(t.Ctx(), metav1.ListOptions{LabelSelector: "machine.openshift.io/cluster-api-machineset=" + machineSetName})
21+
g.Expect(err).NotTo(gomega.HaveOccurred())
22+
return machine.Items
23+
}
24+
}
25+
26+
func GetMachines(t Test, machineSetName string) []machinev1beta1.Machine {
27+
t.T().Helper()
28+
return Machines(t, machineSetName)(t)
29+
}
30+
31+
func MachineSetId(machineSet machinev1beta1.MachineSet) string {
32+
return machineSet.Name
33+
}
34+
35+
func MachineSetsExist(t Test) (bool, error) {
36+
ms, err := GetMachineSets(t)
37+
if err != nil && errors.IsNotFound(err) {
38+
return false, err
39+
}
40+
t.Expect(err).NotTo(gomega.HaveOccurred())
41+
return ms != nil, err
42+
}

test/support/machinesets.go

-40
This file was deleted.

0 commit comments

Comments
 (0)