Wait for GCP volume attach/detach operations; fix attachments check#334
Merged
Conversation
GCPVolume.attach and detach issued attachDisk/detachDisk but never waited for the asynchronous GCP operation to complete, unlike every other mutating GCP operation. detach() could therefore return before the disk was released; and because attach() did not settle either, detach() could read an instance resource whose disk list did not yet include the disk, match no device, and silently no-op -- leaving the volume attached and timing out test waits on the AVAILABLE state. Wait for both operations to finish. Also fix GCPVolume.attachments, which tested len(self._volume) -- the number of keys in the disk dict -- instead of the length of the 'users' list, producing a spurious "attached to multiple instances" warning.
The CloudVE/moto fix-describe-instances-az-filter branch no longer exists, so the previous pin failed to install in CI. The fix (getmoto/moto#10066) is now merged into upstream moto master, so install from there until 5.2.3 is released.
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.
Summary
Fixes
test_attach_detach_volumefailing on the GCP integration job, where a detached disk stayedin-useuntil the wait timed out and teardown then failed withresourceInUseByAnotherResource.Root cause
GCPVolume.attachandGCPVolume.detachissuedattachDisk/detachDiskbut never waited for the asynchronous GCP operation to complete — unlike every other mutating GCP operation in the provider (which all callself._provider.wait_for_operation(...)).Because
attach()returned before its operation settled, by the timedetach()read the instance resource the disk list could still be eventually-consistent and not yet contain the just-attached disk.detach()matches the device by scanninginstance_data['disks']fordisk['source'] == self.id; finding nothing, it hit the silentif not device_name: returnpath and issued nodetachDiskcall — leaving the disk attached. No error surfaced, so the volume simply never leftin-useand the test'swait_for([AVAILABLE])timed out.Changes
attach()anddetach()nowwait_for_operation(response, zone=...)after.execute(), so the disk is actually attached/released (and the instance disk list is consistent) before returning.GCPVolume.attachments, which testedlen(self._volume)— the number of keys in the disk dict — instead oflen(self._volume['users']), producing a spurious "attached to multiple instances" warning.Testing
The existing
tests/test_block_store_service.py::test_attach_detach_volumeis the regression test; it requires the GCP integration job (credentials) to verify, as there is no GCP mock. Lint passes and the module imports cleanly.Pre-existing issue, independent of any object-store / multipart work.