From 818f1e25a1592509a6012fee070623908937ba64 Mon Sep 17 00:00:00 2001 From: ximeng zhao Date: Thu, 26 Mar 2026 01:57:54 +0000 Subject: [PATCH 1/5] Fix the location logic for managed namespace update operation --- .../command_modules/acs/managednamespace.py | 2 +- .../acs/tests/latest/test_managednamespace.py | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/managednamespace.py b/src/azure-cli/azure/cli/command_modules/acs/managednamespace.py index 3c409192d7c..04d4ada77ae 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/managednamespace.py +++ b/src/azure-cli/azure/cli/command_modules/acs/managednamespace.py @@ -201,7 +201,7 @@ def aks_managed_namespace_update(cmd, client, raw_parameters, headers, existedNa namespace_name = raw_parameters.get("name") namespace_config = updateNamespace(cmd, raw_parameters, existedNamespace) - namespace_config.location = get_cluster_location(cmd, resource_group_name, cluster_name) + namespace_config.location = existedNamespace.location return sdk_no_wait( no_wait, diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py index ade3263dc13..297ec266580 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py @@ -274,6 +274,51 @@ def test_update_managed_namespace_with_invalid_delete_policy(self, mock_get_clie with self.assertRaises(InvalidArgumentValueError) as cm: ns.aks_managed_namespace_update(cmd, None, raw_parameters, None, None, False) self.assertIn(err, str(cm.exception)) + + def test_update_managed_namespace_sets_location_from_existing_namespace(self, mock_get_client): + cli_ctx = MockCLI() + cmd = MockCmd(cli_ctx) + + mock_client = Mock() + + existing_ns = Mock() + existing_ns.name = "test_managed_namespace" + existing_ns.location = "westus2" + existing_ns.properties.default_resource_quota.cpu_request = "300m" + existing_ns.properties.default_resource_quota.cpu_limit = "500m" + existing_ns.properties.default_resource_quota.memory_request = "1Gi" + existing_ns.properties.default_resource_quota.memory_limit = "2Gi" + existing_ns.properties.default_network_policy.ingress = "DenyAll" + existing_ns.properties.default_network_policy.egress = "AllowAll" + existing_ns.properties.adoption_policy = "Never" + existing_ns.properties.delete_policy = "Keep" + + raw_parameters = { + "resource_group_name": "test_rg", + "cluster_name": "test_cluster", + "name": "test_managed_namespace", + "tags": {}, + "labels": None, + "annotations": ["a=c"], + "cpu_request": None, + "cpu_limit": None, + "memory_request": None, + "memory_limit": None, + "ingress_policy": None, + "egress_policy": None, + "adoption_policy": None, + "delete_policy": None, + } + + ns.aks_managed_namespace_update(cmd, mock_client, raw_parameters, None, existing_ns, False) + + # The namespace passed to begin_create_or_update should carry the existing location + call_args = mock_client.begin_create_or_update.call_args + namespace_config = call_args[0][3] # 4th positional arg + self.assertEqual(namespace_config.location, "westus2") + + # No managed cluster GET should be needed for the update path + mock_get_client.assert_not_called() if __name__ == "__main__": From 092ae656496d0c176631ad28ba375d941c0bf44f Mon Sep 17 00:00:00 2001 From: ximeng zhao Date: Thu, 26 Mar 2026 02:18:30 +0000 Subject: [PATCH 2/5] remove trailing space --- .../command_modules/acs/tests/latest/test_managednamespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py index 297ec266580..5e7d0135fb8 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py @@ -274,7 +274,7 @@ def test_update_managed_namespace_with_invalid_delete_policy(self, mock_get_clie with self.assertRaises(InvalidArgumentValueError) as cm: ns.aks_managed_namespace_update(cmd, None, raw_parameters, None, None, False) self.assertIn(err, str(cm.exception)) - + def test_update_managed_namespace_sets_location_from_existing_namespace(self, mock_get_client): cli_ctx = MockCLI() cmd = MockCmd(cli_ctx) From fabd7a4517fd9fdf93ae4ab96e386b034e6f42a7 Mon Sep 17 00:00:00 2001 From: ximeng zhao Date: Thu, 26 Mar 2026 02:35:57 +0000 Subject: [PATCH 3/5] push a comment --- .../command_modules/acs/tests/latest/test_managednamespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py index 5e7d0135fb8..2e87fe91fdb 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py @@ -312,7 +312,7 @@ def test_update_managed_namespace_sets_location_from_existing_namespace(self, mo ns.aks_managed_namespace_update(cmd, mock_client, raw_parameters, None, existing_ns, False) - # The namespace passed to begin_create_or_update should carry the existing location + # The namespace that passed to begin_create_or_update should carry the existing location call_args = mock_client.begin_create_or_update.call_args namespace_config = call_args[0][3] # 4th positional arg self.assertEqual(namespace_config.location, "westus2") From 2ede9091a50c33beb4a4795cee145c240469ebc4 Mon Sep 17 00:00:00 2001 From: ximeng zhao Date: Thu, 26 Mar 2026 03:18:43 +0000 Subject: [PATCH 4/5] update the PR title --- .../command_modules/acs/tests/latest/test_managednamespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py index 2e87fe91fdb..5e7d0135fb8 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py @@ -312,7 +312,7 @@ def test_update_managed_namespace_sets_location_from_existing_namespace(self, mo ns.aks_managed_namespace_update(cmd, mock_client, raw_parameters, None, existing_ns, False) - # The namespace that passed to begin_create_or_update should carry the existing location + # The namespace passed to begin_create_or_update should carry the existing location call_args = mock_client.begin_create_or_update.call_args namespace_config = call_args[0][3] # 4th positional arg self.assertEqual(namespace_config.location, "westus2") From cb28ba9ccac33f827cfbb2d58516bf0695516c86 Mon Sep 17 00:00:00 2001 From: ximeng zhao Date: Thu, 26 Mar 2026 03:32:34 +0000 Subject: [PATCH 5/5] fixed PR title --- .../command_modules/acs/tests/latest/test_managednamespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py index 5e7d0135fb8..2e87fe91fdb 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py +++ b/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py @@ -312,7 +312,7 @@ def test_update_managed_namespace_sets_location_from_existing_namespace(self, mo ns.aks_managed_namespace_update(cmd, mock_client, raw_parameters, None, existing_ns, False) - # The namespace passed to begin_create_or_update should carry the existing location + # The namespace that passed to begin_create_or_update should carry the existing location call_args = mock_client.begin_create_or_update.call_args namespace_config = call_args[0][3] # 4th positional arg self.assertEqual(namespace_config.location, "westus2")