Skip to content

fix: convert device_id via int in attach_volume to avoid a panic - #342

Open
nagaboinaramgopal wants to merge 1 commit into
apache:mainfrom
nagaboinaramgopal:fix/attach-volume-device-id-panic
Open

fix: convert device_id via int in attach_volume to avoid a panic#342
nagaboinaramgopal wants to merge 1 commit into
apache:mainfrom
nagaboinaramgopal:fix/attach-volume-device-id-panic

Conversation

@nagaboinaramgopal

@nagaboinaramgopal nagaboinaramgopal commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Description

device_id on cloudstack_attach_volume is a schema.TypeInt, which the SDK returns as a Go int, but the create path asserted it as int64:

p.SetDeviceid(v.(int64))

so attaching a volume with an explicit device_id panics the provider with interface conversion: interface {} is int, not int64. Fixed by asserting int and converting to int64.

Testing

Added a unit test TestAttachVolumeDeviceIdDoesNotPanic that runs the create function with device_id set against an unreachable endpoint. It needs no live CloudStack:

go test ./cloudstack/ -run TestAttachVolumeDeviceIdDoesNotPanic

It panics against the current code and passes with the fix.

device_id is a schema.TypeInt, which the SDK returns as a Go int, so the create path asserted v.(int64) and panicked with "interface conversion: interface {} is int, not int64" whenever a volume was attached with an explicit device_id. Assert int and convert to int64.
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 this pull request may close these issues.

1 participant