fix: detect a disk's VM change with the correct schema key - #346
Open
nagaboinaramgopal wants to merge 1 commit into
Open
fix: detect a disk's VM change with the correct schema key#346nagaboinaramgopal wants to merge 1 commit into
nagaboinaramgopal wants to merge 1 commit into
Conversation
The disk update checked HasChange("virtual_machine"), but the schema key is virtual_machine_id, so a change to the attached VM was never detected: the detach branch was skipped, the disk stayed attached to the old VM, and it was never moved to the new one. Use virtual_machine_id. That branch being unreachable also hid a second bug: the detach fallback stopped and restarted the current virtual_machine_id, but during a VM change the disk is still on the old VM, so stop and restart the source VM instead.
nagaboinaramgopal
force-pushed
the
fix/disk-haschange-vm-key
branch
from
September 7, 2026 19:56
ced7fb6 to
c234577
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The disk update detects a change of the attached VM to trigger a detach and re-attach, but it checked
d.HasChange("virtual_machine")and the schema key isvirtual_machine_id.HasChangeon a key that does not exist is always false, so changingvirtual_machine_idnever ran the detach branch: the disk stayed attached to the old VM, and because attach is skipped when the volume is already attached, it was never moved to the new VM. Fixed to checkvirtual_machine_id.Making that branch reachable exposed a second bug in the detach fallback. When a plain detach fails, the fallback stops the VM to force the detach and then restarts it, using the current
virtual_machine_id. During a VM change that value is the new VM, but the disk is still on the old one, so the fallback would stop the wrong VM. It now uses the old value (viaGetChange) whenvirtual_machine_idchanged.Testing
Two unit tests, no live CloudStack:
TestDiskUpdateDetachesWhenVirtualMachineChangesasserts avirtual_machine_idchange reaches the detach path; before the fix it falls through to attach.TestDiskUpdateDetachFallbackStopsSourceVMuses a stub server and asserts that when the plain detach fails, the fallback stops the source VM (the old id), not the destination.