Skip to content

fix(compute): pass ip address to static IP entrypoint - #14614

Open
aniruddhaadak80 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
aniruddhaadak80:fix/compute-static-ip-entrypoint
Open

aniruddhaadak80 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
aniruddhaadak80:fix/compute-static-ip-entrypoint

Conversation

@aniruddhaadak80

Copy link
Copy Markdown

Description

Fixes #14611

The static external IP sample entry point passed external_ipv4 and external_access keyword arguments to a function that accepts only ip_address. Both the canonical Compute client-library recipe and its generated snippet therefore raised TypeError before 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 passed
  • Pre-fix entry-point execution — reproduced TypeError: ... 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 — passed
  • python -m black --check compute/client_library/snippets/tests/test_static_ip_entrypoint.py — passed
  • python -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 found
  • python -m compileall -q on the changed Python files — passed
  • Live Compute Engine execution was not run because this regression is isolated to the entry-point call signature.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

Fixes GoogleCloudPlatform#14611

Signed-off-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
@aniruddhaadak80
aniruddhaadak80 requested review from a team as code owners September 25, 2026 04:05
@product-auto-label product-auto-label Bot added api: compute Issues related to the Compute Engine API. samples Issues that are directly related to samples. labels Sep 25, 2026

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

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.

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]

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

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.

Suggested change
ROOT = Path(__file__).parents[2]
ROOT = Path(__file__).resolve().parents[2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: compute Issues related to the Compute Engine API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static external IP sample entry point passes invalid keyword arguments

1 participant