Skip to content

Conversation

@huiii99
Copy link
Member

@huiii99 huiii99 commented Jan 20, 2026

Related command
az vm disk attach
az vm disk detach

Description
Migrate az vm disk attach and az vm disk detach commands from hand written sdk to aaz.

Testing Guide

History Notes


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

Copilot AI review requested due to automatic review settings January 20, 2026 06:48
@huiii99 huiii99 requested a review from yanzhudd as a code owner January 20, 2026 06:48
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jan 20, 2026

❌AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
❌backup
❌latest
❌3.12
Type Test Case Error Message Line
Failed test_backup_disk_exclusion self = <azure.cli.testsdk.base.ExecutionResult object at 0x7f68da9d5520>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7f68e0d05f40>
command = 'vm disk attach -g AzureBackupRG_clitest_000001 --vm-name clitest-vm000003 --name mydisk1 --new --size-gb 10'
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:303: 
                                        
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:135: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
                                        

ex = AttributeError("'dict' object has no attribute 'lun'"), args = ()
kwargs = {}

    def handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
        if isinstance(ex, CannotOverwriteExistingCassetteException):
            # This exception usually caused by a no match HTTP request. This is a product error
            # that is caused by change of SDK invocation.
            raise ex
    
>       raise CliExecutionError(ex)
E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception AttributeError during execution and fails the command.

src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: CliExecutionError

During handling of the above exception, another exception occurred:

