Skip to content

fix(vm): fall back on invalid image alias doc#33429

Open
rohan-patnaik wants to merge 1 commit into
Azure:devfrom
rohan-patnaik:fix-vm-image-alias-json-fallback
Open

fix(vm): fall back on invalid image alias doc#33429
rohan-patnaik wants to merge 1 commit into
Azure:devfrom
rohan-patnaik:fix-vm-image-alias-json-fallback

Conversation

@rohan-patnaik
Copy link
Copy Markdown

Fixes #33162

Summary

This makes az vm image list fall 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.py
  • git diff --check

Note: I also tried the focused pytest for the new test, but the local venv is missing vcr, required by azure-cli-testsdk during test collection.

Copilot AI review requested due to automatic review settings May 22, 2026 08:52
@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Hi @rohan-patnaik,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Breaking Change Starting...

Thanks for your contribution!

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label May 22, 2026
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

Thank you for your contribution @rohan-patnaik! We will review the pull request and get back to you soon.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')
@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented May 22, 2026

vm

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented May 22, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

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

Labels

act-observability-squad Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'az vm image list' crashes

5 participants