feat(storagecontrol): Added samples for Anywhere Cache.#14020
Conversation
Implemented create, get, list, update, pause, resume, and disable anywhere cache snippets. Added integration tests. API Reference: https://github.com/googleapis/google-cloud-cpp/pull/15134/changes Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive set of Python code samples for managing Google Cloud Storage Control Anywhere Caches, including operations for creation, retrieval, listing, updating, pausing, resuming, and disabling. It also includes an integration test suite. Review feedback highlights a potential issue with the test's retry mechanism, where a non-idempotent test function decorated with a backoff could fail upon retry due to resource conflicts. There is also a suggestion to improve test assertions to verify all output fields from the retrieval sample.
| @backoff.on_exception( | ||
| backoff.expo, exceptions.InternalServerError, max_tries=3 | ||
| ) |
There was a problem hiding this comment.
Applying @backoff to the entire test function is problematic because the test is not idempotent. If the create_anywhere_cache operation succeeds but a subsequent step (like get or update) fails with an InternalServerError, the retry will attempt to call create_anywhere_cache again with the same bucket and zone. This will result in a 409 AlreadyExists error, causing the test to fail on the retry attempt rather than successfully retrying the failed step.
Consider applying the backoff to individual operations or ensuring the test can handle existing resources. Additionally, it is recommended to include exceptions.ServiceUnavailable (503) in the list of retryable exceptions.
| get_anywhere_cache.get_anywhere_cache(bucket_name, ZONE) | ||
| out, _ = capsys.readouterr() | ||
| expected = ( | ||
| f"Anywhere Cache: " | ||
| f"projects/_/buckets/{bucket_name}/anywhereCaches/{ZONE}" | ||
| ) | ||
| assert expected in out |
There was a problem hiding this comment.
The test for get_anywhere_cache only verifies that the resource name is printed. However, the get_anywhere_cache.py sample also prints the Admission Policy and State. To ensure the sample is fully functional and the output is as expected, consider adding assertions for these additional printed lines.
Implemented create, get, list, update, pause, resume, and disable anywhere cache snippets. Added integration tests.