Skip to content

Commit

Permalink
Merge pull request #219 from rabi/func_tests
Browse files Browse the repository at this point in the history
Add more functional tests individual bmh selection
  • Loading branch information
openshift-merge-bot[bot] authored Oct 4, 2024
2 parents 98ec0fc + 1959e29 commit 199ee1a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 5 deletions.
56 changes: 52 additions & 4 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,54 @@ func TwoNodeBaremetalSetSpecWithWrongNodeLabel(namespace string) map[string]inte
return spec
}

func MultiNodeBaremetalSetSpecWithSameNodeLabel(namespace string) map[string]interface{} {
spec := map[string]interface{}{
"baremetalHosts": map[string]interface{}{
"compute-0": map[string]interface{}{
"ctlPlaneIP": "10.0.0.1",
"bmhLabelSelector": map[string]string{"nodeType": "compute"},
},
"compute-1": map[string]interface{}{
"ctlPlaneIP": "10.0.0.2",
"bmhLabelSelector": map[string]string{"nodeType": "compute"},
},
"compute-2": map[string]interface{}{
"ctlPlaneIP": "10.0.0.3",
"bmhLabelSelector": map[string]string{"nodeType": "compute"},
},
},
"bmhLabelSelector": map[string]string{"app": "openstack"},
"deploymentSSHSecret": "mysecret",
"ctlplaneInterface": "eth0",
"bmhNamespace": namespace,
}
return spec
}

func MultiNodeBaremetalSetSpecWithOverlappingNodeLabels(namespace string) map[string]interface{} {
spec := map[string]interface{}{
"baremetalHosts": map[string]interface{}{
"compute-0": map[string]interface{}{
"ctlPlaneIP": "10.0.0.1",
"bmhLabelSelector": map[string]string{"nodeType": "compute", "dummyLabel": "dummy"},
},
"compute-1": map[string]interface{}{
"ctlPlaneIP": "10.0.0.2",
"bmhLabelSelector": map[string]string{"nodeType": "compute", "nodeName": "compute-1"},
},
"compute-2": map[string]interface{}{
"ctlPlaneIP": "10.0.0.3",
"bmhLabelSelector": map[string]string{"nodeType": "compute", "dummyLabel": "dummy"},
},
},
"bmhLabelSelector": map[string]string{"app": "openstack"},
"deploymentSSHSecret": "mysecret",
"ctlplaneInterface": "eth0",
"bmhNamespace": namespace,
}
return spec
}

