Skip to content

{Compute} az vm delete: Raise error when resource not found - #34316

Open
William (william051200) wants to merge 6 commits into
Azure:devfrom
william051200:vm-delete-handle
Open

William (william051200) wants to merge 6 commits into
Azure:devfrom
william051200:vm-delete-handle

Conversation

@william051200

@william051200 William (william051200) commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ❌ Action needed

Breaking Changes Tests Suppressions
️✔️ None ❌ 128/130 ️✔️ None
❌AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.14
️✔️acs
️✔️latest
️✔️3.12
️✔️3.14
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.14
️✔️ams
️✔️latest
️✔️3.12
️✔️3.14
️✔️apim
️✔️latest
️✔️3.12
️✔️3.14
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.14
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️aro
️✔️latest
️✔️3.12
️✔️3.14
️✔️backup
️✔️latest
️✔️3.12
️✔️3.14
️✔️batch
️✔️latest
️✔️3.12
️✔️3.14
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.14
️✔️billing
️✔️latest
️✔️3.12
️✔️3.14
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.14
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.14
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.14
️✔️config
️✔️latest
️✔️3.12
️✔️3.14
️✔️configure
️✔️latest
️✔️3.12
️✔️3.14
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.14
️✔️container
️✔️latest
️✔️3.12
️✔️3.14
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.14
️✔️core
️✔️latest
️✔️3.12
️✔️3.14
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.14
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.14
️✔️dls
️✔️latest
️✔️3.12
️✔️3.14
️✔️dms
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.14
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.14
️✔️find
️✔️latest
️✔️3.12
️✔️3.14
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.14
️✔️identity
️✔️latest
️✔️3.12
️✔️3.14
️✔️iot
️✔️latest
️✔️3.12
️✔️3.14
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.14
️✔️lab
️✔️latest
️✔️3.12
️✔️3.14
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️maps
️✔️latest
️✔️3.12
️✔️3.14
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.14
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.14
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.14
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.14
️✔️network
️✔️latest
️✔️3.12
️✔️3.14
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.14
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.14
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.14
️✔️profile
️✔️latest
️✔️3.12
️✔️3.14
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.14
️✔️redis
️✔️latest
️✔️3.12
️✔️3.14
️✔️relay
️✔️latest
️✔️3.12
️✔️3.14
️✔️resource
️✔️latest
️✔️3.12
️✔️3.14
️✔️role
️✔️latest
️✔️3.12
️✔️3.14
️✔️search
️✔️latest
️✔️3.12
️✔️3.14
️✔️security
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.14
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.14
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.14
️✔️sql
️✔️latest
️✔️3.12
️✔️3.14
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.14
️✔️storage
️✔️latest
️✔️3.12
️✔️3.14
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.14
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.14
️✔️util
️✔️latest
️✔️3.12
️✔️3.14
❌vm
❌latest
❌3.12
Type Test Case Error Message Line
Failed test_dedicated_host_e2e self = <azure.cli.testsdk.base.ExecutionResult object at 0x7f6f46de39b0>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7f6f49179ca0>
command = 'vm delete --name ded-host-vm -g cli_test_dedicated_host_000001 --yes'
expect_failure = False

    def in_process_execute(self, cli_ctx, command, expect_failure=False):
        from io import StringIO
        from vcr.errors import CannotOverwriteExistingCassetteException
    
        if command.startswith('az '):
            command = command[3:]
    
        stdout_buf = StringIO()
        logging_buf = StringIO()
        try:
            # issue: stderr cannot be redirect in this form, as a result some failure information
            # is lost when command fails.
>           self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/azure-cli-testsdk/azure/cli/testsdk/base.py:304: 
                                        
env/lib/python3.12/site-packages/knack/cli.py:245: in invoke
    exit_code = self.exception_handler(ex)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/init.py:153: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: in handle_main_exception
    raise ex
env/lib/python3.12/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:677: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:820: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:800: in run_job
    result = LongRunningOperation(cmd_copy.cli_ctx, 'Starting {}'.format(cmd_copy.name))(result)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:1168: in call
    result = poller.result()
             ^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:109: in result
    self.wait(timeout)
env/lib/python3.12/site-packages/azure/core/tracing/decorator.py:119: in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:131: in wait
    raise self.exception
src/azure-cli-core/azure/cli/core/aaz/poller.py:84: in start
    for polling_method in self.polling_generator:
                          ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:11218: in execute_operations
    self.pre_operations()
