feat(storagecontrol): add anywhere cache samples for python#14155
feat(storagecontrol): add anywhere cache samples for python#14155nidhiii-27 wants to merge 2 commits into
Conversation
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 set of Python scripts for managing the lifecycle of Anywhere Caches in Google Cloud Storage, including creation, retrieval, listing, updating, and state transitions. A comprehensive test suite is also provided. Reviewer feedback suggests using the client library's built-in path helpers for resource names, implementing argparse for more robust command-line argument parsing, and correcting type hints for the capsys fixture in tests. It was also noted that the update test should use a different value than the creation step to effectively verify the update operation.
| project_path = storage_control_client.common_project_path("_") | ||
| bucket_path = f"{project_path}/buckets/{bucket_name}" |
There was a problem hiding this comment.
Use the client's built-in path helper methods instead of manual string concatenation for resource names. This is more idiomatic and less error-prone.
| project_path = storage_control_client.common_project_path("_") | |
| bucket_path = f"{project_path}/buckets/{bucket_name}" | |
| bucket_path = storage_control_client.bucket_path("_", bucket_name) |
|
|
||
|
|
||
| def test_anywhere_cache_lifecycle( | ||
| capsys: pytest.LogCaptureFixture, ubla_enabled_bucket: storage.Bucket |
There was a problem hiding this comment.
| anywhere_cache_id=anywhere_cache_id, admission_policy="admit-on-second-miss" | ||
| ) | ||
| out, _ = capsys.readouterr() | ||
| assert anywhere_cache_id in out | ||
| assert "admit-on-second-miss" in out |
There was a problem hiding this comment.
The update test currently uses the same admission_policy value as the creation step. To effectively test the update functionality, use a different value such as "admit-on-first-miss" and update the assertion accordingly.
| anywhere_cache_id=anywhere_cache_id, admission_policy="admit-on-second-miss" | |
| ) | |
| out, _ = capsys.readouterr() | |
| assert anywhere_cache_id in out | |
| assert "admit-on-second-miss" in out | |
| anywhere_cache_id=anywhere_cache_id, admission_policy="admit-on-first-miss" | |
| ) | |
| out, _ = capsys.readouterr() | |
| assert anywhere_cache_id in out | |
| assert "admit-on-first-miss" in out |
Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
This PR adds the following samples:
CreateAnywhereCache
GetAnywhereCache
ListAnywhereCaches
UpdateAnywhereCache
PauseAnywhereCache
ResumeAnywhereCache
DisableAnywhereCache