fix(compute): pass ip address to static IP entrypoint - #14614
aniruddhaadak80 wants to merge 1 commit into
Conversation
Fixes GoogleCloudPlatform#14611 Signed-off-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request updates the assign_static_external_ip_to_new_vm function call in both the recipe and snippet files to use the ip_address parameter instead of external_ipv4 and external_access. It also introduces a new AST-based test to verify this entrypoint call. Feedback suggests resolving the path of __file__ to an absolute path before accessing its parents in the test file to prevent potential IndexError issues depending on how the test is executed.
| import ast | ||
| from pathlib import Path | ||
|
|
||
| ROOT = Path(__file__).parents[2] |
There was a problem hiding this comment.
Using Path(__file__).parents[2] without resolving the path first can raise an IndexError if the test is executed from within the test directory (where __file__ might be a relative path with fewer than 3 parent directories, e.g., test_static_ip_entrypoint.py). Resolving the path to an absolute path first using .resolve() ensures that .parents[2] always resolves correctly.
| ROOT = Path(__file__).parents[2] | |
| ROOT = Path(__file__).resolve().parents[2] |
Description
Fixes #14611
The static external IP sample entry point passed
external_ipv4andexternal_accesskeyword arguments to a function that accepts onlyip_address. Both the canonical Compute client-library recipe and its generated snippet therefore raisedTypeErrorbefore instance creation. This change updates the recipe to pass the address through the supported argument and regenerates the checked-in snippet with SGS.A dependency-free regression test executes both entry-point call expressions against the declared function signature, covering the source recipe and generated output.
Validation:
python -m pytest compute/client_library/snippets/tests/test_static_ip_entrypoint.py -q— 1 passedTypeError: ... unexpected keyword argument 'external_ipv4'python -m ruff check compute/client_library/recipes/instances/ip_address/assign_static_external_ip_to_new_vm.py compute/client_library/snippets/instances/ip_address/assign_static_external_ip_to_new_vm.py compute/client_library/snippets/tests/test_static_ip_entrypoint.py— passedpython -m black --check compute/client_library/snippets/tests/test_static_ip_entrypoint.py— passedpython -m mypy --implicit-optional --follow-imports=skip --ignore-missing-imports compute/client_library/snippets/instances/ip_address/assign_static_external_ip_to_new_vm.py— no issues foundpython -m compileall -qon the changed Python files — passedChecklist
Testing
Compliance & Style
Post-Approval Actions