From f17e482482daf36650ad75d5f19b65306a03289a Mon Sep 17 00:00:00 2001 From: Rob Conde Date: Mon, 5 Jul 2021 16:24:31 -0400 Subject: [PATCH 1/2] fix: make processing of mac addresses case insensitive Closes: #2509 --- object/virtual_machine.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/object/virtual_machine.go b/object/virtual_machine.go index 1d85047fc..bb731800c 100644 --- a/object/virtual_machine.go +++ b/object/virtual_machine.go @@ -22,6 +22,7 @@ import ( "fmt" "net" "path" + "strings" "github.com/vmware/govmomi/nfc" "github.com/vmware/govmomi/property" @@ -333,7 +334,9 @@ func (v VirtualMachine) WaitForNetIP(ctx context.Context, v4 bool, device ...str devices := VirtualDeviceList(c.Val.(types.ArrayOfVirtualDevice).VirtualDevice) for _, d := range devices { if nic, ok := d.(types.BaseVirtualEthernetCard); ok { - mac := nic.GetVirtualEthernetCard().MacAddress + // Convert to lower so that e.g. 00:50:56:83:3A:5D is treated the + // same as 00:50:56:83:3a:5d + mac := strings.ToLower(nic.GetVirtualEthernetCard().MacAddress) if mac == "" { return false } @@ -369,7 +372,9 @@ func (v VirtualMachine) WaitForNetIP(ctx context.Context, v4 bool, device ...str nics := c.Val.(types.ArrayOfGuestNicInfo).GuestNicInfo for _, nic := range nics { - mac := nic.MacAddress + // Convert to lower so that e.g. 00:50:56:83:3A:5D is treated the + // same as 00:50:56:83:3a:5d + mac := strings.ToLower(nic.MacAddress) if mac == "" || nic.IpConfig == nil { continue } From bdea6a35493743971bc61ddf8150b6aff13d0f52 Mon Sep 17 00:00:00 2001 From: Rob Conde Date: Sun, 25 Jul 2021 15:10:02 -0400 Subject: [PATCH 2/2] add test for a capitalized mac address --- govc/test/vm.bats | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/govc/test/vm.bats b/govc/test/vm.bats index aefb4ab1c..cdcc26ced 100755 --- a/govc/test/vm.bats +++ b/govc/test/vm.bats @@ -36,6 +36,40 @@ load test_helper assert_equal $ip $res } +@test "vm.ip capital MAC" { + vcsim_env -autostart=false + + id=/DC0/vm/DC0_H0_VM0 + + mac=00:50:56:83:3A:5D + run govc vm.customize -vm $id -mac $mac -ip 10.0.0.1 -netmask 255.255.0.0 -type Linux + assert_success + + run govc vm.power -on $id + assert_success + + run govc vm.ip -wait 5s $id + assert_success + + run govc vm.ip -wait 5s -a -v4 $id + assert_success + + run govc vm.ip -wait 5s -n $mac $id + assert_success + + run govc vm.ip -wait 5s -n ethernet-0 $id + assert_success + + ip=$(govc vm.ip -wait 5s $id) + + # add a second nic + run govc vm.network.add -vm $id "VM Network" + assert_success + + res=$(govc vm.ip -wait 5s -n ethernet-0 $id) + assert_equal $ip $res +} + @test "vm.ip -esxcli" { esx_env