src/azure-cli/azure/cli/command_modules/vm/operations/vm.py:275: in pre_operations
    VMShow(cli_ctx=self.cli_ctx)(command_args={
src/azure-cli-core/azure/cli/core/aaz/command.py:154: in call
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:16841: in handler
    self.execute_operations()
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:16873: in execute_operations
    self.VirtualMachinesGet(ctx=self.ctx)()
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:16893: in call
    session = self.client.send_request(request=request, stream=False, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/client.py:107: in send_request
    session = self.pipeline.run(request, stream=stream, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:242: in run
    return first_node.send(pipeline_request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/mgmt/core/policies/base.py:95: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/policies/redirect.py:205: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/policies/retry.py:545: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/http_policy.py:112: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/base.py:130: in send
    self.sender.send(request.http_request, **request.context.options),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/azure/core/pipeline/transport/requests_basic.py:375: in send
    response = self.session.request(  # type: ignore
env/lib/python3.12/site-packages/requests/sessions.py:592: in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/requests/sessions.py:706: in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/requests/adapters.py:645: in send
    resp = conn.urlopen(
env/lib/python3.12/site-packages/urllib3/connectionpool.py:788: in urlopen
    response = self.make_request(
env/lib/python3.12/site-packages/urllib3/connectionpool.py:534: in make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/vcr/stubs/urllib3_stubs.py:20: in getresponse
    response = super().getresponse(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  

self = <VCRRequestsHTTPSConnection/mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml(host='management.azure.com', port=443) at 0x7f6f46cea630>
 = False, kwargs = {}

    def getresponse(self, 
=False, **kwargs):
        """Retrieve the response"""
        # Check to see if the cassette has a response for this request. If so,
        # then return it
        if self.cassette.can_play_response_for(self.vcr_request):
            log.info(f"Playing response for {self.vcr_request} from cassette")
            response = self.cassette.play_response(self.vcr_request)
            return VCRHTTPResponse(response, self.vcr_request.uri)
        else:
            if self.cassette.write_protected and self.cassette.filter_request(self.vcr_request):
>               raise CannotOverwriteExistingCassetteException(
                    cassette=self.cassette,
                    failed_request=self.vcr_request,
                )
E               vcr.errors.CannotOverwriteExistingCassetteException: Can't play back this request: it matches 1 recorded interaction, but that has already been played back.
E               record_mode 'once' doesn't record new requests into an existing cassette.
E               
E                 GET https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/virtualMachines/ded-host-vm?api-version=2026-04-01
E               
E               Cassette: /mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml
E                 record_mode: once
E                 match_on: method, scheme, host, port, path, custom_request_query_matcher
E                 interactions: 86 recorded, 25 played
E               
E               How to fix:
E                  If it's fine for this request to get the same response each time, set
E                   allow_playback_repeats=True [1].
E                 
 Otherwise record the extra request: run once with record_mode='new_episodes'
E                   [2].
E               
E               [1] https://vcrpy.readthedocs.io/en/latest/advanced.html#playback-repeats
E               [2] https://vcrpy.readthedocs.io/en/latest/usage.html#record-modes

env/lib/python3.12/site-packages/vcr/stubs/init.py:313: CannotOverwriteExistingCassetteException

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.DedicatedHostScenarioTest testMethod=test_dedicated_host_e2e>
resource_group = 'cli_test_dedicated_host2_000002'
resource_group_location = 'eastus'

    @AllowLargeResponse()
    @ResourceGroupPreparer(name_prefix='cli_test_dedicated_host
', location='westeurope')
    @ResourceGroupPreparer(name_prefix='cli_test_dedicated_host2
', location='eastus', key='rg2')
    def test_dedicated_host_e2e(self, resource_group, resource_group_location):
        self.kwargs.update({
            'host-group': 'my-host-group',
            'host-name': 'my-host',
            'vm-name': 'ded-host-vm'
        })
    
        # create resources
        self.cmd('vm host group create -n {host-group} -c 3 -g {rg} --tags "foo=bar"', checks=[
            self.check('name', '{host-group}'),
            self.check('platformFaultDomainCount', 3),
            self.check('tags.foo', 'bar')
        ])
    
        try:
            self.cmd('vm host create -n {host-name} --host-group {host-group} -d 2 -g {rg} '
                     '--sku DSv3-Type1 --auto-replace false --tags "bar=baz" ', checks=[
                self.check('name', '{host-name}'),
                self.check('platformFaultDomain', 2),
                self.check('sku.name', 'DSv3-Type1'),
                self.check('autoReplaceOnFailure', False),
                self.check('tags.bar', 'baz')
            ])
    
        except CLIError as e:
            if 'capacity' in str(e):
                return
    
        result = self.cmd('vm host get-instance-view --host-group {host-group} --name {host-name} -g {rg}', checks=[
            self.check('name', '{host-name}'),
        ]).get_output_in_json()
        instance_view = result["instanceView"]
        self.assertTrue(instance_view["assetId"])
        self.assertTrue(instance_view["availableCapacity"])
    
        self.cmd('vm host group get-instance-view -g {rg} -n {host-group}', checks=[
            self.exists('instanceView')
        ])
    
        host_id = self.cmd('vm host show -g {rg} -n {host-name} --host-group {host-group}').get_output_in_json()['id']
        self.kwargs.update({
            'host_id': host_id
        })
    
        self.cmd('vm create -n {vm-name} --image Debian:debian-10:10:latest -g {rg} --size Standard_D4s_v3 '
                 '--host {host_id} --generate-ssh-keys --admin-username azureuser --nsg-rule NONE')
    
        # validate resources created successfully
        vm_json = self.cmd('vm show -n {vm-name} -g {rg}', checks=[
            self.check('name', '{vm-name}'),
            self.check('provisioningState', 'Succeeded')
        ]).get_output_in_json()
    
        host_json = self.cmd('vm host show --name {host-name} --host-group {host-group} -g {rg}', checks=[
            self.check('name', '{host-name}'),
        ]).get_output_in_json()
    
        host_group_json = self.cmd('vm host group show --name {host-group} -g {rg}', checks=[
            self.check('name', '{host-group}'),
        ]).get_output_in_json()
    
        self.assertTrue(vm_json['host']['id'].lower(), host_json['id'].lower())
        self.assertTrue(host_json['virtualMachines'][0]['id'].lower(), vm_json['id'].lower())
        self.assertTrue(host_group_json['hosts'][0]['id'].lower(), host_json['id'].lower())
    
        # delete resources (test vm host delete commands)
>       self.cmd('vm delete --name {vm-name} -g {rg} --yes')

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:10264: 
 
 
 
 
 
                                   
src/azure-cli-testsdk/azure/cli/testsdk/base.py:178: in cmd
    return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-testsdk/azure/cli/testsdk/base.py:253: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
                                       _ 

self = <azure.cli.testsdk.base.ExecutionResult object at 0x7f6f46de39b0>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7f6f49179ca0>
command = 'vm delete --name ded-host-vm -g cli_test_dedicated_host_000001 --yes'
expect_failure = False

    def _in_process_execute(self, cli_ctx, command, expect_failure=False):
        from io import StringIO
        from vcr.errors import CannotOverwriteExistingCassetteException
    
        if command.startswith('az '):
            command = command[3:]
    
        stdout_buf = StringIO()
        logging_buf = StringIO()
        try:
            # issue: stderr cannot be redirect in this form, as a result some failure information
            # is lost when command fails.
            self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
            self.output = stdout_buf.getvalue()
            self.applog = logging_buf.getvalue()
    
        except CannotOverwriteExistingCassetteException as ex:
>           raise AssertionError(ex)
E           AssertionError: Can't play back this request: it matches 1 recorded interaction, but that has already been played back.
E           record_mode 'once' doesn't record new requests into an existing cassette.
E           
E             GET https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/virtualMachines/ded-host-vm?api-version=2026-04-01
E           
E           Cassette: /mnt/vss/_work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml
E             record_mode: once
E             match_on: method, scheme, host, port, path, _custom_request_query_matcher
E             interactions: 86 recorded, 25 played
E           
E           How to fix:
E              If it's fine for this request to get the same response each time, set
E               allow_playback_repeats=True [1].
E             
 Otherwise record the extra request: run once with record_mode='new_episodes'
E               [2].
E           
E           [1] https://vcrpy.readthedocs.io/en/latest/advanced.html#playback-repeats
E           [2] https://vcrpy.readthedocs.io/en/latest/usage.html#record-modes

src/azure-cli-testsdk/azure/cli/testsdk/base.py:309: AssertionError
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:10194
❌3.14
Type Test Case Error Message Line
Failed test_dedicated_host_e2e self = <azure.cli.testsdk.base.ExecutionResult object at 0x7fae2acef950>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7fae2d9dee90>
command = 'vm delete --name ded-host-vm -g cli_test_dedicated_host_000001 --yes'
expect_failure = False

    def in_process_execute(self, cli_ctx, command, expect_failure=False):
        from io import StringIO
        from vcr.errors import CannotOverwriteExistingCassetteException
    
        if command.startswith('az '):
            command = command[3:]
    
        stdout_buf = StringIO()
        logging_buf = StringIO()
        try:
            # issue: stderr cannot be redirect in this form, as a result some failure information
            # is lost when command fails.
>           self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/azure-cli-testsdk/azure/cli/testsdk/base.py:304: 
                                        
env/lib/python3.14/site-packages/knack/cli.py:245: in invoke
    exit_code = self.exception_handler(ex)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/init.py:153: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: in handle_main_exception
    raise ex
env/lib/python3.14/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:677: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:820: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:800: in run_job
    result = LongRunningOperation(cmd_copy.cli_ctx, 'Starting {}'.format(cmd_copy.name))(result)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:1168: in call
    result = poller.result()
             ^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:109: in result
    self.wait(timeout)
env/lib/python3.14/site-packages/azure/core/tracing/decorator.py:119: in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:131: in wait
    raise self.exception
src/azure-cli-core/azure/cli/core/aaz/poller.py:84: in start
    for polling_method in self.polling_generator:
                          ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:14632: in execute_operations
    self.pre_operations()
src/azure-cli/azure/cli/command_modules/vm/operations/vm.py:275: in pre_operations
    VMShow(cli_ctx=self.cli_ctx)(command_args={
src/azure-cli-core/azure/cli/core/aaz/command.py:154: in call
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:3725: in handler
    self.execute_operations()
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:3757: in execute_operations
    self.VirtualMachinesGet(ctx=self.ctx)()
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:3777: in call
    session = self.client.send_request(request=request, stream=False, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/client.py:107: in send_request
    session = self.pipeline.run(request, stream=stream, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:242: in run
    return first_node.send(pipeline_request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/mgmt/core/policies/base.py:95: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/policies/redirect.py:205: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/policies/retry.py:545: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/http_policy.py:112: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:98: in send
    response = self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/base.py:130: in send
    self.sender.send(request.http_request, **request.context.options),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/azure/core/pipeline/transport/requests_basic.py:375: in send
    response = self.session.request(  # type: ignore
env/lib/python3.14/site-packages/requests/sessions.py:592: in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/requests/sessions.py:706: in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/requests/adapters.py:645: in send
    resp = conn.urlopen(
env/lib/python3.14/site-packages/urllib3/connectionpool.py:788: in urlopen
    response = self.make_request(
env/lib/python3.14/site-packages/urllib3/connectionpool.py:534: in make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
env/lib/python3.14/site-packages/vcr/stubs/urllib3_stubs.py:20: in getresponse
    response = super().getresponse(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  

self = <VCRRequestsHTTPSConnection/mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml(host='management.azure.com', port=443) at 0x7fae2acb25d0>
 = False, kwargs = {}

    def getresponse(self, 
=False, **kwargs):
        """Retrieve the response"""
        # Check to see if the cassette has a response for this request. If so,
        # then return it
        if self.cassette.can_play_response_for(self.vcr_request):
            log.info(f"Playing response for {self.vcr_request} from cassette")
            response = self.cassette.play_response(self.vcr_request)
            return VCRHTTPResponse(response, self.vcr_request.uri)
        else:
            if self.cassette.write_protected and self.cassette.filter_request(self.vcr_request):
>               raise CannotOverwriteExistingCassetteException(
                    cassette=self.cassette,
                    failed_request=self.vcr_request,
                )
E               vcr.errors.CannotOverwriteExistingCassetteException: Can't play back this request: it matches 1 recorded interaction, but that has already been played back.
E               record_mode 'once' doesn't record new requests into an existing cassette.
E               
E                 GET https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/virtualMachines/ded-host-vm?api-version=2026-04-01
E               
E               Cassette: /mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml
E                 record_mode: once
E                 match_on: method, scheme, host, port, path, custom_request_query_matcher
E                 interactions: 86 recorded, 25 played
E               
E               How to fix:
E                  If it's fine for this request to get the same response each time, set
E                   allow_playback_repeats=True [1].
E                 
 Otherwise record the extra request: run once with record_mode='new_episodes'
E                   [2].
E               
E               [1] https://vcrpy.readthedocs.io/en/latest/advanced.html#playback-repeats
E               [2] https://vcrpy.readthedocs.io/en/latest/usage.html#record-modes

env/lib/python3.14/site-packages/vcr/stubs/init.py:313: CannotOverwriteExistingCassetteException

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.DedicatedHostScenarioTest testMethod=test_dedicated_host_e2e>
resource_group = 'cli_test_dedicated_host2_000002'
resource_group_location = 'eastus'

    @AllowLargeResponse()
    @ResourceGroupPreparer(name_prefix='cli_test_dedicated_host
', location='westeurope')
    @ResourceGroupPreparer(name_prefix='cli_test_dedicated_host2
', location='eastus', key='rg2')
    def test_dedicated_host_e2e(self, resource_group, resource_group_location):
        self.kwargs.update({
            'host-group': 'my-host-group',
            'host-name': 'my-host',
            'vm-name': 'ded-host-vm'
        })
    
        # create resources
        self.cmd('vm host group create -n {host-group} -c 3 -g {rg} --tags "foo=bar"', checks=[
            self.check('name', '{host-group}'),
            self.check('platformFaultDomainCount', 3),
            self.check('tags.foo', 'bar')
        ])
    
        try:
            self.cmd('vm host create -n {host-name} --host-group {host-group} -d 2 -g {rg} '
                     '--sku DSv3-Type1 --auto-replace false --tags "bar=baz" ', checks=[
                self.check('name', '{host-name}'),
                self.check('platformFaultDomain', 2),
                self.check('sku.name', 'DSv3-Type1'),
                self.check('autoReplaceOnFailure', False),
                self.check('tags.bar', 'baz')
            ])
    
        except CLIError as e:
            if 'capacity' in str(e):
                return
    
        result = self.cmd('vm host get-instance-view --host-group {host-group} --name {host-name} -g {rg}', checks=[
            self.check('name', '{host-name}'),
        ]).get_output_in_json()
        instance_view = result["instanceView"]
        self.assertTrue(instance_view["assetId"])
        self.assertTrue(instance_view["availableCapacity"])
    
        self.cmd('vm host group get-instance-view -g {rg} -n {host-group}', checks=[
            self.exists('instanceView')
        ])
    
        host_id = self.cmd('vm host show -g {rg} -n {host-name} --host-group {host-group}').get_output_in_json()['id']
        self.kwargs.update({
            'host_id': host_id
        })
    
        self.cmd('vm create -n {vm-name} --image Debian:debian-10:10:latest -g {rg} --size Standard_D4s_v3 '
                 '--host {host_id} --generate-ssh-keys --admin-username azureuser --nsg-rule NONE')
    
        # validate resources created successfully
        vm_json = self.cmd('vm show -n {vm-name} -g {rg}', checks=[
            self.check('name', '{vm-name}'),
            self.check('provisioningState', 'Succeeded')
        ]).get_output_in_json()
    
        host_json = self.cmd('vm host show --name {host-name} --host-group {host-group} -g {rg}', checks=[
            self.check('name', '{host-name}'),
        ]).get_output_in_json()
    
        host_group_json = self.cmd('vm host group show --name {host-group} -g {rg}', checks=[
            self.check('name', '{host-group}'),
        ]).get_output_in_json()
    
        self.assertTrue(vm_json['host']['id'].lower(), host_json['id'].lower())
        self.assertTrue(host_json['virtualMachines'][0]['id'].lower(), vm_json['id'].lower())
        self.assertTrue(host_group_json['hosts'][0]['id'].lower(), host_json['id'].lower())
    
        # delete resources (test vm host delete commands)
>       self.cmd('vm delete --name {vm-name} -g {rg} --yes')

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:10264: 
 
 
 
 
 
                                   
src/azure-cli-testsdk/azure/cli/testsdk/base.py:178: in cmd
    return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-testsdk/azure/cli/testsdk/base.py:253: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
                                       _ 

self = <azure.cli.testsdk.base.ExecutionResult object at 0x7fae2acef950>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7fae2d9dee90>
command = 'vm delete --name ded-host-vm -g cli_test_dedicated_host_000001 --yes'
expect_failure = False

    def _in_process_execute(self, cli_ctx, command, expect_failure=False):
        from io import StringIO
        from vcr.errors import CannotOverwriteExistingCassetteException
    
        if command.startswith('az '):
            command = command[3:]
    
        stdout_buf = StringIO()
        logging_buf = StringIO()
        try:
            # issue: stderr cannot be redirect in this form, as a result some failure information
            # is lost when command fails.
            self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
            self.output = stdout_buf.getvalue()
            self.applog = logging_buf.getvalue()
    
        except CannotOverwriteExistingCassetteException as ex:
>           raise AssertionError(ex)
E           AssertionError: Can't play back this request: it matches 1 recorded interaction, but that has already been played back.
E           record_mode 'once' doesn't record new requests into an existing cassette.
E           
E             GET https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/virtualMachines/ded-host-vm?api-version=2026-04-01
E           
E           Cassette: /mnt/vss/_work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml
E             record_mode: once
E             match_on: method, scheme, host, port, path, _custom_request_query_matcher
E             interactions: 86 recorded, 25 played
E           
E           How to fix:
E              If it's fine for this request to get the same response each time, set
E               allow_playback_repeats=True [1].
E             
 Otherwise record the extra request: run once with record_mode='new_episodes'
E               [2].
E           
E           [1] https://vcrpy.readthedocs.io/en/latest/advanced.html#playback-repeats
E           [2] https://vcrpy.readthedocs.io/en/latest/usage.html#record-modes

src/azure-cli-testsdk/azure/cli/testsdk/base.py:309: AssertionError
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:10194

Related command

az vm delete

Description

Resolve #33794

Check whether the VM exists before deletion. If the VM or resource group is missing, show Azure’s original error and exit instead of silently succeeding.

Testing Guide

azdev test test_vm_delete_nonexistent_vm test_vm_delete_nonexistent_resource_group --live --discover

py -m pytest C:\Users\v-williamng\repos\azure-cli\src\azure-cli\azure\cli\command_modules\vm\tests\latest\test_custom_vm_commands.py::TestVMDelete

History Notes


This checklist is used to make sure that common guidelines for a pull request are followed.

@william051200 William (william051200) added the Request X Engineering Agent Ask the agent to triage this issue or review this PR label Nov 2, 2026
Copilot AI balanced review requested due to automatic review settings November 2, 2026 01:15
@x-engineering-agent

x-engineering-agent Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

X Engineering Agent Pull request review: Comments

William (@william051200)

Check Status Detail
Agent live tests Failed With conclusion failure.
Regression coverage Unverified For vm: 2 focused test file(s) and 6 recording file(s) changed.
Findings 2 high findings 1 medium findings 2 high, 1 medium
Risk Risk 43/100 Medium Medium; owner review recommended

To address

Tick each item as you address it.

  • High Release artifact validator

    Details and fix

    src/azure-cli/azure/cli/command_modules/vm/commands.py:184: Customer-visible Azure CLI behavior is not marked for generated release notes in the PR metadata.

    Remediation: Start the PR title with [Component] and describe the customer-facing change there. For multiple or overriding notes, use the PR description's History Notes section.

    Verify: Run the PR title/content check and confirm the metadata is accepted for automatic history generation.

  • High Preserve delete-only RBAC support

    Details and fix

    src/azure-cli/azure/cli/command_modules/vm/operations/vm.py:275-281 now requires a successful VM GET before the inherited DELETE (aaz/latest/vm/_delete.py:67-69). A custom role granting Microsoft.Compute/virtualMachines/delete but not Microsoft.Compute/virtualMachines/read can no longer delete an existing VM: GET's 403 escapes before DELETE, including with --no-wait or --force-deletion. Previously DELETE was submitted directly.

    Remediation: On preflight authorization denial, let DELETE determine authorization; retain the explicit missing-resource error and propagate DELETE failures.

    Verify: Add GET-403/DELETE-204 coverage expecting DELETE and success, with/without --no-wait; retain DELETE-403 and GET-404 checks. The new authorization test currently expects only GET for this case.

  • Medium Upstream CI

    Details and fix

    Azure.azure-cli Full Test

    • Result: failure
    • Included checks: Azure.azure-cli Full Test (Automation Full Test Python312 Profile Latest instance2), Azure.azure-cli Full Test (Automation Full Test Python314 Profile Latest instance2)
    • Failure details:
          raise AssertionError(ex)
    

    E AssertionError: Can't play back this request: it matches 1 recorded interaction, but that has already been played back.
    E record_mode 'once' doesn't record new requests into an existing cassette.
    E
    - Next action: Address the first actionable diagnostic quoted from the task log; do not infer a source-code cause from the aggregate build status.
    - Verify: Re-run Automation Full Test Python312 Profile Latest instance2 / azdev test and confirm the quoted diagnostic is gone.

          raise AssertionError(ex)
    

    E AssertionError: Can't play back this request: it matches 1 recorded interaction, but that has already been played back.
    E record_mode 'once' doesn't record new requests into an existing cassette.
    E
    - Next action: Address the first actionable diagnostic quoted from the task log; do not infer a source-code cause from the aggregate build status.
    - Verify: Re-run Automation Full Test Python314 Profile Latest instance2 / azdev test and confirm the quoted diagnostic is gone.

    Obtain the failing test/request before attributing either job to this PR.

Review details

Independent review

Reviewed SHA 7641ce8be4ee4d9c089dea2501b26c6cb06f2e0c; COMMENT.

Test validation

  • Live test: Failed with conclusion failure. Workflow run
  • Regression coverage: For vm: 2 focused test file(s) and 6 recording file(s) changed. Scenario coverage is unverified; review the issue's required conditions, test setup, and assertions before approval. No linked issue was found in the PR timeline; inspect the source issue and its required scenario manually.

Live failure classification: Uncertain. Evidence is only conclusion failure at this head, not a failing step. Retrieve the failed-step diagnostic, then rerun the identified scenario at this SHA.

Authored tests assert missing-resource errors, exit codes, output and request order, including no-wait/403 paths. Negative recordings contain GET 404s. This is static evidence, not passing execution; no tests were run here.

Copilot comment 4438172036 is resolved: test_vm_create_with_specialized_unmanaged_disk.yaml:2639,2714 has two matching GETs before DELETE at 2791, covering show at test_vm_commands.py:944 and delete at 947. The other three rerecorded success scenarios include pre-delete GETs. This does not resolve the unidentified CI failures.

Risk assessment

43/100 · Medium

The Medium rating is driven by public CLI behavior, failure-handling behavior.

  • Change scope: 11 changed files, 62588 changed lines (+29676 / -32912), including 2 production files.
  • Affected components: vm
  • Risk drivers: public CLI behavior (+18); failure-handling behavior (+12)
  • Regression evidence: Changed regression tests are included, reducing risk.
  • Confidence: High because changed-line patches were available for every production file.
  • Required review: Owning-squad review is recommended for vm before merge.

X Engineering Agent · Reviewer · React with +1 or -1 to train the agent

Live test — Failed

FAIL (exit 1)

Selectors: vm.TestVMDelete vm.test_vm_commands (module)
PR head ref: vm-delete-handle
PR head sha: 7641ce8be4ee4d9c089dea2501b26c6cb06f2e0c
PR base ref: dev
New test files in PR: false

Changed test files run
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/41575187178

Live-test recordings: 1 regenerated — archived in workflow artifact live-test-pr-34316 (recordings/).

The recording was not committed because the live test failed. Fix the test failure before publishing its regenerated cassette.

Recording files
src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_image_list_by_alias.yaml
Last 80 lines of azdev output

=============
| Run Tests |
=============


test index found: /home/runner/.azdev/env_config/home/runner/work/issue-sentinel/issue-sentinel/.venv/test_index/latest.json

Test on modules: vm.TestVMDelete, vm.test_vm_commands

WARNING: RUNNING TESTS LIVE
The tests are set to run against current profile "latest"
============================= test session starts ==============================
platform linux -- Python 3.12.15, pytest-9.1.1, pluggy-1.7.0 -- /home/runner/work/issue-sentinel/issue-sentinel/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli
configfile: pyproject.toml
plugins: xdist-3.8.0, platformdirs-4.14.3, forked-1.7.5
collecting ... collected 397 items

azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py::TestVMDelete::test_vm_delete_existing_resource_succeeds PASSED [  0%]
azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py::TestVMDelete::test_vm_delete_missing_resource_fails_before_delete PASSED [  0%]
azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py::TestVMDelete::test_vm_delete_preserves_authorization_errors PASSED [  0%]
azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py::VMImageListByAliasesScenarioTest::test_vm_image_list_by_alias FAILED [  1%]

=================================== FAILURES ===================================
_________ VMImageListByAliasesScenarioTest.test_vm_image_list_by_alias _________
self = <latest.test_vm_commands.VMImageListByAliasesScenarioTest testMethod=test_vm_image_list_by_alias>

    def test_vm_image_list_by_alias(self):
        result = self.cmd('vm image list --offer ubuntu').get_output_in_json()
        self.assertTrue(len(result) >= 1)
        self.assertEqual(result[-1]['publisher'], 'Canonical')
>       self.assertTrue('lts' in result[-1]['sku'])
E       AssertionError: False is not true

azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:59: AssertionError
------------------------------ Captured log call -------------------------------
WARNING  cli.azure.cli.command_modules.vm.custom:custom.py:2765 You are viewing an offline list of images, use --all to retrieve an up-to-date list
- generated xml file: /home/runner/work/issue-sentinel/issue-sentinel/test-output/results.xml -
=========================== short test summary info ============================
FAILED azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py::VMImageListByAliasesScenarioTest::test_vm_image_list_by_alias - self = <latest.test_vm_commands.VMImageListByAliasesScenarioTest testMethod=test_vm_image_list_by_alias>

    def test_vm_image_list_by_alias(self):
        result = self.cmd('vm image list --offer ubuntu').get_output_in_json()
        self.assertTrue(len(result) >= 1)
        self.assertEqual(result[-1]['publisher'], 'Canonical')
>       self.assertTrue('lts' in result[-1]['sku'])
E       AssertionError: False is not true

azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:59: AssertionError
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 1 failed, 3 passed in 7.17s ==========================

Workflow run

X Engineering Agent · Tester · React with +1 or -1 to train the agent


Ask the Agent

Tick a box to queue an action. Requires write access to this repository.

  • Re-review this PR
  • Run Agent live tests on this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new preflight GET breaks existing deletion test playback because recordings lack the additional VM response, so affected successful-deletion scenarios need to be re-recorded.

1 open issue
What changed in this PR

Updates az vm delete to check VM existence before deletion, addressing #33794 by returning Azure’s error instead of silently succeeding when the VM or resource group is missing.

Changes:

  • Registers a custom delete command with a pre-deletion existence check.
  • Adds unit coverage for missing resources, successful deletion, authorization failures, and --no-wait.
  • Adds scenario tests and recordings for missing VMs and resource groups.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​vm/​tests/​latest/​test_vm_commands.py Adds missing-VM and missing-resource-group scenarios.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​tests/​latest/​test_custom_vm_commands.py Tests deletion outcomes, errors, and request ordering.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​tests/​latest/​recordings/​test_vm_delete_nonexistent_vm.yaml Records the missing-VM response.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​tests/​latest/​recordings/​test_vm_delete_nonexistent_resource_group.yaml Records the missing-resource-group scenario.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​operations/​vm.py Adds the existence check and missing-resource error conversion.
src/​azure-cli/​azure/​cli/​command_modules/​vm/​commands.py Registers the custom VMDelete implementation.

Review effort: Balanced

Comment on lines +275 to +279
VMShow(cli_ctx=self.cli_ctx)(command_args={
"resource_group": str(args.resource_group),
"vm_name": str(args.name),
"subscription": self.ctx.subscription_id,
})
@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200 William (william051200) added the Request X Engineering Agent Live Test Ask the agent to run live tests and review this PR label Nov 3, 2026
@william051200 William (william051200) added Request X Engineering Agent Live Test Ask the agent to run live tests and review this PR and removed Request X Engineering Agent Live Test Ask the agent to run live tests and review this PR labels Nov 3, 2026
@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

Current status:
Latest implementation introduces changes in vm delete behavior, required re-record test case recording.
Unable to re-record test case due to insufficient account permission.
Looking for workaround.

This branch has not been deployed

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

Labels

act-observability-squad Compute az vm/vmss/image/disk/snapshot do-not-merge Request X Engineering Agent Live Test Ask the agent to run live tests and review this PR Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Reviewed Agent reviewed this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az vm delete Command Does Not Return an Error When the Specified Resource Group or Virtual Machine Does Not Exist

4 participants