Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions test/extended/baremetal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"sync"

g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
Expand All @@ -16,17 +17,48 @@ import (
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
)

var (
clusterInfraMu sync.Mutex
clusterInfra *configv1.Infrastructure
clusterInfraFetched bool
)

// clusterInfrastructure returns the cluster Infrastructure object. A successful fetch is cached for
// the rest of the process; if Get fails, nothing is cached and the next call retries.
func clusterInfrastructure(oc *exutil.CLI) (*configv1.Infrastructure, error) {
clusterInfraMu.Lock()
defer clusterInfraMu.Unlock()
if clusterInfraFetched {
return clusterInfra, nil
}
infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(
context.Background(), "cluster", metav1.GetOptions{})
if err == nil {
clusterInfra = infra
clusterInfraFetched = true
}
return infra, err
}

func skipIfNotBaremetal(oc *exutil.CLI) {
g.By("checking platform type")

infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{})
infra, err := clusterInfrastructure(oc)
o.Expect(err).NotTo(o.HaveOccurred())

if infra.Status.PlatformStatus.Type != configv1.BareMetalPlatformType {
e2eskipper.Skipf("No baremetal platform detected")
}
}

func skipIfTwoNode(oc *exutil.CLI) {
infra, err := clusterInfrastructure(oc)
o.Expect(err).NotTo(o.HaveOccurred())
if infra.Status.ControlPlaneTopology == configv1.DualReplicaTopologyMode {
e2eskipper.Skipf("This test does not apply to two-node")
}
}

// Starting from 4.10, metal3 resources could be created in the vSphere, OpenStack and None
// Platforms in addition to the Baremetal Platform.
// Starting from 4.12, metal3 resources could be created in the AWS Platform too.
Expand All @@ -35,7 +67,7 @@ func skipIfNotBaremetal(oc *exutil.CLI) {
func skipIfUnsupportedPlatformOrConfig(oc *exutil.CLI, dc dynamic.Interface) {
g.By("checking supported platforms")

infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{})
infra, err := clusterInfrastructure(oc)
o.Expect(err).NotTo(o.HaveOccurred())

switch infra.Status.PlatformStatus.Type {
Expand Down
9 changes: 8 additions & 1 deletion test/extended/baremetal/high_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,20 @@ var _ = g.Describe("[sig-installer][Feature:baremetal][Serial] Baremetal platfor
func checkMetal3DeploymentHealthy(oc *exutil.CLI) {
dc := oc.AdminDynamicClient()
bmc := baremetalClient(dc)
operationalStatus := "OK"
infra, err := clusterInfrastructure(oc)
o.Expect(err).NotTo(o.HaveOccurred())

if infra.Status.ControlPlaneTopology == configv1.DualReplicaTopologyMode {
operationalStatus = "detached"
}

hosts, err := bmc.List(context.Background(), v1.ListOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(hosts.Items).ToNot(o.BeEmpty())

for _, h := range hosts.Items {
expectStringField(h, "baremetalhost", "status.operationalStatus").To(o.BeEquivalentTo("OK"))
expectStringField(h, "baremetalhost", "status.operationalStatus").To(o.BeEquivalentTo(operationalStatus))
expectStringField(h, "baremetalhost", "status.provisioning.state").To(o.Or(o.BeEquivalentTo("provisioned"), o.BeEquivalentTo("externally provisioned")))
expectBoolField(h, "baremetalhost", "spec.online").To(o.BeTrue())
}
Expand Down
1 change: 1 addition & 0 deletions test/extended/baremetal/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ var _ = g.Describe("[sig-installer][Feature:baremetal][Serial] Baremetal platfor

g.BeforeEach(func() {
skipIfNotBaremetal(oc)
skipIfTwoNode(oc)
helper = NewBaremetalTestHelper(oc.AdminDynamicClient())
helper.Setup()
})
Expand Down