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

[BUG] vcsim: decreasing disk size should raise an error #2910

Closed
Syuparn opened this issue Jul 21, 2022 · 0 comments · Fixed by #2911
Closed

[BUG] vcsim: decreasing disk size should raise an error #2910

Syuparn opened this issue Jul 21, 2022 · 0 comments · Fixed by #2911

Comments

@Syuparn
Copy link
Contributor

Syuparn commented Jul 21, 2022

Describe the bug

In ReconfigVM_Task, virtual disk size can be increased but not decreased.
However vcsim allows decreasing disk size.

To Reproduce

  1. run vcsim without any options
  2. check DC0_H0_VM0 has a disk whose size is 10GB
  3. decrease the disk size by a script below
$ govc device.info -vm DC0_H0_VM0 disk-* | grep Summary
  Summary:      10,485,760 KB
vm := object.NewVirtualMachine(c.Client, types.ManagedObjectReference{
	Type:  "VirtualMachine",
	Value: "vm-55", // DC0_H0_VM0
})
devices, _ := vm.Device(ctx)
disk := devices.FindByKey(204).(*types.VirtualDisk)
// decrease capacity
disk.CapacityInBytes /= 2
disk.CapacityInKB /= 2

spec := types.VirtualMachineConfigSpec{
	DeviceChange: []types.BaseVirtualDeviceConfigSpec{
		&types.VirtualDeviceConfigSpec{
			Device:        disk,
			Operation:     types.VirtualDeviceConfigSpecOperationEdit,
			FileOperation: "",
		},
	},
}
task, _ := vm.Reconfigure(ctx, spec)

err := task.Wait(ctx)
fmt.Printf("error: %#v\n", err)

Expected behavior

vcsim responds InvalidDeviceOperation.

error: Invalid operation for device '0'.

Affected version

  • vcsim 0.29.0

Screenshots/Debug Output

vcsim decreases the disk size without any errors.

error: <nil>
$ govc device.info -vm DC0_H0_VM0 disk-* | grep Summary
  Summary:      5,242,880 KB

Additional context
Add any other context about the problem here.

Even if capacity is not decreased, InvalidDeviceOperation is raised under following conditions.

  • both CapacityInKB and CapacityInBytes are increased and
  • both have diffrerent capacity
# neither CapacityInKB nor CapacityInBytes are modified: same as before (success)
> go run main.go
before:
kb: 2097156, bytes: 2147487744
modified spec:
kb: 2097156, bytes: 2147487744
after:
kb: 2097156, bytes: 2147487744

# only CapacityInKB is increased: new capacity is same as specified CapacityInKB (success)
> go run main.go
before:
kb: 2097156, bytes: 2147487744
modified spec:
kb: 2097157, bytes: 2147487744
after:
kb: 2097157, bytes: 2147488768

# only CapacityInBytes is increased: new capacity is same as specified CapacityInBytes (success)
> go run main.go
before:
kb: 2097157, bytes: 2147488768
modified spec:
kb: 2097157, bytes: 2147489792
after:
kb: 2097158, bytes: 2147489792

# both are increased: new capacity is same as specified (success)
> go run main.go
before:
kb: 2097158, bytes: 2147489792
modified spec:
kb: 2097159, bytes: 2147490816
after:
kb: 2097159, bytes: 2147490816

# both are increased but diffrerent values are specified (failure)
> go run main.go
before:
kb: 2097158, bytes: 2147489792
modified spec:
kb: 3097158, bytes: 2147490816
error: Invalid operation for device '0'.
Syuparn added a commit to Syuparn/govmomi that referenced this issue Jul 22, 2022
Closes: vmware#2910
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant