Skip to content

Commit

Permalink
fix(gce): fix how gce checks for an operation done (#440)
Browse files Browse the repository at this point in the history
Previous implementation relied on the __repr__ or __str__ representation
of an internal google sdk enum, which, under some versions of the sdk is
`Status.DONE` and under others is an integer. Running cloud-init
integration tests with Python 3.12.3 raises:

E pycloudlib.errors.PycloudlibError: Expected DONE state, but found
2104194 after waiting 300 seconds. Check GCE console for more details.

Use the enum variant DONE for proper comparison. Both,
ZoneOperationsClient[0] and GlobalOperationsClient[1]'s get method
return an instance of Operation[2] which has an instance of Status[3] as
status property.

Refs:

[0]
https://cloud.google.com/python/docs/reference/compute/1.11.0/google.cloud.compute_v1.services.zone_operations.ZoneOperationsClient#google_cloud_compute_v1_services_zone_operations_ZoneOperationsClient_get
[1]
https://cloud.google.com/python/docs/reference/compute/1.11.0/google.cloud.compute_v1.services.global_operations.GlobalOperationsClient#google_cloud_compute_v1_services_global_operations_GlobalOperationsClient_get
[2]
https://cloud.google.com/python/docs/reference/compute/1.11.0/google.cloud.compute_v1.types.operation
[3]
https://cloud.google.com/python/docs/reference/compute/1.11.0/google.cloud.compute_v1.types.Operation.Status
  • Loading branch information
aciba90 authored Oct 11, 2024
1 parent 24aea02 commit 4ed2b61
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1!10.0.3
1!10.0.4
2 changes: 1 addition & 1 deletion pycloudlib/gce/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def _wait_for_operation(
except GoogleAPICallError as e:
raise_on_error(e)
else:
if str(response.status) == "Status.DONE":
if response.status == compute_v1.types.Operation.Status.DONE:
break
time.sleep(1)
else:
Expand Down

0 comments on commit 4ed2b61

Please sign in to comment.