fix(vm): fall back on invalid image alias doc#33429
Conversation
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Hi @rohan-patnaik, |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution @rohan-patnaik! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a fallback to the local VM image alias doc when the remote alias document returns invalid JSON, and introduces a regression test to cover that scenario.
Changes:
- Handle invalid JSON from the remote alias doc by logging a warning and falling back to the embedded local alias doc.
- Add a unit test that mocks a 200 response with non-JSON content and verifies the fallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/vm/_actions.py |
Adds JSON parsing error handling and local-copy fallback when remote content is not valid JSON. |
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_image.py |
Adds a test ensuring invalid JSON from the alias doc endpoint falls back to local aliases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| dic = json.loads(response.content.decode()) | ||
| try: | ||
| dic = json.loads(response.content.decode()) | ||
| except json.JSONDecodeError as ex: |
|
|
||
| images = load_images_from_aliases_doc(cli_ctx) | ||
|
|
||
| self.assertEqual(images[0]['urnAlias'], 'AzureLinux4') |
|
vm |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
Fixes #33162
Summary
This makes
az vm image listfall back to the bundled image alias document when the remote alias document returns HTTP 200 but the body is not valid JSON.Why
Today that path raises a raw
JSONDecodeError, which makes the command fail with a Python traceback. If the alias endpoint is intercepted or returns a small error body, the CLI should behave like the existing fetch-failure paths and use the local alias copy instead.Test plan
PYTHONPATH=src/azure-cli:src/azure-cli-core .venv/bin/python -m py_compile src/azure-cli/azure/cli/command_modules/vm/_actions.py src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_image.pygit diff --checkNote: I also tried the focused pytest for the new test, but the local venv is missing
vcr, required byazure-cli-testsdkduring test collection.