Skip to content

Commit 2482d24

Browse files
rashmichandrashekarbebound
authored andcommitted
[AKS] az aks enable-addons: Add support for default workspace creation in Bleu and Delos clouds (#32753)
1 parent fba9744 commit 2482d24

File tree

2 files changed

+329
-1
lines changed

2 files changed

+329
-1
lines changed

src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@
185185
"ussecwest": "ussecwest",
186186
}
187187

188+
# mapping for azure bleu cloud
189+
AzureBleuLocationToOmsRegionCodeMap = {
190+
"bleufrancecentral": "BLEUC",
191+
"bleufrancesouth": "BLEUS",
192+
}
193+
194+
AzureBleuRegionToOmsRegionMap = {
195+
"bleufrancecentral": "bleufrancecentral",
196+
"bleufrancesouth": "bleufrancesouth",
197+
}
198+
199+
# mapping for azure delos cloud
200+
AzureDelosLocationToOmsRegionCodeMap = {
201+
"deloscloudgermanycentral": "DELOSC",
202+
"deloscloudgermanynorth": "DELOSN",
203+
}
204+
205+
AzureDelosRegionToOmsRegionMap = {
206+
"deloscloudgermanycentral": "deloscloudgermanycentral",
207+
"deloscloudgermanynorth": "deloscloudgermanynorth",
208+
}
209+
188210
ContainerInsightsStreams = [
189211
"Microsoft-ContainerLog",
190212
"Microsoft-ContainerLogV2-HighScale",
@@ -245,7 +267,20 @@ def ensure_default_log_analytics_workspace_for_monitoring(
245267
workspace_region_code = AzureUSSecLocationToOmsRegionCodeMap.get(
246268
workspace_region, "USSW"
247269
)
248-
270+
elif cloud_name.lower() == "azurebleucloud":
271+
workspace_region = AzureBleuRegionToOmsRegionMap.get(
272+
rg_location, "bleufrancecentral"
273+
)
274+
workspace_region_code = AzureBleuLocationToOmsRegionCodeMap.get(
275+
workspace_region, "BLEUC"
276+
)
277+
elif cloud_name.lower() == "azuredeloscloud":
278+
workspace_region = AzureDelosRegionToOmsRegionMap.get(
279+
rg_location, "deloscloudgermanycentral"
280+
)
281+
workspace_region_code = AzureDelosLocationToOmsRegionCodeMap.get(
282+
workspace_region, "DELOSC"
283+
)
249284
else:
250285
logger.error(
251286
"AKS Monitoring addon not supported in cloud : %s", cloud_name

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_custom.py

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
CONST_KUBE_DASHBOARD_ADDON_NAME,
1919
CONST_MONITORING_ADDON_NAME,
2020
)
21+
from azure.cli.command_modules.acs.addonconfiguration import (
22+
ensure_default_log_analytics_workspace_for_monitoring,
23+
)
2124
from azure.cli.command_modules.acs.custom import (
2225
_get_command_context,
2326
_update_addons,
@@ -879,5 +882,295 @@ def test_get_command_context_valid(self):
879882
self.assertNotEqual(context, '')
880883

881884

885+
class TestAddonConfigurationAzureBleuCloud(unittest.TestCase):
886+
"""Test cases for AzureBleu Cloud region mapping in addon configuration."""
887+
888+
def setUp(self):
889+
self.cli = MockCLI()
890+
self.cmd = MockCmd(self.cli)
891+
# Set cloud name to AzureBleuCloud
892+
self.cmd.cli_ctx.cloud.name = 'AzureBleuCloud'
893+
894+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resources_client')
895+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resource_groups_client')
896+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_rg_location')
897+
def test_bleufrancecentral_region_mapping(self, mock_get_rg_location, mock_get_rg_client, mock_get_resources_client):
898+
"""Test that bleufrancecentral region maps correctly."""
899+
# Arrange
900+
mock_get_rg_location.return_value = 'bleufrancecentral'
901+
subscription_id = '00000000-0000-0000-0000-000000000000'
902+
resource_group_name = 'test-rg'
903+
904+
# Mock resource group client
905+
mock_rg_client = mock.Mock()
906+
mock_rg_client.check_existence.return_value = False
907+
mock_rg_client.create_or_update = mock.Mock()
908+
mock_get_rg_client.return_value = mock_rg_client
909+
910+
# Mock resources client
911+
mock_resources_client = mock.Mock()
912+
mock_poller = mock.Mock()
913+
mock_result = mock.Mock()
914+
mock_result.id = f'/subscriptions/{subscription_id}/resourceGroups/DefaultResourceGroup-BLEUC/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-{subscription_id}-BLEUC'
915+
mock_poller.result.return_value = mock_result
916+
mock_poller.done.return_value = True
917+
mock_resources_client.begin_create_or_update_by_id.return_value = mock_poller
918+
mock_get_resources_client.return_value = mock_resources_client
919+
920+
# Mock get_models for GenericResource
921+
self.cmd.get_models = mock.Mock(return_value=mock.Mock)
922+
923+
# Act
924+
result = ensure_default_log_analytics_workspace_for_monitoring(
925+
self.cmd, subscription_id, resource_group_name
926+
)
927+
928+
# Assert
929+
# Verify the resource group was created with correct region
930+
mock_rg_client.create_or_update.assert_called_once_with(
931+
'DefaultResourceGroup-BLEUC',
932+
{'location': 'bleufrancecentral'}
933+
)
934+
935+
# Verify the workspace resource ID contains the correct region code
936+
self.assertIn('DefaultResourceGroup-BLEUC', result)
937+
self.assertIn(f'DefaultWorkspace-{subscription_id}-BLEUC', result)
938+
939+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resources_client')
940+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resource_groups_client')
941+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_rg_location')
942+
def test_bleufrancesouth_region_mapping(self, mock_get_rg_location, mock_get_rg_client, mock_get_resources_client):
943+
"""Test that bleufrancesouth region maps correctly."""
944+
# Arrange
945+
mock_get_rg_location.return_value = 'bleufrancesouth'
946+
subscription_id = '00000000-0000-0000-0000-000000000000'
947+
resource_group_name = 'test-rg'
948+
949+
# Mock resource group client
950+
mock_rg_client = mock.Mock()
951+
mock_rg_client.check_existence.return_value = False
952+
mock_rg_client.create_or_update = mock.Mock()
953+
mock_get_rg_client.return_value = mock_rg_client
954+
955+
# Mock resources client
956+
mock_resources_client = mock.Mock()
957+
mock_poller = mock.Mock()
958+
mock_result = mock.Mock()
959+
mock_result.id = f'/subscriptions/{subscription_id}/resourceGroups/DefaultResourceGroup-BLEUS/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-{subscription_id}-BLEUS'
960+
mock_poller.result.return_value = mock_result
961+
mock_poller.done.return_value = True
962+
mock_resources_client.begin_create_or_update_by_id.return_value = mock_poller
963+
mock_get_resources_client.return_value = mock_resources_client
964+
965+
# Mock get_models for GenericResource
966+
self.cmd.get_models = mock.Mock(return_value=mock.Mock)
967+
968+
# Act
969+
result = ensure_default_log_analytics_workspace_for_monitoring(
970+
self.cmd, subscription_id, resource_group_name
971+
)
972+
973+
# Assert
974+
# Verify the resource group was created with correct region
975+
mock_rg_client.create_or_update.assert_called_once_with(
976+
'DefaultResourceGroup-BLEUS',
977+
{'location': 'bleufrancesouth'}
978+
)
979+
980+
# Verify the workspace resource ID contains the correct region code
981+
self.assertIn('DefaultResourceGroup-BLEUS', result)
982+
self.assertIn(f'DefaultWorkspace-{subscription_id}-BLEUS', result)
983+
984+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resources_client')
985+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resource_groups_client')
986+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_rg_location')
987+
def test_unknown_bleu_region_defaults_to_bleufrancecentral(self, mock_get_rg_location, mock_get_rg_client, mock_get_resources_client):
988+
"""Test that unknown regions in AzureBleu cloud default to bleufrancecentral."""
989+
# Arrange
990+
mock_get_rg_location.return_value = 'unknownregion'
991+
subscription_id = '00000000-0000-0000-0000-000000000000'
992+
resource_group_name = 'test-rg'
993+
994+
# Mock resource group client
995+
mock_rg_client = mock.Mock()
996+
mock_rg_client.check_existence.return_value = False
997+
mock_rg_client.create_or_update = mock.Mock()
998+
mock_get_rg_client.return_value = mock_rg_client
999+
1000+
# Mock resources client
1001+
mock_resources_client = mock.Mock()
1002+
mock_poller = mock.Mock()
1003+
mock_result = mock.Mock()
1004+
mock_result.id = f'/subscriptions/{subscription_id}/resourceGroups/DefaultResourceGroup-BLEUC/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-{subscription_id}-BLEUC'
1005+
mock_poller.result.return_value = mock_result
1006+
mock_poller.done.return_value = True
1007+
mock_resources_client.begin_create_or_update_by_id.return_value = mock_poller
1008+
mock_get_resources_client.return_value = mock_resources_client
1009+
1010+
# Mock get_models for GenericResource
1011+
self.cmd.get_models = mock.Mock(return_value=mock.Mock)
1012+
1013+
# Act
1014+
result = ensure_default_log_analytics_workspace_for_monitoring(
1015+
self.cmd, subscription_id, resource_group_name
1016+
)
1017+
1018+
# Assert
1019+
# Verify the resource group was created with default region
1020+
mock_rg_client.create_or_update.assert_called_once_with(
1021+
'DefaultResourceGroup-BLEUC',
1022+
{'location': 'bleufrancecentral'}
1023+
)
1024+
1025+
# Verify the workspace resource ID contains the default region code
1026+
self.assertIn('DefaultResourceGroup-BLEUC', result)
1027+
self.assertIn(f'DefaultWorkspace-{subscription_id}-BLEUC', result)
1028+
1029+
1030+
class TestAddonConfigurationAzureDelosCloud(unittest.TestCase):
1031+
"""Test cases for AzureDelos Cloud region mapping in addon configuration."""
1032+
1033+
def setUp(self):
1034+
self.cli = MockCLI()
1035+
self.cmd = MockCmd(self.cli)
1036+
# Set cloud name to AzureDelosCloud
1037+
self.cmd.cli_ctx.cloud.name = 'AzureDelosCloud'
1038+
1039+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resources_client')
1040+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resource_groups_client')
1041+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_rg_location')
1042+
def test_deloscloudgermanycentral_region_mapping(self, mock_get_rg_location, mock_get_rg_client, mock_get_resources_client):
1043+
"""Test that deloscloudgermanycentral region maps correctly."""
1044+
# Arrange
1045+
mock_get_rg_location.return_value = 'deloscloudgermanycentral'
1046+
subscription_id = '00000000-0000-0000-0000-000000000000'
1047+
resource_group_name = 'test-rg'
1048+
1049+
# Mock resource group client
1050+
mock_rg_client = mock.Mock()
1051+
mock_rg_client.check_existence.return_value = False
1052+
mock_rg_client.create_or_update = mock.Mock()
1053+
mock_get_rg_client.return_value = mock_rg_client
1054+
1055+
# Mock resources client
1056+
mock_resources_client = mock.Mock()
1057+
mock_poller = mock.Mock()
1058+
mock_result = mock.Mock()
1059+
mock_result.id = f'/subscriptions/{subscription_id}/resourceGroups/DefaultResourceGroup-DELOSC/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-{subscription_id}-DELOSC'
1060+
mock_poller.result.return_value = mock_result
1061+
mock_poller.done.return_value = True
1062+
mock_resources_client.begin_create_or_update_by_id.return_value = mock_poller
1063+
mock_get_resources_client.return_value = mock_resources_client
1064+
1065+
# Mock get_models for GenericResource
1066+
self.cmd.get_models = mock.Mock(return_value=mock.Mock)
1067+
1068+
# Act
1069+
result = ensure_default_log_analytics_workspace_for_monitoring(
1070+
self.cmd, subscription_id, resource_group_name
1071+
)
1072+
1073+
# Assert
1074+
# Verify the resource group was created with correct region
1075+
mock_rg_client.create_or_update.assert_called_once_with(
1076+
'DefaultResourceGroup-DELOSC',
1077+
{'location': 'deloscloudgermanycentral'}
1078+
)
1079+
1080+
# Verify the workspace resource ID contains the correct region code
1081+
self.assertIn('DefaultResourceGroup-DELOSC', result)
1082+
self.assertIn(f'DefaultWorkspace-{subscription_id}-DELOSC', result)
1083+
1084+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resources_client')
1085+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resource_groups_client')
1086+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_rg_location')
1087+
def test_deloscloudgermanynorth_region_mapping(self, mock_get_rg_location, mock_get_rg_client, mock_get_resources_client):
1088+
"""Test that deloscloudgermanynorth region maps correctly."""
1089+
# Arrange
1090+
mock_get_rg_location.return_value = 'deloscloudgermanynorth'
1091+
subscription_id = '00000000-0000-0000-0000-000000000000'
1092+
resource_group_name = 'test-rg'
1093+
1094+
# Mock resource group client
1095+
mock_rg_client = mock.Mock()
1096+
mock_rg_client.check_existence.return_value = False
1097+
mock_rg_client.create_or_update = mock.Mock()
1098+
mock_get_rg_client.return_value = mock_rg_client
1099+
1100+
# Mock resources client
1101+
mock_resources_client = mock.Mock()
1102+
mock_poller = mock.Mock()
1103+
mock_result = mock.Mock()
1104+
mock_result.id = f'/subscriptions/{subscription_id}/resourceGroups/DefaultResourceGroup-DELOSN/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-{subscription_id}-DELOSN'
1105+
mock_poller.result.return_value = mock_result
1106+
mock_poller.done.return_value = True
1107+
mock_resources_client.begin_create_or_update_by_id.return_value = mock_poller
1108+
mock_get_resources_client.return_value = mock_resources_client
1109+
1110+
# Mock get_models for GenericResource
1111+
self.cmd.get_models = mock.Mock(return_value=mock.Mock)
1112+
1113+
# Act
1114+
result = ensure_default_log_analytics_workspace_for_monitoring(
1115+
self.cmd, subscription_id, resource_group_name
1116+
)
1117+
1118+
# Assert
1119+
# Verify the resource group was created with correct region
1120+
mock_rg_client.create_or_update.assert_called_once_with(
1121+
'DefaultResourceGroup-DELOSN',
1122+
{'location': 'deloscloudgermanynorth'}
1123+
)
1124+
1125+
# Verify the workspace resource ID contains the correct region code
1126+
self.assertIn('DefaultResourceGroup-DELOSN', result)
1127+
self.assertIn(f'DefaultWorkspace-{subscription_id}-DELOSN', result)
1128+
1129+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resources_client')
1130+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_resource_groups_client')
1131+
@mock.patch('azure.cli.command_modules.acs.addonconfiguration.get_rg_location')
1132+
def test_unknown_delos_region_defaults_to_deloscloudgermanycentral(self, mock_get_rg_location, mock_get_rg_client, mock_get_resources_client):
1133+
"""Test that unknown regions in AzureDelos cloud default to deloscloudgermanycentral."""
1134+
# Arrange
1135+
mock_get_rg_location.return_value = 'unknownregion'
1136+
subscription_id = '00000000-0000-0000-0000-000000000000'
1137+
resource_group_name = 'test-rg'
1138+
1139+
# Mock resource group client
1140+
mock_rg_client = mock.Mock()
1141+
mock_rg_client.check_existence.return_value = False
1142+
mock_rg_client.create_or_update = mock.Mock()
1143+
mock_get_rg_client.return_value = mock_rg_client
1144+
1145+
# Mock resources client
1146+
mock_resources_client = mock.Mock()
1147+
mock_poller = mock.Mock()
1148+
mock_result = mock.Mock()
1149+
mock_result.id = f'/subscriptions/{subscription_id}/resourceGroups/DefaultResourceGroup-DELOSC/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-{subscription_id}-DELOSC'
1150+
mock_poller.result.return_value = mock_result
1151+
mock_poller.done.return_value = True
1152+
mock_resources_client.begin_create_or_update_by_id.return_value = mock_poller
1153+
mock_get_resources_client.return_value = mock_resources_client
1154+
1155+
# Mock get_models for GenericResource
1156+
self.cmd.get_models = mock.Mock(return_value=mock.Mock)
1157+
1158+
# Act
1159+
result = ensure_default_log_analytics_workspace_for_monitoring(
1160+
self.cmd, subscription_id, resource_group_name
1161+
)
1162+
1163+
# Assert
1164+
# Verify the resource group was created with default region
1165+
mock_rg_client.create_or_update.assert_called_once_with(
1166+
'DefaultResourceGroup-DELOSC',
1167+
{'location': 'deloscloudgermanycentral'}
1168+
)
1169+
1170+
# Verify the workspace resource ID contains the default region code
1171+
self.assertIn('DefaultResourceGroup-DELOSC', result)
1172+
self.assertIn(f'DefaultWorkspace-{subscription_id}-DELOSC', result)
1173+
1174+
8821175
if __name__ == "__main__":
8831176
unittest.main()

0 commit comments

Comments
 (0)