Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
11 changes: 6 additions & 5 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ var _ = BeforeSuite(func() {
}).SetupWithManager(ctx, testEnv.Manager, controller.Options{})).To(Succeed())

Expect((&HetznerBareMetalHostReconciler{
Client: testEnv.Manager.GetClient(),
APIReader: testEnv.Manager.GetAPIReader(),
RobotClientFactory: testEnv.RobotClientFactory,
SSHClientFactory: testEnv.BaremetalSSHClientFactory,
PreProvisionCommand: "dummy-pre-provision-command",
Client: testEnv.Manager.GetClient(),
APIReader: testEnv.Manager.GetAPIReader(),
RobotClientFactory: testEnv.RobotClientFactory,
SSHClientFactory: testEnv.BaremetalSSHClientFactory,
PreProvisionCommand: "dummy-pre-provision-command",
SSHAfterInstallImage: true,
}).SetupWithManager(ctx, testEnv.Manager, controller.Options{})).To(Succeed())

Expect((&HetznerBareMetalMachineReconciler{
Expand Down
76 changes: 72 additions & 4 deletions controllers/hetznerbaremetalmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -390,16 +391,83 @@ var _ = Describe("HetznerBareMetalMachineReconciler", func() {
})

It("deletes successfully", func() {
By("deleting bm machine")
By("Waiting until host is provisioned")

Eventually(func() bool {
return isPresentAndTrue(key, bmMachine, infrav1.HostReadyCondition)
}, timeout).Should(BeTrue())

err := testEnv.Get(ctx, hostKey, host)
Expect(err).To(BeNil())

Expect(host.Spec.Status.ProvisioningState).To(Equal(infrav1.StateProvisioned))

By("deleting hbmm")
Expect(testEnv.Delete(ctx, bmMachine)).To(Succeed())

Eventually(func() error {
err := testEnv.Get(ctx, key, bmMachine)
if apierrors.IsNotFound(err) {
return nil
}
return err
}, timeout, time.Second).Should(Succeed())

By("making sure the host has been deprovisioned")

Eventually(func() bool {
if err := testEnv.Get(ctx, key, bmMachine); apierrors.IsNotFound(err) {
return true
if err := testEnv.Get(ctx, hostKey, host); err != nil {
return false
}
return false
return host.Spec.Status.ProvisioningState == infrav1.StateNone
}, timeout, time.Second).Should(BeTrue())
})

It("deletes successfully, even if state is 'ensure-provisioned'", func() {
By("checking that the host is ready")
Eventually(func() bool {
return isPresentAndTrue(key, bmMachine, infrav1.HostReadyCondition)
}, timeout).Should(BeTrue())

osSSHClient.On("GetHostName").Unset()

osSSHClient.On("GetHostName").Return(sshclient.Output{
StdOut: "some-unexpected-hostname",
StdErr: "",
Err: nil,
})

err := testEnv.Get(ctx, hostKey, host)
Expect(err).To(BeNil())
Expect(host.Spec.Status.ProvisioningState).To(Equal(infrav1.StateProvisioned))

By("Setting State to 'ensure-provisioned'")
host.Spec.Status.ProvisioningState = infrav1.StateEnsureProvisioned
err = testEnv.Update(ctx, host)
Expect(err).To(BeNil())

Eventually(func() error {
err := testEnv.Get(ctx, hostKey, host)
apierrors.IsNotFound(err)
if err != nil {
return err
}
if host.Spec.Status.ProvisioningState != infrav1.StateEnsureProvisioned {
return fmt.Errorf("ProvisioningState=%s", host.Spec.Status.ProvisioningState)
}
return nil
}, timeout, time.Second).Should(Succeed())

By("deleting bm machine")
Expect(testEnv.Delete(ctx, bmMachine)).To(Succeed())

Eventually(func() error {
err := testEnv.Get(ctx, key, bmMachine)
if apierrors.IsNotFound(err) {
return nil
}
return err
}, timeout, time.Second).Should(Succeed())

By("making sure the host has been deprovisioned")

Expand Down
Loading