Check if task result is nil and return error (#9354)

This commit is contained in:
Sylvia Moss 2020-06-03 17:37:30 +02:00 committed by GitHub
parent 8e4a3662ca
commit 434c9bcae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -59,9 +59,10 @@
* builder/vagrant: Use absolute path for package_include files to prevent them
from having to be relative to the output vagrant directory. [GH-9260]
* builder/virtualbox: Fix bug using checksum files. [GH-9101]
* builder/vSphere: Add option not to set host during datastore upload. [GH-9100
* builder/vsphere: Add option not to set host during datastore upload. [GH-9100
* builder/vsphere: Fix iso config prepare being called incorrectly, which
caused `iso_url` field to fail. [GH-9197]
* builder/vsphere: Fix crash in the driver for an interface conversion of types.AnyType nil to types.ManagedObjectReference. [GH-9354]
* core: Ensure HTTP server information `PackerHTTPIP`, `PackerHTTPPort`, and
`PackerHTTPAddr` are available via the `build` template engine for all
supported builders [GH-9238]

View File

@ -205,7 +205,10 @@ func (d *Driver) CreateVM(config *CreateConfig) (*VirtualMachine, error) {
return nil, err
}
vmRef := taskInfo.Result.(types.ManagedObjectReference)
vmRef, ok := taskInfo.Result.(types.ManagedObjectReference)
if !ok {
return nil, fmt.Errorf("something went wrong when creating the VM")
}
return d.NewVM(&vmRef), nil
}
@ -326,7 +329,11 @@ func (vm *VirtualMachine) Clone(ctx context.Context, config *CloneConfig) (*Virt
return nil, err
}
vmRef := info.Result.(types.ManagedObjectReference)
vmRef, ok := info.Result.(types.ManagedObjectReference)
if !ok {
return nil, fmt.Errorf("something went wrong when cloning the VM")
}
created := vm.driver.NewVM(&vmRef)
return created, nil
}