danielwardega7777 opened a new pull request, #77690:
URL: https://github.com/apache/airflow/pull/77690

   Several delete handlers in the Google system test resource cleanup CLI 
(`providers/google/tests/system/google/resources_cleanup`) fail silently when 
`gcloud` or `curl` exits with errors—printing `Resource deleted!` even when 
deletion fails—and cannot consistently resolve project IDs when Cloud Asset 
Inventory returns numeric project numbers or `_` wildcards.
   
   This PR adds the shared, backwards-compatible foundation so individual 
handler fixes can follow in small, per-handler PRs:
   
   - **Base handler & CLI (`commands/cmd_delete.py`, `handlers/_base.py`):**
     - Pass `project_id=cfg.project_id` when instantiating delete handlers 
(`BaseDeleteHandler(project_id=None)`).
     - Automatically forward `project_id=self.project_id` in 
`BaseDeleteHandler._call_deleter()` when a deleter declares a `project_id` 
parameter, while keeping existing 2-argument deleters backwards-compatible.
   - **Shared helpers (`helpers.py`):**
     - Add `resolve_project_id`, `build_project_flag`, and 
`resolve_resource_path` to ignore numeric Cloud Asset Inventory project numbers 
and `_` wildcards, falling back to `resource["project"]` or the handler's 
configured `project_id`.
     - Add `check` and `ignore_not_found` (including `curl --fail` HTTP 404 
responses) to `run_command_async` and `curl` so real failures surface instead 
of logging `Resource deleted!`, while already-deleted resources log `Resource 
no longer exists.`.
     - Update `curl()` to authenticate via `google.auth.default()`, use 
HTTP/1.1 with retries, and pass `x-goog-user-project` when `quota_project_id` 
is configured on credentials.
   - **Unit tests (`test_cmd_delete.py`, `test_helpers.py`):** Cover 
`project_id` forwarding, project/path resolution helpers, checked command / 
`ignore_not_found` behavior, credential refresh, and `curl()` options.
   
   ### Verification
   - `uv run --project providers/google pytest 
providers/google/tests/unit/google/resources_cleanup/`: 85 passed.
   - `breeze run mypy providers/google/tests/system/google/resources_cleanup 
providers/google/tests/unit/google/resources_cleanup`: passed (`Success: no 
issues found in 43 source files`).
   - `ruff format --check` and `ruff check`: passed.
   - **Manual side-by-side verification on a test GCP project (`main` vs. this 
branch):**
     - Confirmed backwards compatibility across all 20 registered delete 
handlers (`get_delete_handlers()` instantiated cleanly with `project_id`), and 
verified an untouched legacy handler (`ComputeDeleteHandler` via 
`cmd_delete.handle_asset_type`) deleted a temporary Compute Engine disk 
identically on both branches.
     - Verified `resolve_project_id`, `build_project_flag`, and 
`resolve_resource_path` against real Cloud Asset Inventory entries containing 
numeric project numbers and bucket path formats.
     - Verified `helpers.curl()` against a live Cloud DLP `InspectTemplate`: on 
`main`, `gcloud auth print-access-token` failed with HTTP 401 while `curl` 
exited `0` and returned `None` (leaving the template orphaned); on this branch, 
ADC + `x-goog-user-project` deleted the template cleanly, a repeat DELETE (HTTP 
404) logged `Resource no longer exists.` and returned `False`, and a malformed 
request (HTTP 400) raised `CalledProcessError`.
     - Verified `run_command_async(..., check=True, ignore_not_found=True)` 
against a live GCS bucket: deleted the bucket cleanly, treated a repeat delete 
(`not found: 404`) as `Resource no longer exists.` (`False`), and raised 
`CalledProcessError` on an invalid CLI flag (whereas `main` silently returned 
`None` on both exit codes 1 and 2).
     - Cleaned up all temporary test resources afterward and verified none 
remained.
   
   *(No newsfragment added—changes are limited to Google provider system-test 
cleanup tooling under `providers/google/tests/`.)*
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Jetski (Gemini) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to