From 8cc0776f3a0d5335a5ef1eb5b35a1f19121fb5e4 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Sun, 10 Sep 2017 16:02:45 -0500 Subject: [PATCH] Fixed oversight in VMware builder's mock-driver that neglected to initialize 'HostAddressResult'. --- builder/vmware/common/driver_mock.go | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/builder/vmware/common/driver_mock.go b/builder/vmware/common/driver_mock.go index 8b533db88..9c63a7bf9 100644 --- a/builder/vmware/common/driver_mock.go +++ b/builder/vmware/common/driver_mock.go @@ -1,6 +1,7 @@ package common import ( + "net" "sync" "github.com/hashicorp/packer/helper/multistep" @@ -127,13 +128,41 @@ func (d *DriverMock) CommHost(state multistep.StateBag) (string, error) { return d.CommHostResult, d.CommHostErr } +func MockInterface() net.Interface { + interfaces, err := net.Interfaces() + + // Build a dummy interface due to being unable to enumerate interfaces + if err != nil || len(interfaces) == 0 { + return net.Interface{ + Index: 0, + MTU: -1, + Name: "dummy", + HardwareAddr: net.HardwareAddr{0, 0, 0, 0, 0, 0}, + Flags: net.FlagLoopback, + } + } + + // Find the first loopback interface + for _, intf := range interfaces { + if intf.Flags&net.FlagLoopback == net.FlagLoopback { + return intf + } + } + + // Fall-back to just the first one + return interfaces[0] +} + func (d *DriverMock) HostAddress(state multistep.StateBag) (string, error) { + intf := MockInterface() + d.HostAddressResult = intf.HardwareAddr.String() d.HostAddressCalled = true d.HostAddressState = state return d.HostAddressResult, d.HostAddressErr } func (d *DriverMock) HostIP(state multistep.StateBag) (string, error) { + d.HostIPResult = "127.0.0.1" d.HostIPCalled = true d.HostIPState = state return d.HostIPResult, d.HostIPErr