Repository navigation
Conversation
The Compute API raises HttpError when it rejects an instance insert (bad config, missing image, quota, rate limit, server error) instead of returning an error inside the operation. start_test() only checked the returned operation, so the exception escaped to gcp_instance(), which logs it and leaves the test pending. A permanent error was retried on every cron run and the test never failed or reported back to GitHub. Catch HttpError around create_instance() and convert it to the same error shape a failed operation has, so the existing retry rules and messages apply. 429 and 5xx responses, quota and rate limit errors are retried; anything else marks the test as failed.
kaihere14
requested review from
canihavesomecoffee and
thealphadollar
as code owners
November 16, 2026 20:08
The four start_test HttpError tests repeated the same decorator stack and setup, which SonarCloud counted as duplicated new code. They now share one helper that patches with an ExitStack and raises from compute.instances().insert().execute(), and the cases run as subtests. The gcp_error_from_http_error unit tests are a single table as well.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



In raising this pull request, I confirm the following (please check boxes):
My familiarity with the project is as follows (check one):
What happens today
When the platform starts a test,
start_test()callscreate_instance(), which asks Google Cloud to create the VM withcompute.instances().insert(...).execute().The code after that call expects any failure to come back as an
errorfield in the returned result. But when Google Cloud rejects the request outright, the client library does not return anything. It raises anHttpError. That happens for quota and rate limits, server errors, a wrong machine type or config, or a missing image family (thegetFromFamily(...).execute()calls increate_instance()can raise the same way).Nothing in
start_test()catches that exception. The artifact download a few lines above it is wrapped intry/except, but the VM creation is not. The exception goes up to the catch-all added togcp_instance()in #1244, which logs "could not be started, will retry on next cron run" and leaves the test pending.For a temporary problem that is fine. For a permanent one it is not: the test is retried every 10 minutes, forever. It never gets marked as failed, the PR author never sees a status on GitHub, and every retry writes the test XML files and downloads the build artifact again.
The tests did not catch this because every test that mocks
create_instanceonly sets areturn_value. None of them makes it raise.What should happen
An error that Google Cloud raises should be treated the same way as one it returns:
How this PR fixes it
start_test()now wraps thecreate_instance()call intry/except HttpError. It logs the error and passes it to the existingif 'error' in operation:check, so there is no second copy of the retry-or-fail logic.gcp_error_from_http_error(), turns theHttpErrorinto the same{'error': {'errors': [{'code': ..., 'message': ...}]}}shape that a failed operation has. The error body uses camelCase reasons, so the known ones are mapped to the codes the platform already uses:quotaExceeded->QUOTA_EXCEEDED(retried)rateLimitExceeded,userRateLimitExceeded->RATE_LIMIT_EXCEEDED(new, retried)backendError,internalError->BACKEND_ERROR(new, retried)notFound->RESOURCE_NOT_FOUND(fails the test)alreadyExists->RESOURCE_ALREADY_EXISTS(fails the test)HTTP_<status>.RATE_LIMIT_EXCEEDEDandBACKEND_ERRORare added toGCP_RETRYABLE_ERRORSandGCP_ERROR_MESSAGES.Only
HttpErroris caught. Other exceptions, such as network errors, still reach the catch-all ingcp_instance()and are retried on the next cron run, as before.Tests
TestGcpErrorFromHttpErrorchecks the mapping as a table of subtests: quota, rate limit, not found, already exists, an unknown reason, a 503, a 429 with an HTML body, and a 400 with a plain-text body. A second test checks that the raw GCP message is kept for the log but not shown to the user.TestVMCreationVerificationmakecompute.instances().insert().execute()raise a realHttpError, withcreate_instanceitself left unmocked so the real call path is covered:GcpInstancerow added, no wait on an operation;All 5
start_testcases fail on currentmaster(theHttpErrorescapesstart_test) and pass with this change. The full suite passes (819 tests), and isort, pycodestyle, pydocstyle, mypy and dodgy are clean.