Skip to content

Commit 9d4bee2

Browse files
committed
Add TestReconcileMachineAddresses_DHCP
1 parent 9a88f24 commit 9d4bee2

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

internal/service/vmservice/helpers_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ func newVMWithNets(def string, additional ...string) *proxmox.VirtualMachine {
286286
Nets: map[string]string{
287287
"net0": def,
288288
},
289+
Net0: def,
289290
},
290291
Name: "test",
291292
Node: "node1",

internal/service/vmservice/vm_test.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import (
2121
"fmt"
2222
"testing"
2323

24-
"github.com/stretchr/testify/require"
25-
"k8s.io/utils/ptr"
26-
2724
infrav1 "github.com/ionos-cloud/cluster-api-provider-proxmox/api/v1alpha1"
2825
"github.com/ionos-cloud/cluster-api-provider-proxmox/internal/service/scheduler"
2926
"github.com/ionos-cloud/cluster-api-provider-proxmox/pkg/proxmox"
3027
"github.com/ionos-cloud/cluster-api-provider-proxmox/pkg/scope"
28+
go_proxmox "github.com/luthermonson/go-proxmox"
29+
"github.com/stretchr/testify/require"
30+
"k8s.io/utils/ptr"
3131
)
3232

3333
func TestReconcileVM_EverythingReady(t *testing.T) {
@@ -268,3 +268,40 @@ func TestReconcileMachineAddresses_DualStack(t *testing.T) {
268268
require.Equal(t, machineScope.ProxmoxMachine.Status.Addresses[1].Address, "10.10.10.10")
269269
require.Equal(t, machineScope.ProxmoxMachine.Status.Addresses[2].Address, "2001:db8::2")
270270
}
271+
272+
func TestReconcileMachineAddresses_DHCP(t *testing.T) {
273+
machineScope, proxmoxClient, _ := setupReconcilerTest(t)
274+
machineScope.ProxmoxMachine.Spec.Network = &infrav1.NetworkSpec{
275+
Default: &infrav1.NetworkDevice{
276+
Bridge: "vmbr1",
277+
Model: ptr.To("virtio"),
278+
DHCP4: true,
279+
},
280+
}
281+
282+
vm := newVMWithNets("virtio=A6:23:64:4D:84:CB,bridge=vmbr1")
283+
machineScope.SetVirtualMachine(vm)
284+
machineScope.SetVirtualMachineID(int64(vm.VMID))
285+
machineScope.ProxmoxMachine.Status.IPAddresses = map[string]infrav1.IPAddress{infrav1.DefaultNetworkDevice: {IPV4: "DHCP"}}
286+
machineScope.ProxmoxMachine.Status.BootstrapDataProvided = ptr.To(true)
287+
288+
iFaces := []*go_proxmox.AgentNetworkIface{
289+
&go_proxmox.AgentNetworkIface{
290+
Name: "net0",
291+
HardwareAddress: "A6:23:64:4D:84:CB",
292+
IPAddresses: []*go_proxmox.AgentNetworkIPAddress{{
293+
IPAddressType: "ipv4",
294+
IPAddress: "10.10.10.4",
295+
Prefix: 24,
296+
MacAddress: "A6:23:64:4D:84:CB",
297+
},
298+
},
299+
},
300+
}
301+
302+
proxmoxClient.EXPECT().GetVMNetwork(context.Background(), vm).Return(iFaces, nil).Once()
303+
304+
require.NoError(t, reconcileMachineAddresses(context.Background(), machineScope))
305+
require.Equal(t, machineScope.ProxmoxMachine.Status.Addresses[0].Address, machineScope.ProxmoxMachine.GetName())
306+
require.Equal(t, machineScope.ProxmoxMachine.Status.Addresses[1].Address, "10.10.10.4")
307+
}

pkg/proxmox/proxmoxtest/mock_client.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)