Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new disk to existingDevices list #10844

Merged
merged 2 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builder/vsphere/driver/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (c *StorageConfig) AddStorageDevices(existingDevices object.VirtualDeviceLi
}

existingDevices.AssignController(disk, controllers[dc.ControllerIndex])
existingDevices = append(existingDevices, disk)
newDevices = append(newDevices, disk)
}

Expand Down
46 changes: 46 additions & 0 deletions builder/vsphere/driver/disk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package driver

import (
"testing"

"github.com/vmware/govmomi/object"
)

func TestAddStorageDevices(t *testing.T) {
config := &StorageConfig{
DiskControllerType: []string{"pvscsi"},
Storage: []Disk{
{
DiskSize: 3072,
DiskThinProvisioned: true,
ControllerIndex: 0,
},
{
DiskSize: 20480,
DiskThinProvisioned: true,
ControllerIndex: 0,
},
},
}

noExistingDevices := object.VirtualDeviceList{}
storageConfigSpec, err := config.AddStorageDevices(noExistingDevices)
if err != nil {
t.Fatalf("unexpected erro: %q", err.Error())
}
if len(storageConfigSpec) != 3 {
t.Fatalf("Expecting VirtualDeviceList to have 3 storage devices but had %d", len(storageConfigSpec))
}

existingDevices := object.VirtualDeviceList{}
device, err := existingDevices.CreateNVMEController()
existingDevices = append(existingDevices, device)

storageConfigSpec, err = config.AddStorageDevices(existingDevices)
if err != nil {
t.Fatalf("unexpected erro: %q", err.Error())
}
if len(storageConfigSpec) != 3 {
t.Fatalf("Expecting VirtualDeviceList to have 3 storage devices but had %d", len(storageConfigSpec))
}
}
43 changes: 43 additions & 0 deletions builder/vsphere/driver/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,46 @@ func TestVirtualMachineDriver_Configure(t *testing.T) {
t.Fatalf("Configure should fail")
}
}

func TestVirtualMachineDriver_CreateVM(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to test this with a real environment yet but this test, which uses a simulator, fails for the same reported issue without the changes from this PR. With the changes, it starts passing 👍🏼

Copy link
Contributor Author

@sylviamoss sylviamoss Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the change:

=== RUN   TestVirtualMachineDriver_CreateVM
    vm_test.go:103: unexpected error *types.InvalidDeviceSpec
--- FAIL: TestVirtualMachineDriver_CreateVM (0.04s)

After the change:

=== RUN   TestVirtualMachineDriver_CreateVM
--- PASS: TestVirtualMachineDriver_CreateVM (0.04s)

sim, err := NewVCenterSimulator()
if err != nil {
t.Fatalf("should not fail: %s", err.Error())
}
defer sim.Close()

_, datastore := sim.ChooseSimulatorPreCreatedDatastore()

config := &CreateConfig{
Annotation: "mock annotation",
Name: "mock name",
Host: "DC0_H0",
Datastore: datastore.Name,
NICs: []NIC{
{
Network: "VM Network",
NetworkCard: "vmxnet3",
},
},
StorageConfig: StorageConfig{
DiskControllerType: []string{"pvscsi"},
Storage: []Disk{
{
DiskSize: 3072,
DiskThinProvisioned: true,
ControllerIndex: 0,
},
{
DiskSize: 20480,
DiskThinProvisioned: true,
ControllerIndex: 0,
},
},
},
}

_, err = sim.driver.CreateVM(config)
if err != nil {
t.Fatalf("unexpected error %s", err.Error())
}
}