Skip to content

feat(storagecontrol): add anywhere cache samples for python#14155

Draft
nidhiii-27 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
nidhiii-27:jules-3252669075971440226-51e2439e
Draft

feat(storagecontrol): add anywhere cache samples for python#14155
nidhiii-27 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
nidhiii-27:jules-3252669075971440226-51e2439e

Conversation

@nidhiii-27
Copy link
Copy Markdown
Contributor

This PR adds the following samples:
CreateAnywhereCache
GetAnywhereCache
ListAnywhereCaches
UpdateAnywhereCache
PauseAnywhereCache
ResumeAnywhereCache
DisableAnywhereCache

Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label May 12, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread storagecontrol/anywhere_cache_create.py Outdated
Comment on lines +31 to +32
project_path = storage_control_client.common_project_path("_")
bucket_path = f"{project_path}/buckets/{bucket_name}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Comment thread storagecontrol/anywhere_cache_create.py
Comment thread storagecontrol/anywhere_cache_test.py Outdated


def test_anywhere_cache_lifecycle(
capsys: pytest.LogCaptureFixture, ubla_enabled_bucket: storage.Bucket
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The capsys fixture should be type-hinted as pytest.CaptureFixture. pytest.LogCaptureFixture is intended for the caplog fixture.

Suggested change
capsys: pytest.LogCaptureFixture, ubla_enabled_bucket: storage.Bucket
capsys: pytest.CaptureFixture, ubla_enabled_bucket: storage.Bucket

Comment thread storagecontrol/anywhere_cache_test.py Outdated
Comment on lines +53 to +57
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant