/
inspection.go
63 lines (53 loc) · 2.07 KB
/
inspection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package e2e
import (
"context"
bmov1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/ptr"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
inspectAnnotation = "inspect.metal3.io"
)
type InspectionInput struct {
E2EConfig *clusterctl.E2EConfig
ClusterctlConfigPath string
BootstrapClusterProxy framework.ClusterProxy
Namespace string
SpecName string
}
// Inspection test request inspection on all the available BMH using annotation.
func inspection(ctx context.Context, inputGetter func() InspectionInput) {
Logf("Starting inspection tests")
input := inputGetter()
var (
numberOfWorkers = int(*input.E2EConfig.GetInt32PtrVariable("WORKER_MACHINE_COUNT"))
numberOfAvailableBMHs = 2 * numberOfWorkers
)
bootstrapClient := input.BootstrapClusterProxy.GetClient()
Logf("Request inspection for all Available BMHs via API")
availableBMHList := bmov1alpha1.BareMetalHostList{}
Expect(bootstrapClient.List(ctx, &availableBMHList, client.InNamespace(input.Namespace))).To(Succeed())
Logf("Request inspection for all Available BMHs via API")
for _, bmh := range availableBMHList.Items {
if bmh.Status.Provisioning.State == bmov1alpha1.StateAvailable {
AnnotateBmh(ctx, bootstrapClient, bmh, inspectAnnotation, ptr.To(""))
}
}
WaitForNumBmhInState(ctx, bmov1alpha1.StateInspecting, WaitForNumInput{
Client: bootstrapClient,
Options: []client.ListOption{client.InNamespace(input.Namespace)},
Replicas: numberOfAvailableBMHs,
Intervals: input.E2EConfig.GetIntervals(input.SpecName, "wait-bmh-inspecting"),
})
WaitForNumBmhInState(ctx, bmov1alpha1.StateAvailable, WaitForNumInput{
Client: bootstrapClient,
Options: []client.ListOption{client.InNamespace(input.Namespace)},
Replicas: numberOfAvailableBMHs,
Intervals: input.E2EConfig.GetIntervals(input.SpecName, "wait-bmh-available"),
})
By("INSPECTION TESTS PASSED!")
}