// Default BMH Template with preset values
func DefaultBMHTemplate(name types.NamespacedName) map[string]interface{} {
return map[string]interface{}{
Expand Down Expand Up @@ -160,8 +208,8 @@ func DefaultBMHTemplate(name types.NamespacedName) map[string]interface{} {
}

// Default BMH Template with preset values
func BMHTemplateWithNodeLabel(name types.NamespacedName, nodeLabel map[string]string) map[string]interface{} {
labels := util.MergeMaps(map[string]string{"app": "openstack"}, nodeLabel)
func BMHTemplateWithNodeLabels(name types.NamespacedName, nodeLabels map[string]string) map[string]interface{} {
labels := util.MergeMaps(map[string]string{"app": "openstack"}, nodeLabels)
return map[string]interface{}{
"apiVersion": "metal3.io/v1alpha1",
"kind": "BareMetalHost",
Expand Down Expand Up @@ -203,8 +251,8 @@ func CreateBaremetalHost(name types.NamespacedName) *unstructured.Unstructured {

// Create BaremetalHost with NodeLabel
func CreateBaremetalHostWithNodeLabel(name types.NamespacedName,
nodeLabel map[string]string) *unstructured.Unstructured {
instance := BMHTemplateWithNodeLabel(name, nodeLabel)
nodeLabels map[string]string) *unstructured.Unstructured {
instance := BMHTemplateWithNodeLabels(name, nodeLabels)
return th.CreateUnstructured(instance)
}

Expand Down
53 changes: 52 additions & 1 deletion tests/functional/openstackbaremetalset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ = Describe("OpenStackBaremetalSet Webhook", func() {
var baremetalSetName types.NamespacedName
var bmhName types.NamespacedName
var bmhName1 types.NamespacedName
var bmhName2 types.NamespacedName

BeforeEach(func() {
baremetalSetName = types.NamespacedName{
Expand All @@ -33,6 +34,11 @@ var _ = Describe("OpenStackBaremetalSet Webhook", func() {
Name: "compute-1",
Namespace: namespace,
}
bmhName2 = types.NamespacedName{
Name: "compute-3",
Namespace: namespace,
}

})
When("When creating BaremetalSet", func() {
BeforeEach(func() {
Expand Down Expand Up @@ -102,7 +108,7 @@ var _ = Describe("OpenStackBaremetalSet Webhook", func() {
})
})

When("When creating BaremetalSet with nodeSelector", func() {
When("When creating BaremetalSet with a node selector", func() {
BeforeEach(func() {
DeferCleanup(th.DeleteInstance, CreateBaremetalHostWithNodeLabel(
bmhName, map[string]string{"nodeName": "compute-0"}))
Expand Down Expand Up @@ -144,4 +150,49 @@ var _ = Describe("OpenStackBaremetalSet Webhook", func() {
)
})
})

When("When creating BaremetalSet with node selectors", func() {
BeforeEach(func() {
DeferCleanup(th.DeleteInstance, CreateBaremetalHostWithNodeLabel(
bmhName, map[string]string{"nodeType": "compute", "dummyLabel": "dummy", "nodeName": "compute-1"}))
bmh := GetBaremetalHost(bmhName)
DeferCleanup(th.DeleteInstance, CreateBaremetalHostWithNodeLabel(
bmhName1, map[string]string{"nodeType": "compute", "nodeName": "compute-0", "dummyLabel": "dummy"}))
bmh1 := GetBaremetalHost(bmhName1)
DeferCleanup(th.DeleteInstance, CreateBaremetalHostWithNodeLabel(
bmhName2, map[string]string{"nodeType": "compute", "dummyLabel": "dummy"}))
bmh2 := GetBaremetalHost(bmhName2)

Eventually(func(g Gomega) {
// OpenStackBaremetalSet has the same name as OpenStackDataPlaneNodeSet
bmh.Status.Provisioning.State = metal3v1.StateAvailable
bmh1.Status.Provisioning.State = metal3v1.StateAvailable
bmh2.Status.Provisioning.State = metal3v1.StateAvailable
g.Expect(th.K8sClient.Status().Update(th.Ctx, bmh)).To(Succeed())
g.Expect(th.K8sClient.Status().Update(th.Ctx, bmh1)).To(Succeed())
g.Expect(th.K8sClient.Status().Update(th.Ctx, bmh2)).To(Succeed())
}, th.Timeout, th.Interval).Should(Succeed())

})

It("It should pass if node labels are same", func() {
spec := MultiNodeBaremetalSetSpecWithSameNodeLabel(baremetalSetName.Namespace)
object := DefaultBaremetalSetTemplate(baremetalSetName, spec)
unstructuredObj := &unstructured.Unstructured{Object: object}
_, err := controllerutil.CreateOrPatch(
th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil })
Expect(err).ShouldNot(HaveOccurred())
})

It("It should pass if overlapping node labels match", func() {
spec := MultiNodeBaremetalSetSpecWithOverlappingNodeLabels(baremetalSetName.Namespace)
object := DefaultBaremetalSetTemplate(baremetalSetName, spec)
unstructuredObj := &unstructured.Unstructured{Object: object}
_, err := controllerutil.CreateOrPatch(
th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil })
Expect(err).ShouldNot(HaveOccurred())
})

})

})

0 comments on commit 199ee1a

Please sign in to comment.