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

Fix calculation of diskCapacityInGiB by rounding up #1397

Merged
merged 1 commit into from
Apr 28, 2021
Merged

Fix calculation of diskCapacityInGiB by rounding up #1397

merged 1 commit into from
Apr 28, 2021

Conversation

isometry
Copy link
Contributor

  • Fix the error Invalid operation for device '0' when cloning a virtual
    machine template with a disk whose size is not an multiple of 1024^3
    bytes, by ensuring that the calculated disk capacity is rounded up
    rather than down.

Description

The vsphere_virtual_machine data source calculates and stores disk size in integer GiB. Unfortunately, without this patch, the calculation always rounds the size down. As a result, if the vsphere_virtual_machine resource is used to clone a template with a non-integer GiB disk, it tries to shrink the disk to the calculated, rounded-down size, resulting in the opaque error Invalid operation for device '0'.

This PR resolves the issue by ensuring that the calculated size is always rounded up rather than down, so that, for example, a Packer-generated template with disk size 42000MiB will be cloned without error to a virtual machine with disk size 42GiB rather than 41GiB.

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch?

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestDiskCapacityInGiB'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestDiskCapacityInGiB -timeout 240m
?       github.com/hashicorp/terraform-provider-vsphere [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere 0.357s [no tests to run]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/administrationroles    [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/clustercomputeresource  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/computeresource [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/customattribute [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datacenter      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/datastore       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/dvportgroup     [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/envbrowse       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/folder  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/hostsystem      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/network [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/nsx     [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/ovfdeploy       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/provider        [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/resourcepool    [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/spbm    [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/storagepod      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/structure       [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/testhelper      [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/utils   [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vappcontainer   [no test files]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/viapi   0.240s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualdisk     0.588s [no tests to run]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/virtualmachine  [no test files]
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/helper/vsansystem      [no test files]
=== RUN   TestDiskCapacityInGiB
=== RUN   TestDiskCapacityInGiB/capacityInBytes_-_integer_GiB
=== RUN   TestDiskCapacityInGiB/capacityInKB_-_integer_GiB
2021/04/24 12:04:28 [DEBUG] diskCapacityInGiB: capacityInBytes missing for for disk-0-0, falling back to capacityInKB
=== RUN   TestDiskCapacityInGiB/capacityInBytes_-_non-integer_GiB
=== RUN   TestDiskCapacityInGiB/capacityInKB_-_non-integer_GiB
2021/04/24 12:04:28 [DEBUG] diskCapacityInGiB: capacityInBytes missing for for disk-0-0, falling back to capacityInKB
--- PASS: TestDiskCapacityInGiB (0.00s)
    --- PASS: TestDiskCapacityInGiB/capacityInBytes_-_integer_GiB (0.00s)
    --- PASS: TestDiskCapacityInGiB/capacityInKB_-_integer_GiB (0.00s)
    --- PASS: TestDiskCapacityInGiB/capacityInBytes_-_non-integer_GiB (0.00s)
    --- PASS: TestDiskCapacityInGiB/capacityInKB_-_non-integer_GiB (0.00s)
PASS
ok      github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/virtualdevice  0.296s
?       github.com/hashicorp/terraform-provider-vsphere/vsphere/internal/vmworkflow     [no test files]

Release Note

Release note for CHANGELOG:

Fix `Invalid operation for device '0'` error when cloning template with non-integer GiB disk size.

References

@ghost ghost added the size/s Relative Sizing: Small label Apr 24, 2021
@hashicorp-cla
Copy link

hashicorp-cla commented Apr 24, 2021

CLA assistant check
All committers have signed the CLA.

* Fix the error `Invalid operation for device '0'` when cloning a virtual
  machine template with a disk whose size is not an multiple of 1024^3
  bytes, by ensuring that the calculated disk capacity is rounded up
  rather than down.
Copy link
Contributor

@koikonom koikonom left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@koikonom koikonom merged commit bdfc368 into hashicorp:master Apr 28, 2021
@isometry isometry deleted the fix-disk-capacity-calculation branch April 30, 2021 18:30
@ghost
Copy link

ghost commented May 29, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
size/s Relative Sizing: Small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants