[VM] az vm delete: raise ResourceNotFoundError when VM or resource group does not exist#33795
Conversation
|
Hi @copilot, |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
…oup does not exist
Live test results —
|
|
VM |
There was a problem hiding this comment.
CI Failure Summary
The automated validation pipeline for this PR has 4 failing checks (with 11 checks still pending/queued as of this review, and 65 passing). The live-test workflow for the changed test file(s) already completed successfully.
Failed checks:
Azure.azure-cli (Test Homebrew Formula)— https://github.com/Azure/azure-cli/runs/89914205503Azure.azure-cli Full Test— https://github.com/Azure/azure-cli/runs/89914052842 (Build #20260727.21 had test failures)Azure.azure-cli Full Test (Automation Full Test Python312 Profile Latest instance2)— https://github.com/Azure/azure-cli/runs/89914049410Azure.azure-cli Full Test (Automation Full Test Python314 Profile Latest instance2)— https://github.com/Azure/azure-cli/runs/89912150631
Please open the linked Azure Pipelines run logs for each failed check, identify the root cause (likely a test assertion depending on the previous az vm delete behavior/error type, or a recording mismatch caused by switching to ResourceNotFoundError), and update the implementation and/or the affected test cases (including any recorded test fixtures) so all Automation Full Test profiles and the Homebrew Formula check pass. Push a new commit once done.
Posted by agent-assist (autonomous bug-fix pipeline).
|
@copilot the automated CI and live-test review on this PR found failures. Please look into the requested changes here: #33795 (review) and push a fix. Posted by agent-assist (autonomous bug-fix pipeline). |
…eaking VCR recordings
Investigated the CI failures and found the root cause: the previous Fix (commit
|
Live test results —
|
There was a problem hiding this comment.
Automated Review Summary
Result: PASS ✅
- Live test (azdev --live): success
- CI checks: 18/18 passed, 0 failed, 0 pending
All automated validation for this PR has passed. Flipping out of draft for human review.
Posted by agent-assist (autonomous bug-fix pipeline).
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot could not run the full agentic suite for this review because it was automatically requested on a bot-authored pull request. Request a review from Copilot under Reviewers to retry with the full agentic suite. Improved support for bot-authored pull requests is coming soon.
Adds a custom vm delete operation to change how HTTP 204 responses are handled, and includes a unit test asserting the new behavior.
Changes:
- Introduce
VMDeleteoperation overriding the 204-response handler to raiseResourceNotFoundError. - Register
vm deleteto use the new operation implementation. - Add a unit test verifying the raised error contains VM and resource group names.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py | Adds a unit test asserting on_204 raises ResourceNotFoundError. |
| src/azure-cli/azure/cli/command_modules/vm/operations/vm.py | Introduces VMDelete and overrides on_204 to raise ResourceNotFoundError. |
| src/azure-cli/azure/cli/command_modules/vm/commands.py | Registers vm delete to use the new VMDelete operation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class VMDelete(_VMDelete): | ||
| class VirtualMachinesDelete(_VMDelete.VirtualMachinesDelete): | ||
| def on_204(self, session): | ||
| from azure.cli.core.azclierror import ResourceNotFoundError | ||
| raise ResourceNotFoundError( | ||
| "The VM '{}' under resource group '{}' was not found.".format( | ||
| str(self.ctx.args.name), str(self.ctx.args.resource_group) | ||
| ) | ||
| ) |
| class TestVMDeleteOn204(unittest.TestCase): | ||
| """Unit tests for VMDelete.VirtualMachinesDelete.on_204 behavior.""" | ||
|
|
||
| def test_on_204_raises_resource_not_found_error(self): | ||
| from azure.cli.core.azclierror import ResourceNotFoundError | ||
| from azure.cli.command_modules.vm.operations.vm import VMDelete | ||
|
|
||
| cli_ctx = DummyCli() | ||
| vm_delete = VMDelete(cli_ctx=cli_ctx) | ||
|
|
||
| # Simulate the ctx that would be set during command execution | ||
| ctx = mock.MagicMock() | ||
| ctx.args.name = "nonexistent-vm" | ||
| ctx.args.resource_group = "nonexistent-rg" | ||
|
|
||
| # Instantiate the inner operation class with the mocked ctx | ||
| vm_delete_op = VMDelete.VirtualMachinesDelete(ctx=ctx) | ||
|
|
||
| with self.assertRaises(ResourceNotFoundError) as cm: | ||
| vm_delete_op.on_204(session=mock.MagicMock()) |
Related command
az vm deleteDescription
az vm deletesilently exits with code 0 when the target VM or resource group does not exist. Azure's REST API returns HTTP 204 for DELETE on non-existent resources (idempotent), so the CLI treated it as success — misleading users and automation pipelines.Changes:
vm/operations/vm.py: AddedVMDeleteclass extending_VMDeletethat overridespre_operationsto callVMShowbefore deletion. If the VM is not found (HTTP 404), raisesResourceNotFoundErrorwith a descriptive message.vm/commands.py: RegistersVMDeletein the command table to override the auto-generatedvm deletecommand.vm/tests/latest/test_custom_vm_commands.py: Unit tests covering the non-existent VM path and the happy path.Testing Guide
History Notes
[VM]
az vm delete: RaiseResourceNotFoundErrorwhen the specified VM or resource group does not exist.This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.