Skip to content

Wait for GCP volume attach/detach operations; fix attachments check#334

Merged
nuwang merged 2 commits into
mainfrom
fix-gcp-volume-attach-detach
Jun 27, 2026
Merged

Wait for GCP volume attach/detach operations; fix attachments check#334
nuwang merged 2 commits into
mainfrom
fix-gcp-volume-attach-detach

Conversation

@nuwang

@nuwang nuwang commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes test_attach_detach_volume failing on the GCP integration job, where a detached disk stayed in-use until the wait timed out and teardown then failed with resourceInUseByAnotherResource.

Root cause

GCPVolume.attach and GCPVolume.detach issued attachDisk / detachDisk but never waited for the asynchronous GCP operation to complete — unlike every other mutating GCP operation in the provider (which all call self._provider.wait_for_operation(...)).

Because attach() returned before its operation settled, by the time detach() 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 scanning instance_data['disks'] for disk['source'] == self.id; finding nothing, it hit the silent if not device_name: return path and issued no detachDisk call — leaving the disk attached. No error surfaced, so the volume simply never left in-use and the test's wait_for([AVAILABLE]) timed out.

Changes

  1. attach() and detach() now wait_for_operation(response, zone=...) after .execute(), so the disk is actually attached/released (and the instance disk list is consistent) before returning.
  2. Fix GCPVolume.attachments, which tested len(self._volume) — the number of keys in the disk dict — instead of len(self._volume['users']), producing a spurious "attached to multiple instances" warning.

Testing

The existing tests/test_block_store_service.py::test_attach_detach_volume is 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.

nuwang added 2 commits June 27, 2026 16:42
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.
@nuwang nuwang merged commit aea097b into main Jun 27, 2026
3 checks passed
@nuwang nuwang deleted the fix-gcp-volume-attach-detach branch June 27, 2026 11:35
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