feat(storagecontrol): add anywhere cache samples#14265
Conversation
|
Here is the summary of changes. You are about to add 7 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces new Python snippets for managing Google Cloud Storage Control Anywhere Caches, including operations to create, disable, get, list, pause, resume, and update caches, along with a comprehensive integration test verifying their lifecycle. The review feedback points out a critical issue in anywhere_cache_disable.py where the long-running operation is not awaited. This causes incorrect console output and can lead to flaky tests during cleanup, as the cache may not be fully disabled before bucket deletion. A code suggestion was provided to wait for the operation to complete.
| response = storage_control_client.disable_anywhere_cache(request=request) | ||
|
|
||
| print(f"Disabled anywhere cache: {response.name}") |
There was a problem hiding this comment.
The disable_anywhere_cache method returns a Long-Running Operation (google.longrunning.Operation) rather than the AnywhereCache resource directly.
Currently, the code does not wait for this operation to complete. This has two major issues:
- Incorrect Output:
response.namewill print the operation's resource path (e.g.,.../anywhereCaches/{zone}/operations/{operation_id}) instead of the disabled cache's resource path. (Note: The test assertionassert f"Disabled anywhere cache: {cache_name}" in outaccidentally passes because the operation path contains the cache path as a prefix). - Flaky/Failing Tests: Because the operation is asynchronous and not awaited, the cache is not fully disabled when the function returns. When the test teardown runs immediately after, the bucket deletion will fail because the cache is still in the process of being disabled.
Please update the code to wait for the operation to complete using operation.result() before printing the result.
| response = storage_control_client.disable_anywhere_cache(request=request) | |
| print(f"Disabled anywhere cache: {response.name}") | |
| operation = storage_control_client.disable_anywhere_cache(request=request) | |
| print("Waiting for operation to complete...") | |
| response = operation.result() | |
| print(f"Disabled anywhere cache: {response.name}") |
Implement Anywhere Cache (Rapid Cache) lifecycle operations (create, get, list, update, pause, resume, disable) in GCS Python samples.