Skip to content

Commit

Permalink
Re-inspection by annotation test added
Browse files Browse the repository at this point in the history
  • Loading branch information
adilGhaffarDev committed Oct 30, 2023
1 parent 3dccd97 commit 245ef64
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ test/e2e/images
go.work
go.work.sum

# Common editor / temporary files
*~
*.tmp
.DS_Store

# Tilt files.
.tiltbuild
/tilt.d
Expand Down
1 change: 1 addition & 0 deletions test/e2e/config/fixture.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ intervals:
inspection/wait-inspecting: ["5s", "10ms"]
inspection/wait-available: ["5s", "1ms"]
external-inspection/wait-available: ["5s", "1ms"]
re-inspection/wait-available: ["5m", "1s"]
default/wait-deployment: ["5m", "1s"]
default/wait-namespace-deleted: ["20s", "1s"]
ironic/wait-deployment: ["10m", "2s"]
Expand Down
1 change: 1 addition & 0 deletions test/e2e/config/ironic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ intervals:
default/wait-registering: ["1m", "5s"]
inspection/wait-registration-error: ["1m", "5s"]
external-inspection/wait-available: ["20s", "1s"]
re-inspection/wait-available: ["5m", "1s"]
default/wait-inspecting: ["2m", "10s"]
default/wait-available: ["10m", "10s"]
default/wait-deployment: ["5m", "1s"]
Expand Down
81 changes: 81 additions & 0 deletions test/e2e/inspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/util"

capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e"

metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
)

Expand Down Expand Up @@ -145,6 +148,84 @@ var _ = Describe("Inspection", func() {
}, e2eConfig.GetIntervals(specName, "wait-available")...)
})

It("should re-inspect the annotated BMH", func() {
By("creating a secret with BMH credentials")
bmcCredentials := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "bmc-credentials",
Namespace: namespace.Name,
},
StringData: map[string]string{
"username": bmcUser,
"password": bmcPassword,
},
}
err := clusterProxy.GetClient().Create(ctx, &bmcCredentials)
Expect(err).NotTo(HaveOccurred())

By("creating a BMH")
bmh := metal3api.BareMetalHost{
ObjectMeta: metav1.ObjectMeta{
Name: specName + "-inspect",
Namespace: namespace.Name,
},
Spec: metal3api.BareMetalHostSpec{
BMC: metal3api.BMCDetails{
Address: bmcAddress,
CredentialsName: "bmc-credentials",
},
BootMode: metal3api.Legacy,
BootMACAddress: bootMacAddress,
},
}
err = clusterProxy.GetClient().Create(ctx, &bmh)
Expect(err).NotTo(HaveOccurred())

By("waiting for the BMH to be in registering state")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateRegistering,
}, e2eConfig.GetIntervals(specName, "wait-registering")...)

By("waiting for the BMH to be in inspecting state")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateInspecting,
}, e2eConfig.GetIntervals(specName, "wait-inspecting")...)

By("waiting for the BMH to become available")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateAvailable,
}, e2eConfig.GetIntervals(specName, "wait-available")...)

By("setting the inspect annotation and checking for BMH to go in inspecting")
capm3_e2e.AnnotateBmh(ctx, clusterProxy.GetClient(), bmh, metal3api.InspectAnnotationPrefix, pointer.String(""))

By("waiting for the BMH to be in inspecting state after inspection annotaion")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateInspecting,
}, e2eConfig.GetIntervals(specName, "wait-inspecting")...)

By("waiting for the BMH to become available")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateAvailable,
}, e2eConfig.GetIntervals(specName, "wait-available")...)
annotations := bmh.GetAnnotations()
if annotations != nil {
value, ok := annotations[metal3api.InspectAnnotationPrefix]
Expect(ok).NotTo(BeTrue())
Expect(value).To(Equal(nil))
}
})

AfterEach(func() {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
})
Expand Down
136 changes: 136 additions & 0 deletions test/e2e/re_inspection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package e2e

import (
"context"
"fmt"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/util"

capm3_e2e "github.com/metal3-io/cluster-api-provider-metal3/test/e2e"

metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
)

