@@ -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
3333func 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+ }
0 commit comments