Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 9 additions & 12 deletions pkg/services/baremetal/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,17 @@ func (s *Service) actionPreparing(ctx context.Context) actionResult {

s.scope.HetznerBareMetalHost.Status.SSHStatus.RescueKey = sshKey

// Populate reboot methods in status
if len(s.scope.HetznerBareMetalHost.Status.RebootTypes) == 0 {
reboot, err := s.scope.RobotClient.GetReboot(int(s.scope.HetznerBareMetalHost.Spec.ServerID))
if err != nil {
s.handleRobotRateLimitExceeded(err, "GetReboot")
return actionError{err: fmt.Errorf("failed to get reboot: %w", err)}
}
reboot, err := s.scope.RobotClient.GetReboot(int(s.scope.HetznerBareMetalHost.Spec.ServerID))
if err != nil {
s.handleRobotRateLimitExceeded(err, "GetReboot")
return actionError{err: fmt.Errorf("failed to get reboot: %w", err)}
}

rebootTypes, err := rebootTypesFromStringList(reboot.Type)
if err != nil {
return actionError{err: fmt.Errorf("failed to unmarshal: %w", err)}
}
s.scope.HetznerBareMetalHost.Status.RebootTypes = rebootTypes
rebootTypes, err := rebootTypesFromStringList(reboot.Type)
if err != nil {
return actionError{err: fmt.Errorf("failed to unmarshal: %w", err)}
}
s.scope.HetznerBareMetalHost.Status.RebootTypes = rebootTypes

if err := s.enforceRescueMode(); err != nil {
return actionError{err: fmt.Errorf("failed to enforce rescue mode: %w", err)}
Expand Down
48 changes: 48 additions & 0 deletions pkg/services/baremetal/host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,54 @@ var _ = Describe("actionPreparing", func() {
Expect(host.Status.HardwareDetails).To(BeNil())
})

It("replaces the stored reboot types with the ones Robot offers now", func() {
// rebootTypes still has power and power_long, but Robot no longer offers them
host := helpers.BareMetalHost(
"test-host",
"default",
helpers.WithRebootTypes([]infrav1.RebootType{
infrav1.RebootTypePower,
infrav1.RebootTypePowerLong,
infrav1.RebootTypeHardware,
infrav1.RebootTypeManual,
}),
)

robotMock := robotmock.Client{}
robotMock.On("GetBMServer", mock.Anything).Return(&models.Server{ServerNumber: 1, ServerIP: "1.2.3.4"}, nil)
robotMock.On("ListSSHKeys").Return([]models.Key{}, nil)
robotMock.On("SetSSHKey", mock.Anything, mock.Anything).Return(
&models.Key{Name: rescueSSHKeyName, Fingerprint: sshFingerprint},
nil,
)
robotMock.On("GetReboot", mock.Anything).Return(&models.Reset{Type: []string{"sw", "hw", "man"}}, nil)
robotMock.On("DeleteBootRescue", mock.Anything).Return(&models.Rescue{Active: false}, nil)
robotMock.On("SetBootRescue", mock.Anything, sshFingerprint).Return(&models.Rescue{Active: true}, nil)
robotMock.On("RebootBMServer", mock.Anything, mock.Anything).Return(&models.ResetPost{}, nil)

sshMock := &sshmock.Client{}
sshMock.On("GetHostName", mock.Anything).Return(sshclient.Output{})

service := newTestService(
host,
&robotMock,
bmmock.NewSSHFactory(sshMock, sshMock, sshMock),
helpers.GetDefaultSSHSecret(osSSHKeyName, "default"),
helpers.GetDefaultSSHSecret(rescueSSHKeyName, "default"),
)

Expect(service.actionPreparing(context.Background())).To(BeAssignableToTypeOf(actionComplete{}))

// rebootTypeAfterTimeout picks sw from the new list. With the old list it would pick power_long.
Expect(host.Status.RebootTypes).To(Equal([]infrav1.RebootType{
infrav1.RebootTypeSoftware,
infrav1.RebootTypeHardware,
infrav1.RebootTypeManual,
}))
robotMock.AssertCalled(GinkgoT(), "RebootBMServer", mock.Anything, infrav1.RebootTypeSoftware)
robotMock.AssertNotCalled(GinkgoT(), "RebootBMServer", mock.Anything, infrav1.RebootTypePowerLong)
})

It("sets a permanent error when the server has no IPv4", func() {
host := helpers.BareMetalHost(
"test-host",
Expand Down
Loading