var _ = Describe("Re-Inspection", func() {
var (
specName = "re-inspection"
namespace *corev1.Namespace
cancelWatches context.CancelFunc
bmcUser string
bmcPassword string
bmcAddress string
bootMacAddress string
)
const (
wrongHostName = "wrongHostName"
rightHostName = "localhost.localdomain"
)
BeforeEach(func() {
bmcUser = e2eConfig.GetVariable("BMC_USER")
bmcPassword = e2eConfig.GetVariable("BMC_PASSWORD")
bmcAddress = e2eConfig.GetVariable("BMC_ADDRESS")
bootMacAddress = e2eConfig.GetVariable("BOOT_MAC_ADDRESS")

namespace, cancelWatches = framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{
Creator: clusterProxy.GetClient(),
ClientSet: clusterProxy.GetClientSet(),
Name: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
LogFolder: artifactFolder,
})
})

It("should re-inspect the annotated BMH", func() {
By("creating a secret with BMH credentials")
bmcCredentials := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "bmc-credentials",
Namespace: namespace.Name,
},
StringData: map[string]string{
"username": bmcUser,
"password": bmcPassword,
},
}
err := clusterProxy.GetClient().Create(ctx, &bmcCredentials)
Expect(err).NotTo(HaveOccurred())

By("creating a BMH with inspection disabled and hardware details added with wrong HostName")
newHardwareDetails := strings.Replace(hardwareDetails, "localhost.localdomain", wrongHostName, 1)
bmh := metal3api.BareMetalHost{
ObjectMeta: metav1.ObjectMeta{
Name: specName + "-reinspect",
Namespace: namespace.Name,
Annotations: map[string]string{
metal3api.InspectAnnotationPrefix: "disabled",
metal3api.HardwareDetailsAnnotation: newHardwareDetails,
},
},
Spec: metal3api.BareMetalHostSpec{
BMC: metal3api.BMCDetails{
Address: bmcAddress,
CredentialsName: "bmc-credentials",
},
BootMode: metal3api.Legacy,
BootMACAddress: bootMacAddress,
},
}
err = clusterProxy.GetClient().Create(ctx, &bmh)
Expect(err).NotTo(HaveOccurred())

By("waiting for the BMH to be in registering state")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateRegistering,
}, e2eConfig.GetIntervals(specName, "wait-registering")...)

By("waiting for the BMH to become available")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateAvailable,
}, e2eConfig.GetIntervals(specName, "wait-available")...)

By("checking that the BMH has wrong HostName")
key := types.NamespacedName{Namespace: bmh.Namespace, Name: bmh.Name}
Expect(clusterProxy.GetClient().Get(ctx, key, &bmh)).To(Succeed())
Expect(bmh.Status.HardwareDetails.Hostname).To(Equal(wrongHostName))

By("removing HardwareDetailsAnnotation")
capm3_e2e.AnnotateBmh(ctx, clusterProxy.GetClient(), bmh, metal3api.HardwareDetailsAnnotation, nil)

By("adding InspectAnnotation to re-inspect")
capm3_e2e.AnnotateBmh(ctx, clusterProxy.GetClient(), bmh, metal3api.InspectAnnotationPrefix, pointer.String(""))

By("waiting for the BMH to be in inspecting state after inspection annotaion")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateInspecting,
}, e2eConfig.GetIntervals(specName, "wait-inspecting")...)

By("waiting for the BMH to become available after re-inspection")
WaitForBmhInProvisioningState(ctx, WaitForBmhInProvisioningStateInput{
Client: clusterProxy.GetClient(),
Bmh: bmh,
State: metal3api.StateAvailable,
}, e2eConfig.GetIntervals(specName, "wait-available")...)

By("checking that the hardware details are corrected after re-inspection")
key = types.NamespacedName{Namespace: bmh.Namespace, Name: bmh.Name}
Expect(clusterProxy.GetClient().Get(ctx, key, &bmh)).To(Succeed())
Expect(bmh.Status.HardwareDetails.Hostname).To(Equal(rightHostName))
})

AfterEach(func() {
cleanup(ctx, clusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
})
})

0 comments on commit 245ef64

Please sign in to comment.