From 31cf332d39dde9eec46dd78d6e0c20e79f12392b Mon Sep 17 00:00:00 2001 From: ekarlso Date: Wed, 9 Oct 2024 20:50:55 +0200 Subject: [PATCH] Fix tests Signed-off-by: ekarlso --- internal/service/vmservice/vm.go | 2 +- pkg/proxmox/goproxmox/api_client.go | 2 +- pkg/scope/machine.go | 4 ++++ pkg/scope/machine_test.go | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/service/vmservice/vm.go b/internal/service/vmservice/vm.go index dbd076b9..a68aeb5b 100644 --- a/internal/service/vmservice/vm.go +++ b/internal/service/vmservice/vm.go @@ -120,7 +120,7 @@ func checkCloudInitStatus(ctx context.Context, machineScope *scope.MachineScope) } } - if !machineScope.SkipQemuGuestCheck() && !machineScope.SkipCloudInitCheck() { + if !machineScope.SkipCloudInitCheck() { if running, err := machineScope.InfraCluster.ProxmoxClient.CloudInitStatus(ctx, machineScope.VirtualMachine); err != nil || running { if running { return true, nil diff --git a/pkg/proxmox/goproxmox/api_client.go b/pkg/proxmox/goproxmox/api_client.go index 781e4dc4..e9ecef4a 100644 --- a/pkg/proxmox/goproxmox/api_client.go +++ b/pkg/proxmox/goproxmox/api_client.go @@ -277,7 +277,7 @@ func (c *APIClient) UnmountCloudInitISO(ctx context.Context, vm *proxmox.Virtual // CloudInitStatus returns the cloud-init status of the VM. func (c *APIClient) CloudInitStatus(ctx context.Context, vm *proxmox.VirtualMachine) (running bool, err error) { - if err := vm.WaitForAgent(ctx, 5); err != nil { + if err := c.QemuAgentStatus(ctx, vm); err != nil { return false, errors.Wrap(err, "error waiting for agent") } diff --git a/pkg/scope/machine.go b/pkg/scope/machine.go index 988d57e8..59084ef9 100644 --- a/pkg/scope/machine.go +++ b/pkg/scope/machine.go @@ -255,6 +255,10 @@ func (m *MachineScope) SkipQemuGuestCheck() bool { // SkipCloudInitCheck check whether cloud-init status check is enabled. func (m *MachineScope) SkipCloudInitCheck() bool { + if m.SkipQemuGuestCheck() { + return true + } + if m.ProxmoxMachine.Spec.Checks != nil { return ptr.Deref(m.ProxmoxMachine.Spec.Checks.SkipCloudInitStatus, false) } diff --git a/pkg/scope/machine_test.go b/pkg/scope/machine_test.go index 814c0def..053beee7 100644 --- a/pkg/scope/machine_test.go +++ b/pkg/scope/machine_test.go @@ -174,6 +174,21 @@ func TestMachineScope_SkipCloudInit(t *testing.T) { require.False(t, scope.SkipQemuGuestCheck()) } +func TestMachineScope_SkipQemuDisablesCloudInitCheck(t *testing.T) { + p := infrav1alpha1.ProxmoxMachine{ + Spec: infrav1alpha1.ProxmoxMachineSpec{ + Checks: &infrav1alpha1.ProxmoxMachineChecks{ + SkipQemuGuestAgent: ptr.To(true), + }, + }, + } + scope := MachineScope{ + ProxmoxMachine: &p, + } + + require.False(t, scope.SkipCloudInitCheck()) +} + func TestMachineScope_GetBootstrapSecret(t *testing.T) { client := fake.NewClientBuilder().Build() p := infrav1alpha1.ProxmoxMachine{