From 8f26c3f182c7f1dbd0b3adfd3d7e486c9d32791b Mon Sep 17 00:00:00 2001 From: WhaleTech <304937387+ryo-whaletech@users.noreply.github.com> Date: Fri, 11 Sep 2026 15:39:47 +0900 Subject: [PATCH] {Compute} Fix VMSS zone placement filter switching --- .../azure/cli/command_modules/vm/custom.py | 2 ++ .../tests/latest/test_custom_vm_commands.py | 33 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py index 131be9743ca..72eb4025978 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -5150,9 +5150,11 @@ def _output(self, *args, **kwargs): if include_zones is not None: vmss["placement"]["include_zones"] = include_zones + vmss["placement"].pop("exclude_zones", None) if exclude_zones is not None: vmss["placement"]["exclude_zones"] = exclude_zones + vmss["placement"].pop("include_zones", None) from .operations.vmss import VMSSCreate return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss) diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py index 4ab2527a4aa..5114da33de3 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_custom_vm_commands.py @@ -16,7 +16,7 @@ _get_extension_instance_name, get_boot_log) from azure.cli.command_modules.vm.custom import \ - (attach_unmanaged_data_disk, detach_unmanaged_data_disk, get_vmss_instance_view) + (attach_unmanaged_data_disk, detach_unmanaged_data_disk, get_vmss_instance_view, update_vmss) from azure.cli.core import AzCommandsLoader from azure.cli.core.commands import AzCliCommand @@ -166,6 +166,37 @@ def test_get_extension_instance_name_when_type_none(self): # assert self.assertEqual(result, 'extension-name') + @mock.patch('azure.cli.command_modules.vm.operations.vmss.VMSSCreate') + def test_update_vmss_switches_zone_placement_filter(self, vmss_create_mock): + transitions = ( + ('includeZones', ['1'], 'exclude_zones', ['2'], 'include_zones'), + ('excludeZones', ['2'], 'include_zones', ['1'], 'exclude_zones'), + ) + + for existing_key, existing_value, new_key, new_value, stale_key in transitions: + with self.subTest(existing_key=existing_key, new_key=new_key): + vmss_create_mock.reset_mock() + parameters = { + 'location': 'eastus2', + 'placement': { + 'zonePlacementPolicy': 'Auto', + existing_key: existing_value, + }, + } + + update_vmss( + _get_test_cmd(), + 'resource-group', + 'vmss-name', + parameters=parameters, + **{new_key: new_value} + ) + + command_args = vmss_create_mock.return_value.call_args.kwargs['command_args'] + placement = command_args['placement'] + self.assertEqual(new_value, placement[new_key]) + self.assertNotIn(stale_key, placement) + class TestVMBootLog(unittest.TestCase):