self = <azure.cli.command_modules.backup.tests.latest.test_backup_commands.BackupTests testMethod=test_backup_disk_exclusion>
resource_group = 'AzureBackupRG_clitest_000001'
vault_name = 'clitest-vault000002', vm_name = 'clitest-vm000003'
storage_account = 'clitest000004'

    @ResourceGroupPreparer(name_prefix="AzureBackupRG_clitest
", location="eastus2euap")
    @VaultPreparer()
    @VMPreparer()
    @StorageAccountPreparer(location="eastus2euap")
    def test_backup_disk_exclusion(self, resource_group, vault_name, vm_name, storage_account):
        self.kwargs.update({
            'vault': vault_name,
            'vm': vm_name,
            'rg': resource_group,
            'sa': storage_account
        })
>       self.cmd('vm disk attach -g {rg} --vm-name {vm} --name mydisk1 --new --size-gb 10')

src/azure-cli/azure/cli/command_modules/backup/tests/latest/test_backup_commands.py:1061: 
                                        
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: 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:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:315: in in_process_execute
    raise ex.exception
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:669: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:737: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:717: 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:1075: in call
    result = poller.result()
             ^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:108: 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:130: in wait
    raise self.exception
src/azure-cli-core/azure/cli/core/aaz/poller.py:83: in start
    for polling_method in self.polling_generator:
                          ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:14050: in execute_operations
    self.pre_instance_update(self.ctx.vars.instance)
src/azure-cli/azure/cli/command_modules/vm/custom.py:2368: in pre_instance_update
    disk_lun = get_disk_lun(data_disks_list)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
 
                           

data_disks = [{'caching': 'None', 'createOption': 'Empty', 'deleteOption': 'Detach', 'diskSizeGB': 10, ...}]

    def _get_disk_lun(data_disks):
        # start from 0, search for unused int for lun
        if not data_disks:
            return 0
    
>       existing_luns = sorted([d.lun for d in data_disks])
                                ^^^^^
E       AttributeError: 'dict' object has no attribute 'lun'

src/azure-cli/azure/cli/command_modules/vm/custom.py:184: AttributeError
azure/cli/command_modules/backup/tests/latest/test_backup_commands.py:1049
❌3.13
Type Test Case Error Message Line
Failed test_backup_disk_exclusion self = <azure.cli.testsdk.base.ExecutionResult object at 0x7ff506908e10>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7ff509c55950>
command = 'vm disk attach -g AzureBackupRG_clitest_000001 --vm-name clitest-vm000003 --name mydisk1 --new --size-gb 10'
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:303: 
                                        
env/lib/python3.13/site-packages/knack/cli.py:245: in invoke
    exit_code = self.exception_handler(ex)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/init.py:135: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
                                        

ex = AttributeError("'dict' object has no attribute 'lun'"), args = ()
kwargs = {}

    def handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
        if isinstance(ex, CannotOverwriteExistingCassetteException):
            # This exception usually caused by a no match HTTP request. This is a product error
            # that is caused by change of SDK invocation.
            raise ex
    
>       raise CliExecutionError(ex)
E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception AttributeError during execution and fails the command.

src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: CliExecutionError

During handling of the above exception, another exception occurred:

self = <azure.cli.command_modules.backup.tests.latest.test_backup_commands.BackupTests testMethod=test_backup_disk_exclusion>
resource_group = 'AzureBackupRG_clitest_000001'
vault_name = 'clitest-vault000002', vm_name = 'clitest-vm000003'
storage_account = 'clitest000004'

    @ResourceGroupPreparer(name_prefix="AzureBackupRG_clitest
", location="eastus2euap")
    @VaultPreparer()
    @VMPreparer()
    @StorageAccountPreparer(location="eastus2euap")
    def test_backup_disk_exclusion(self, resource_group, vault_name, vm_name, storage_account):
        self.kwargs.update({
            'vault': vault_name,
            'vm': vm_name,
            'rg': resource_group,
            'sa': storage_account
        })
>       self.cmd('vm disk attach -g {rg} --vm-name {vm} --name mydisk1 --new --size-gb 10')

src/azure-cli/azure/cli/command_modules/backup/tests/latest/test_backup_commands.py:1061: 
                                        
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: 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:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:315: in in_process_execute
    raise ex.exception
env/lib/python3.13/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:669: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:737: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:717: 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:1075: in call
    result = poller.result()
             ^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:108: in result
    self.wait(timeout)
env/lib/python3.13/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:130: in wait
    raise self.exception
src/azure-cli-core/azure/cli/core/aaz/poller.py:83: in start
    for polling_method in self.polling_generator:
                          ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:10646: in execute_operations
    self.pre_instance_update(self.ctx.vars.instance)
src/azure-cli/azure/cli/command_modules/vm/custom.py:2368: in pre_instance_update
    disk_lun = get_disk_lun(data_disks_list)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
 
                           

data_disks = [{'caching': 'None', 'createOption': 'Empty', 'deleteOption': 'Detach', 'diskSizeGB': 10, ...}]

    def _get_disk_lun(data_disks):
        # start from 0, search for unused int for lun
        if not data_disks:
            return 0
    
>       existing_luns = sorted([d.lun for d in data_disks])
                                ^^^^^
E       AttributeError: 'dict' object has no attribute 'lun'

src/azure-cli/azure/cli/command_modules/vm/custom.py:184: AttributeError
azure/cli/command_modules/backup/tests/latest/test_backup_commands.py:1049
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
❌vm
❌latest
❌3.12
Type Test Case Error Message Line
Failed test_vm_custom_image self = <azure.cli.core.commands.AzCliCommandInvoker object at 0x7f5547daabd0>
parsed_ns = Namespace(log_verbosity_verbose=False, log_verbosity_debug=False, log_verbosity_only_show_errors=False, output_for...ngeTag object at 0x7f5547cce990>, <azure.cli.core.breaking_change.UpcomingBreakingChangeTag object at 0x7f5547cce990>])

    def validation(self, parsed_ns):
        try:
            cmd_validator = getattr(parsed_ns, 'command_validator', None)
            if cmd_validator:
>               self.validate_cmd_level(parsed_ns, cmd_validator)

env/lib/python3.12/site-packages/knack/invocation.py:111: 
 
 
 
 
 
 
                                  
src/azure-cli-core/azure/cli/core/commands/init.py:918: in validate_cmd_level
    cmd_validator(**self.build_kwargs(cmd_validator, ns))
src/azure-cli/azure/cli/command_modules/vm/validators.py:1537: in process_vm_create_namespace
    validate_vm_create_storage_profile(cmd, namespace)
src/azure-cli/azure/cli/command_modules/vm/validators.py:391: in validate_vm_create_storage_profile
    image_type = parse_image_argument(cmd, namespace)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/validators.py:279: in parse_image_argument
    images = load_images_from_aliases_doc(cmd.cli_ctx)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/actions.py:180: in load_images_from_aliases_doc
    response = requests.get(target_url, verify=not should_disable_connection_verify())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/requests/api.py:73: in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/requests/api.py:59: in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/requests/sessions.py:703: in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/requests/adapters.py:667: in send
    resp = conn.urlopen(
env/lib/python3.12/site-packages/urllib3/connectionpool.py:787: in urlopen
    response = self.make_request(
env/lib/python3.12/site-packages/urllib3/connectionpool.py:534: in make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
                            

self = <VCRRequestsHTTPSConnection/mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_custom_image.yaml(host='azcliprod.blob.core.windows.net', port=443) at 0x7f5547b1ee70>
 = 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)
        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 overwrite existing cassette ('/mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_custom_image.yaml') in your current record mode ('once').
E               No match for the request (<Request (GET) https://azcliprod.blob.core.windows.net/cli/vm/aliases.json>)&nbsp;was&nbsp;found.
E               Found 2 similar requests with 2 different matcher(s) :
E               
E               1 - (<Request (GET) https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json>).
E               Matchers succeeded : ['method', 'scheme', 'port', 'custom_request_query_matcher']
E               Matchers failed :
E               host - assertion failure :
E               azcliprod.blob.core.windows.net != raw.githubusercontent.com
E               path - assertion failure :
E               /cli/vm/aliases.json != /Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json
E               
E               2 - (<Request (GET) https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json>).
E               Matchers succeeded : ['method', 'scheme', 'port', 'custom_request_query_matcher']
E               Matchers failed :
E               host - assertion failure :
E               azcliprod.blob.core.windows.net != raw.githubusercontent.com
E               path - assertion failure :
E               /cli/vm/aliases.json != /Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json

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

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.VMCustomImageTest testMethod=test_vm_custom_image>
resource_group = 'cli_test_vm_custom_image000001'

    @AllowLargeResponse(size_kb=99999)
    @ResourceGroupPreparer(name_prefix='cli_test_vm_custom_image')
    def test_vm_custom_image(self, resource_group):
        self.kwargs.update({
            'vm1': 'vm-unmanaged-disk',
            'vm2': 'vm-managed-disk',
            'newvm1': 'fromimage1',
            'newvm2': 'fromimage2',
            'image1': 'img-from-unmanaged',
            'image2': 'img-from-managed',
            'subnet': 'subnet1',
            'vnet': 'vnet1',
            'nsg': 'nsg',
            'pubip1': 'pubip1',
            'pubip2': 'pubip2',
            'pubip3': 'pubip3',
            'pubip4': 'pubip4',
            'pubip5': 'pubip5',
            'pubip6': 'pubip6',
            'pubip7': 'pubip7',
            'ssh_key': TEST_SSH_KEY_PUB,
        })
    
        # Create a public IP resource with service tag
        self.cmd('network public-ip create --name {pubip1} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm1} --image Debian:debian-10:10:latest '
            '--use-unmanaged-disk '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip1} --nsg-rule NONE'
        )
    
        # Disable default outbound access
        self.cmd(
            'network vnet subnet update -g {rg} --vnet-name {vnet} -n {subnet} --default-outbound-access false')
    
        # deprovision the VM, but we have to do it async to avoid hanging the run-command itself
        self.cmd('vm run-command invoke -g {rg} -n {vm1} --command-id RunShellScript --scripts "echo $0 $1" --parameters hello world')
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm1}')
        self.cmd('vm generalize -g {rg} -n {vm1}')
        self.cmd('image create -g {rg} -n {image1} --source {vm1}')
    
        # Create a public IP resource with service tag
        self.cmd('network public-ip create --name {pubip2} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm2} --image Debian:debian-10:10:latest '
            '--storage-sku standard_lrs --data-disk-sizes-gb 1 1 1 1 '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip2} --nsg-rule NONE'
        )
        data_disks = self.cmd('vm show -g {rg} -n {vm2}').get_output_in_json()['storageProfile']['dataDisks']
        self.kwargs['disk_0_name'] = data_disks[0]['name']
        self.kwargs['disk_2_name'] = data_disks[2]['name']
    
        # detach the 0th and 2nd disks leaving disks at lun 1 and 3
        self.cmd('vm disk detach -n {disk_0_name} --vm-name {vm2} -g {rg}')
        self.cmd('vm disk detach -n {disk_2_name} --vm-name {vm2} -g {rg}')
    
        self.cmd('vm show -g {rg} -n {vm2}', checks=self.check("length(storageProfile.dataDisks)", 2))
    
        self.cmd('vm run-command invoke -g {rg} -n {vm2} --command-id RunShellScript --scripts "echo $0 $1" --parameters hello world')
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm2}')
        self.cmd('vm generalize -g {rg} -n {vm2}')
        self.cmd('image create -g {rg} -n {image2} --source {vm2}')
    
        # Create a public IP resource with service tag
        self.cmd('network public-ip create --name {pubip3} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
>       self.cmd(
            'vm create -g {rg} -n {newvm1} --image {image1} '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--authentication-type password '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip3} --nsg-rule NONE'
        )

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:573: 
 
 
 
 
 
 
 
                                 
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: 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:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:303: in in_process_execute
    self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.12/site-packages/knack/cli.py:250: in invoke
    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:657: in execute
    self.validation(expanded_arg)
env/lib/python3.12/site-packages/knack/invocation.py:118: in validation
    getattr(parsed_ns, 'parser', self.parser).validation_error(str(err))
src/azure-cli-core/azure/cli/core/parser.py:150: in validation_error
    self.exit(2)
 
 
 
 
                                   _ 

self = AzCliCommandParser(prog='az vm create', usage=None, description='', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
status = 2, message = None

    def exit(self, status=0, message=None):
        if message:
            self._print_message(message, _sys.stderr)
>       _sys.exit(status)
E       SystemExit: 2

/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/argparse.py:2637: SystemExit
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:501
Failed test_vm_disk_attach_from_copy_and_restore self = <azure.cli.testsdk.base.ExecutionResult object at 0x7f554888df10>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7f554b939460>
command = 'vm disk attach -g cli_test_vm_disk_attach_from_copy_and_restore000001 --size 20 --sku Standard_LRS --vm-name vm_00000...rePoints/point_000004/diskRestorePoints/disk_000005_43f1765e-f52d-4d18-8397-927d883cb921 --new-names-of-rp disk_000012'
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:303: 
                                        
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:135: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
                                        

ex = AttributeError("'dict' object has no attribute 'lun'"), args = ()
kwargs = {}

    def handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
        if isinstance(ex, CannotOverwriteExistingCassetteException):
            # This exception usually caused by a no match HTTP request. This is a product error
            # that is caused by change of SDK invocation.
            raise ex
    
>       raise CliExecutionError(ex)
E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception AttributeError during execution and fails the command.

src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: CliExecutionError

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.VMManagedDiskScenarioTest testMethod=test_vm_disk_attach_from_copy_and_restore>

    @AllowLargeResponse(size_kb=99999)
    @ResourceGroupPreparer('cli_test_vm_disk_attach_from_copy_and_restore', location='eastus2euap')
    def test_vm_disk_attach_from_copy_and_restore(self):
        self.kwargs.update({
            'vm_name': self.create_random_name('vm
', length=15),
            'collection_name': self.create_random_name('collection
', length=20),
            'point_name': self.create_random_name('point_', length=15),
            'disk_name1': self.create_random_name('disk_', length=15),
            'disk_name2': self.create_random_name('disk_', length=15),
            'disk_name3': self.create_random_name('disk_', length=15),
            'disk_name4': self.create_random_name('disk_', length=15),
            'disk_name5': self.create_random_name('disk_', length=15),
            'disk_name6': self.create_random_name('disk_', length=15),
            'disk_name7': self.create_random_name('disk_', length=15),
            'disk_name8': self.create_random_name('disk_', length=15),
            'subnet': self.create_random_name('subnet', length=15),
            'vnet': self.create_random_name('vnet', length=15)
        })
    
        self.cmd('disk create -g {rg} -n {disk_name1} --size-gb 1 --sku Standard_LRS')
        vm = self.cmd('vm create -n {vm_name} -g {rg} --image Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest --attach-data-disks {disk_name1} '
                      '--admin-username rp_disk_test --subnet {subnet} --vnet-name {vnet} --size Standard_B2ms --nsg-rule NONE').get_output_in_json()
    
        # Disable default outbound access
        self.cmd('network vnet subnet update -g {rg} --vnet-name {vnet} -n {subnet} --default-outbound-access false')
    
        self.kwargs.update({
            'vm_id': vm['id']
        })
        self.cmd('restore-point collection create -g {rg} --collection-name {collection_name} --source-id {vm_id}')
        self.cmd('restore-point create -g {rg} -n {point_name} --collection-name {collection_name}')
        disk_restore_point = self.cmd('restore-point show --resource-group {rg} --collection-name {collection_name} --name {point_name}').get_output_in_json()
        self.kwargs['disk_restore_point_id'] = disk_restore_point['sourceMetadata']['storageProfile']['dataDisks'][0]['diskRestorePoint']['id']
    
        self.cmd('disk create --resource-group {rg} --name {disk_name2} --sku Standard_LRS --size-gb 5 --source {disk_restore_point_id}').get_output_in_json()
        self.cmd('disk create --resource-group {rg} --name {disk_name3} --sku Standard_LRS --size-gb 5')
        copy_disk = self.cmd('disk create --resource-group {rg} --name {disk_name4} --source {disk_name3} --sku Standard_LRS --size-gb 5').get_output_in_json()
        copy_snapshot = self.cmd('snapshot create --resource-group {rg} --name {disk_name5} --source {disk_name3} --sku Standard_LRS --size-gb 5').get_output_in_json()
    
        self.kwargs.update({
            'copy_resource1_id': copy_disk['id'],
            'copy_resource2_id': copy_snapshot['id']
        })
>       self.cmd('vm disk attach -g {rg} --size 20 --sku Standard_LRS --vm-name {vm_name} --source-resource {copy_resource1_id} {copy_resource2_id} --new-names-of-sr {disk_name6} {disk_name7}'
                 ' --source-disk-rp {disk_restore_point_id} --new-names-of-rp {disk_name8}')

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:1492: 
                                        
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: 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:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:315: in in_process_execute
    raise ex.exception
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:669: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:737: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:717: 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:1075: in call
    result = poller.result()
             ^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:108: 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:130: in wait
    raise self.exception
src/azure-cli-core/azure/cli/core/aaz/poller.py:83: in start
    for polling_method in self.polling_generator:
                          ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:4055: in execute_operations
    self.pre_instance_update(self.ctx.vars.instance)
src/azure-cli/azure/cli/command_modules/vm/custom.py:2393: in pre_instance_update
    disk_lun = get_disk_lun(data_disks_list)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
                           _ 

data_disks = [{'caching': 'None', 'createOption': 'Attach', 'deleteOption': 'Detach', 'diskSizeGB': 1, ...}, {'caching': 'None', 'c...diskSizeGB': 20, ...}, {'caching': 'None', 'createOption': 'Restore', 'deleteOption': 'Detach', 'diskSizeGB': 20, ...}]

    def _get_disk_lun(data_disks):
        # start from 0, search for unused int for lun
        if not data_disks:
            return 0
    
>       existing_luns = sorted([d.lun for d in data_disks])
                                ^^^^^
E       AttributeError: 'dict' object has no attribute 'lun'

src/azure-cli/azure/cli/command_modules/vm/custom.py:184: AttributeError
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:1448
Failed test_vm_disk_attach_detach The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3643
Failed test_vm_disk_attach_detach_api The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3772
Failed test_vm_disk_attach_multiple_disks The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3829
Failed test_vm_disk_force_detach The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3701
Failed test_vm_disk_storage_sku The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3887
Failed test_vm_ultra_ssd_storage_sku The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3971
❌3.13
Type Test Case Error Message Line
Failed test_vm_custom_image self = <azure.cli.core.commands.AzCliCommandInvoker object at 0x7f0a46512990>
parsed_ns = Namespace(log_verbosity_verbose=False, log_verbosity_debug=False, log_verbosity_only_show_errors=False, output_for...ngeTag object at 0x7f0a4622f390>, <azure.cli.core.breaking_change.UpcomingBreakingChangeTag object at 0x7f0a4622f390>])

    def validation(self, parsed_ns):
        try:
            cmd_validator = getattr(parsed_ns, 'command_validator', None)
            if cmd_validator:
>               self.validate_cmd_level(parsed_ns, cmd_validator)

env/lib/python3.13/site-packages/knack/invocation.py:111: 
 
 
 
 
 
 
                                  
src/azure-cli-core/azure/cli/core/commands/init.py:918: in validate_cmd_level
    cmd_validator(**self.build_kwargs(cmd_validator, ns))
src/azure-cli/azure/cli/command_modules/vm/validators.py:1537: in process_vm_create_namespace
    validate_vm_create_storage_profile(cmd, namespace)
src/azure-cli/azure/cli/command_modules/vm/validators.py:391: in validate_vm_create_storage_profile
    image_type = parse_image_argument(cmd, namespace)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/validators.py:279: in parse_image_argument
    images = load_images_from_aliases_doc(cmd.cli_ctx)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/actions.py:180: in load_images_from_aliases_doc
    response = requests.get(target_url, verify=not should_disable_connection_verify())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.13/site-packages/requests/api.py:73: in get
    return request("get", url, params=params, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.13/site-packages/requests/api.py:59: in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.13/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.13/site-packages/requests/sessions.py:703: in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.13/site-packages/requests/adapters.py:667: in send
    resp = conn.urlopen(
env/lib/python3.13/site-packages/urllib3/connectionpool.py:787: in urlopen
    response = self.make_request(
env/lib/python3.13/site-packages/urllib3/connectionpool.py:534: in make_request
    response = conn.getresponse()
               ^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
                            

self = <VCRRequestsHTTPSConnection/mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_custom_image.yaml(host='azcliprod.blob.core.windows.net', port=443) at 0x7f0a4602ca60>
 = 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)
        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 overwrite existing cassette ('/mnt/vss/work/1/s/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_custom_image.yaml') in your current record mode ('once').
E               No match for the request (<Request (GET) https://azcliprod.blob.core.windows.net/cli/vm/aliases.json>)&nbsp;was&nbsp;found.
E               Found 2 similar requests with 2 different matcher(s) :
E               
E               1 - (<Request (GET) https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json>).
E               Matchers succeeded : ['method', 'scheme', 'port', 'custom_request_query_matcher']
E               Matchers failed :
E               host - assertion failure :
E               azcliprod.blob.core.windows.net != raw.githubusercontent.com
E               path - assertion failure :
E               /cli/vm/aliases.json != /Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json
E               
E               2 - (<Request (GET) https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json>).
E               Matchers succeeded : ['method', 'scheme', 'port', 'custom_request_query_matcher']
E               Matchers failed :
E               host - assertion failure :
E               azcliprod.blob.core.windows.net != raw.githubusercontent.com
E               path - assertion failure :
E               /cli/vm/aliases.json != /Azure/azure-rest-api-specs/main/arm-compute/quickstart-templates/aliases.json

env/lib/python3.13/site-packages/vcr/stubs/init.py:277: CannotOverwriteExistingCassetteException

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.VMCustomImageTest testMethod=test_vm_custom_image>
resource_group = 'cli_test_vm_custom_image000001'

    @AllowLargeResponse(size_kb=99999)
    @ResourceGroupPreparer(name_prefix='cli_test_vm_custom_image')
    def test_vm_custom_image(self, resource_group):
        self.kwargs.update({
            'vm1': 'vm-unmanaged-disk',
            'vm2': 'vm-managed-disk',
            'newvm1': 'fromimage1',
            'newvm2': 'fromimage2',
            'image1': 'img-from-unmanaged',
            'image2': 'img-from-managed',
            'subnet': 'subnet1',
            'vnet': 'vnet1',
            'nsg': 'nsg',
            'pubip1': 'pubip1',
            'pubip2': 'pubip2',
            'pubip3': 'pubip3',
            'pubip4': 'pubip4',
            'pubip5': 'pubip5',
            'pubip6': 'pubip6',
            'pubip7': 'pubip7',
            'ssh_key': TEST_SSH_KEY_PUB,
        })
    
        # Create a public IP resource with service tag
        self.cmd('network public-ip create --name {pubip1} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm1} --image Debian:debian-10:10:latest '
            '--use-unmanaged-disk '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip1} --nsg-rule NONE'
        )
    
        # Disable default outbound access
        self.cmd(
            'network vnet subnet update -g {rg} --vnet-name {vnet} -n {subnet} --default-outbound-access false')
    
        # deprovision the VM, but we have to do it async to avoid hanging the run-command itself
        self.cmd('vm run-command invoke -g {rg} -n {vm1} --command-id RunShellScript --scripts "echo $0 $1" --parameters hello world')
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm1}')
        self.cmd('vm generalize -g {rg} -n {vm1}')
        self.cmd('image create -g {rg} -n {image1} --source {vm1}')
    
        # Create a public IP resource with service tag
        self.cmd('network public-ip create --name {pubip2} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
        self.cmd(
            'vm create -g {rg} -n {vm2} --image Debian:debian-10:10:latest '
            '--storage-sku standard_lrs --data-disk-sizes-gb 1 1 1 1 '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip2} --nsg-rule NONE'
        )
        data_disks = self.cmd('vm show -g {rg} -n {vm2}').get_output_in_json()['storageProfile']['dataDisks']
        self.kwargs['disk_0_name'] = data_disks[0]['name']
        self.kwargs['disk_2_name'] = data_disks[2]['name']
    
        # detach the 0th and 2nd disks leaving disks at lun 1 and 3
        self.cmd('vm disk detach -n {disk_0_name} --vm-name {vm2} -g {rg}')
        self.cmd('vm disk detach -n {disk_2_name} --vm-name {vm2} -g {rg}')
    
        self.cmd('vm show -g {rg} -n {vm2}', checks=self.check("length(storageProfile.dataDisks)", 2))
    
        self.cmd('vm run-command invoke -g {rg} -n {vm2} --command-id RunShellScript --scripts "echo $0 $1" --parameters hello world')
        time.sleep(70)
        self.cmd('vm deallocate -g {rg} -n {vm2}')
        self.cmd('vm generalize -g {rg} -n {vm2}')
        self.cmd('image create -g {rg} -n {image2} --source {vm2}')
    
        # Create a public IP resource with service tag
        self.cmd('network public-ip create --name {pubip3} -g {rg} --ip-tags FirstPartyUsage=/NonProd')
>       self.cmd(
            'vm create -g {rg} -n {newvm1} --image {image1} '
            '--admin-username sdk-test-admin --admin-password testPassword0 '
            '--authentication-type password '
            '--subnet {subnet} --vnet-name {vnet} '
            '--size Standard_B2ms --public-ip-address {pubip3} --nsg-rule NONE'
        )

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:573: 
 
 
 
 
 
 
 
                                 
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: 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:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:303: in in_process_execute
    self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
env/lib/python3.13/site-packages/knack/cli.py:250: in invoke
    raise ex
env/lib/python3.13/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:657: in execute
    self.validation(expanded_arg)
env/lib/python3.13/site-packages/knack/invocation.py:118: in validation
    getattr(parsed_ns, 'parser', self.parser).validation_error(str(err))
src/azure-cli-core/azure/cli/core/parser.py:150: in validation_error
    self.exit(2)
 
 
 
 
                                   _ 

self = AzCliCommandParser(prog='az vm create', usage=None, description='', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
status = 2, message = None

    def exit(self, status=0, message=None):
        if message:
            self._print_message(message, _sys.stderr)
>       _sys.exit(status)
E       SystemExit: 2

/opt/hostedtoolcache/Python/3.13.11/x64/lib/python3.13/argparse.py:2645: SystemExit
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:501
Failed test_vm_disk_attach_from_copy_and_restore self = <azure.cli.testsdk.base.ExecutionResult object at 0x7f0a46378c80>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7f0a499f2710>
command = 'vm disk attach -g cli_test_vm_disk_attach_from_copy_and_restore000001 --size 20 --sku Standard_LRS --vm-name vm_00000...rePoints/point_000004/diskRestorePoints/disk_000005_43f1765e-f52d-4d18-8397-927d883cb921 --new-names-of-rp disk_000012'
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:303: 
                                        
env/lib/python3.13/site-packages/knack/cli.py:245: in invoke
    exit_code = self.exception_handler(ex)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/init.py:135: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
                                        

ex = AttributeError("'dict' object has no attribute 'lun'"), args = ()
kwargs = {}

    def handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
        if isinstance(ex, CannotOverwriteExistingCassetteException):
            # This exception usually caused by a no match HTTP request. This is a product error
            # that is caused by change of SDK invocation.
            raise ex
    
>       raise CliExecutionError(ex)
E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception AttributeError during execution and fails the command.

src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: CliExecutionError

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.VMManagedDiskScenarioTest testMethod=test_vm_disk_attach_from_copy_and_restore>

    @AllowLargeResponse(size_kb=99999)
    @ResourceGroupPreparer('cli_test_vm_disk_attach_from_copy_and_restore', location='eastus2euap')
    def test_vm_disk_attach_from_copy_and_restore(self):
        self.kwargs.update({
            'vm_name': self.create_random_name('vm
', length=15),
            'collection_name': self.create_random_name('collection
', length=20),
            'point_name': self.create_random_name('point_', length=15),
            'disk_name1': self.create_random_name('disk_', length=15),
            'disk_name2': self.create_random_name('disk_', length=15),
            'disk_name3': self.create_random_name('disk_', length=15),
            'disk_name4': self.create_random_name('disk_', length=15),
            'disk_name5': self.create_random_name('disk_', length=15),
            'disk_name6': self.create_random_name('disk_', length=15),
            'disk_name7': self.create_random_name('disk_', length=15),
            'disk_name8': self.create_random_name('disk_', length=15),
            'subnet': self.create_random_name('subnet', length=15),
            'vnet': self.create_random_name('vnet', length=15)
        })
    
        self.cmd('disk create -g {rg} -n {disk_name1} --size-gb 1 --sku Standard_LRS')
        vm = self.cmd('vm create -n {vm_name} -g {rg} --image Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest --attach-data-disks {disk_name1} '
                      '--admin-username rp_disk_test --subnet {subnet} --vnet-name {vnet} --size Standard_B2ms --nsg-rule NONE').get_output_in_json()
    
        # Disable default outbound access
        self.cmd('network vnet subnet update -g {rg} --vnet-name {vnet} -n {subnet} --default-outbound-access false')
    
        self.kwargs.update({
            'vm_id': vm['id']
        })
        self.cmd('restore-point collection create -g {rg} --collection-name {collection_name} --source-id {vm_id}')
        self.cmd('restore-point create -g {rg} -n {point_name} --collection-name {collection_name}')
        disk_restore_point = self.cmd('restore-point show --resource-group {rg} --collection-name {collection_name} --name {point_name}').get_output_in_json()
        self.kwargs['disk_restore_point_id'] = disk_restore_point['sourceMetadata']['storageProfile']['dataDisks'][0]['diskRestorePoint']['id']
    
        self.cmd('disk create --resource-group {rg} --name {disk_name2} --sku Standard_LRS --size-gb 5 --source {disk_restore_point_id}').get_output_in_json()
        self.cmd('disk create --resource-group {rg} --name {disk_name3} --sku Standard_LRS --size-gb 5')
        copy_disk = self.cmd('disk create --resource-group {rg} --name {disk_name4} --source {disk_name3} --sku Standard_LRS --size-gb 5').get_output_in_json()
        copy_snapshot = self.cmd('snapshot create --resource-group {rg} --name {disk_name5} --source {disk_name3} --sku Standard_LRS --size-gb 5').get_output_in_json()
    
        self.kwargs.update({
            'copy_resource1_id': copy_disk['id'],
            'copy_resource2_id': copy_snapshot['id']
        })
>       self.cmd('vm disk attach -g {rg} --size 20 --sku Standard_LRS --vm-name {vm_name} --source-resource {copy_resource1_id} {copy_resource2_id} --new-names-of-sr {disk_name6} {disk_name7}'
                 ' --source-disk-rp {disk_restore_point_id} --new-names-of-rp {disk_name8}')

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:1492: 
                                        
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: 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:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:315: in in_process_execute
    raise ex.exception
env/lib/python3.13/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:669: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:737: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:717: 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:1075: in call
    result = poller.result()
             ^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/aaz/poller.py:108: in result
    self.wait(timeout)
env/lib/python3.13/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:130: in wait
    raise self.exception
src/azure-cli-core/azure/cli/core/aaz/poller.py:83: in start
    for polling_method in self.polling_generator:
                          ^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__cmds.py:1833: in execute_operations
    self.pre_instance_update(self.ctx.vars.instance)
src/azure-cli/azure/cli/command_modules/vm/custom.py:2393: in pre_instance_update
    disk_lun = get_disk_lun(data_disks_list)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
 
 
 
 
 
 
 
 
 
 
                           _ 

data_disks = [{'caching': 'None', 'createOption': 'Attach', 'deleteOption': 'Detach', 'diskSizeGB': 1, ...}, {'caching': 'None', 'c...diskSizeGB': 20, ...}, {'caching': 'None', 'createOption': 'Restore', 'deleteOption': 'Detach', 'diskSizeGB': 20, ...}]

    def _get_disk_lun(data_disks):
        # start from 0, search for unused int for lun
        if not data_disks:
            return 0
    
>       existing_luns = sorted([d.lun for d in data_disks])
                                ^^^^^
E       AttributeError: 'dict' object has no attribute 'lun'

src/azure-cli/azure/cli/command_modules/vm/custom.py:184: AttributeError
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:1448
Failed test_vm_disk_attach_detach The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3643
Failed test_vm_disk_attach_detach_api The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3772
Failed test_vm_disk_attach_multiple_disks The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3829
Failed test_vm_disk_force_detach The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3701
Failed test_vm_disk_storage_sku The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3887
Failed test_vm_ultra_ssd_storage_sku The error message is too long, please check the pipeline log for details. azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:3971

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

Hi @huiii99,
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

azure-client-tools-bot-prd bot commented Jan 20, 2026

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Collaborator

yonzhan commented Jan 20, 2026

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

@github-actions
Copy link

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>

Copy link
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

Migrates az vm disk attach / az vm disk detach from handwritten SDK logic to AAZ-based implementations, with corresponding test and recording updates.

Changes:

  • Reworked managed disk attach/detach logic in vm/custom.py to use AAZ commands.
  • Updated scenario tests and re-recorded HTTP interactions for the new behavior / API versions.
  • Added a small safe_get helper for nested dict access used by the new detach flow.

Reviewed changes

Copilot reviewed 7 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/vm/custom.py Migrates VM disk attach/detach implementation to AAZ (core behavior change).
src/azure-cli/azure/cli/command_modules/vm/_vm_utils.py Adds safe_get helper for nested dict access used by new logic.
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py Updates VM scenario tests to reflect new behavior and VM create parameters.
src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_ultra_ssd_storage_sku.yaml Updates recordings for new compute API version.
src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_disk_storage_sku.yaml Updates recordings for new compute API version.
src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_disk_attach_from_copy_and_restore.yaml Updates recordings for new compute API version.
src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_disk_attach_detach_api.yaml Updates recordings for new compute API version.
Comments suppressed due to low confidence (1)

src/azure-cli/azure/cli/command_modules/vm/custom.py:2468

  • AttachDetachDataDisk expects snake_case element fields (disk_id, detach_option) but this list uses diskId/detachOption, which will likely be ignored and violate the required disk_id field. Also, this branch doesn't forward the no_wait parameter to the AAZ command. Use the AAZ arg names and include no_wait in command_args.
        for disk_item in disk_ids:
            disk = {'diskId': disk_item, 'detachOption': 'ForceDetach' if force_detach else None}
            data_disks.append(disk)
        result = AttachDetachDataDisk(cli_ctx=cmd.cli_ctx)(command_args={
            'vm_name': vm_name,
            'resource_group': resource_group_name,
            'data_disks_to_detach': data_disks
        })

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yanzhudd
Copy link
Contributor

Please keep the migrated code as consistent with the original code as possible, since the greater the implementation differences, the higher the risk of introducing issues.

fix: update recording

refactor: keep migrate code consistent

fix: remove unused import

dev
@huiii99 huiii99 force-pushed the vm-disk-attach-detach-migration-v3 branch from e3af2b6 to 6971cfe Compare January 27, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants