Baremetal platform tests refinement
@@ -2,6 +2,8 @@ package baremetal
import (
"context"
+ "fmt"
+ "strings"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
@@ -33,6 +35,29 @@ func baremetalClient(dc dynamic.Interface) dynamic.ResourceInterface {
return baremetalClient.Namespace("openshift-machine-api")
}
+type FieldGetterFunc func(obj map[string]interface{}, fields ...string) (interface{}, bool, error)
+
+func expectField(host unstructured.Unstructured, nestedField string, fieldGetter FieldGetterFunc) o.Assertion {
+ fields := strings.Split(nestedField, ".")
+
+ value, found, err := fieldGetter(host.Object, fields...)
+ o.Expect(err).NotTo(o.HaveOccurred())
+ o.Expect(found).To(o.BeTrue(), fmt.Sprintf("baremetalhost field `%s` not found", nestedField))
+ return o.Expect(value)
+}
+
+func expectStringField(host unstructured.Unstructured, nestedField string) o.Assertion {
+ return expectField(host, nestedField, func(obj map[string]interface{}, fields ...string) (interface{}, bool, error) {
+ return unstructured.NestedString(host.Object, fields...)
+ })
+}
+
+func expectBoolField(host unstructured.Unstructured, nestedField string) o.Assertion {
+ return expectField(host, nestedField, func(obj map[string]interface{}, fields ...string) (interface{}, bool, error) {
+ return unstructured.NestedBool(host.Object, fields...)
+ })
+}
+
var _ = g.Describe("[sig-installer][Feature:baremetal] Baremetal platform should", func() {
defer g.GinkgoRecover()
@@ -47,6 +72,9 @@ var _ = g.Describe("[sig-installer][Feature:baremetal] Baremetal platform should
metal3, err := c.AppsV1().Deployments("openshift-machine-api").Get(context.Background(), "metal3", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(metal3.Status.AvailableReplicas).To(o.BeEquivalentTo(1))
+
+ o.Expect(metal3.Annotations).Should(o.HaveKey("baremetal.openshift.io/owned"))
+ o.Expect(metal3.Labels).Should(o.HaveKeyWithValue("baremetal.openshift.io/cluster-baremetal-operator", "metal3-state"))
})
g.It("have baremetalhost resources", func() {
@@ -60,10 +88,9 @@ var _ = g.Describe("[sig-installer][Feature:baremetal] Baremetal platform should
o.Expect(hosts.Items).ToNot(o.BeEmpty())
for _, h := range hosts.Items {
- status, found, err := unstructured.NestedString(h.Object, "status", "operationalStatus")
- o.Expect(err).NotTo(o.HaveOccurred())
- o.Expect(found).To(o.BeTrue(), "baremetalhost not ready")
- o.Expect(status).To(o.BeEquivalentTo("OK"))
+ expectStringField(h, "status.operationalStatus").To(o.BeEquivalentTo("OK"))
+ expectStringField(h, "status.provisioning.state").To(o.Or(o.BeEquivalentTo("provisioned"), o.BeEquivalentTo("externally provisioned")))
+ expectBoolField(h, "spec.online").To(o.BeTrue())
}
})
})
