|
| 1 | +package baremetal |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + g "github.com/onsi/ginkgo" |
| 7 | + o "github.com/onsi/gomega" |
| 8 | + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 9 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
| 10 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 11 | + "k8s.io/client-go/dynamic" |
| 12 | + e2e "k8s.io/kubernetes/test/e2e/framework" |
| 13 | + |
| 14 | + configv1 "github.com/openshift/api/config/v1" |
| 15 | + exutil "github.com/openshift/origin/test/extended/util" |
| 16 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 17 | + e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" |
| 18 | +) |
| 19 | + |
| 20 | +func skipIfNotBaremetal(oc *exutil.CLI) { |
| 21 | + g.By("checking platform type") |
| 22 | + |
| 23 | + infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{}) |
| 24 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 25 | + |
| 26 | + if infra.Status.Platform != configv1.BareMetalPlatformType { |
| 27 | + e2eskipper.Skipf("No baremetal platform detected") |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func baremetalClient(dc dynamic.Interface) dynamic.ResourceInterface { |
| 32 | + baremetalClient := dc.Resource(schema.GroupVersionResource{Group: "metal3.io", Resource: "baremetalhosts", Version: "v1alpha1"}) |
| 33 | + return baremetalClient.Namespace("openshift-machine-api") |
| 34 | +} |
| 35 | + |
| 36 | +var _ = g.Describe("[sig-cluster-lifecycle][Feature:baremetal] Baremetal platform should", func() { |
| 37 | + defer g.GinkgoRecover() |
| 38 | + |
| 39 | + oc := exutil.NewCLI("baremetal") |
| 40 | + |
| 41 | + g.It("have a metal3 deployment", func() { |
| 42 | + skipIfNotBaremetal(oc) |
| 43 | + |
| 44 | + c, err := e2e.LoadClientset() |
| 45 | + o.Expect(err).ToNot(o.HaveOccurred()) |
| 46 | + |
| 47 | + _, err = c.AppsV1().Deployments("openshift-machine-api").Get(context.Background(), "metal3", metav1.GetOptions{}) |
| 48 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 49 | + }) |
| 50 | + |
| 51 | + g.It("have baremetalhost resources", func() { |
| 52 | + skipIfNotBaremetal(oc) |
| 53 | + |
| 54 | + dc := oc.AdminDynamicClient() |
| 55 | + bmc := baremetalClient(dc) |
| 56 | + |
| 57 | + hosts, err := bmc.List(context.Background(), v1.ListOptions{}) |
| 58 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 59 | + o.Expect(hosts.Items).ToNot(o.BeEmpty()) |
| 60 | + |
| 61 | + for _, h := range hosts.Items { |
| 62 | + status, found, err := unstructured.NestedString(h.Object, "status", "operationalStatus") |
| 63 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 64 | + o.Expect(found).To(o.BeTrue(), "baremetalhost not ready") |
| 65 | + o.Expect(status).To(o.BeEquivalentTo("OK")) |
| 66 | + } |
| 67 | + }) |
| 68 | +}) |
0 commit comments