Skip to content

Commit 3ad9f41

Browse files
authored
[AKS] az aks create/update: Update the VM SKU regex validation to include larger set of VMs for Azure Container Storage (#29726)
1 parent f806cf6 commit 3ad9f41

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

src/azure-cli/azure/cli/command_modules/acs/azurecontainerstorage/_helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,15 @@ def get_desired_resource_value_args(
414414
# Returns -1 if there is a problem with parsing the vm_size.
415415
def get_cores_from_sku(vm_size):
416416
cpu_value = -1
417-
pattern = r'standard_([a-z]+)(\d+)([a-z]*)_v(\d+)'
417+
pattern = r'([a-z])+(\d+)[a-z]*(?=_v(\d+)[^_]*$|$)'
418418
match = re.search(pattern, vm_size.lower())
419419
if match:
420420
series_prefix = match.group(1)
421421
size_val = int(match.group(2))
422-
version = int(match.group(4))
422+
version_val = match.group(3)
423+
version = -1
424+
if version_val is not None:
425+
version = int(version_val)
423426

424427
cpu_value = size_val
425428
# https://learn.microsoft.com/en-us/azure/virtual-machines/dv2-dsv2-series

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,91 @@ def test_enable_with_premiumv2_sku_and_azure_disk(self):
985985
)
986986
self.assertEqual(str(cm.exception), err)
987987

988+
def test_enable_with_insufficient_cores_1(self):
989+
storage_pool_name = "valid-name"
990+
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
991+
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
992+
nodepool_list = "pool1"
993+
agentpools = [{"name": "pool1", "vm_size": "Standard_D2s_v2", "count": 3, "zoned": False}]
994+
err = (
995+
"Cannot operate Azure Container Storage on a node pool consisting of "
996+
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_D2s_v2 "
997+
"which is assigned for Azure Container Storage has nodes with 2 cores."
998+
)
999+
with self.assertRaises(InvalidArgumentValueError) as cm:
1000+
acstor_validator.validate_enable_azure_container_storage_params(
1001+
storage_pool_type, storage_pool_name, storage_pool_sku, None, None, nodepool_list, agentpools, False, False, False, False, False, None, None, acstor_consts.CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD
1002+
)
1003+
self.assertEqual(str(cm.exception), err)
1004+
1005+
def test_enable_with_insufficient_cores_2(self):
1006+
storage_pool_name = "valid-name"
1007+
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
1008+
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
1009+
nodepool_list = "pool1"
1010+
agentpools = [{"name": "pool1", "vm_size": "Standard_H100-D2s_v2", "count": 3, "zoned": False}]
1011+
err = (
1012+
"Cannot operate Azure Container Storage on a node pool consisting of "
1013+
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_H100-D2s_v2 "
1014+
"which is assigned for Azure Container Storage has nodes with 2 cores."
1015+
)
1016+
with self.assertRaises(InvalidArgumentValueError) as cm:
1017+
acstor_validator.validate_enable_azure_container_storage_params(
1018+
storage_pool_type, storage_pool_name, storage_pool_sku, None, None, nodepool_list, agentpools, False, False, False, False, False, None, None, acstor_consts.CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD
1019+
)
1020+
self.assertEqual(str(cm.exception), err)
1021+
1022+
def test_enable_with_insufficient_cores_3(self):
1023+
storage_pool_name = "valid-name"
1024+
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
1025+
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
1026+
nodepool_list = "pool1"
1027+
agentpools = [{"name": "pool1", "vm_size": "Standard_H100-D2s", "count": 3, "zoned": False}]
1028+
err = (
1029+
"Cannot operate Azure Container Storage on a node pool consisting of "
1030+
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_H100-D2s "
1031+
"which is assigned for Azure Container Storage has nodes with 2 cores."
1032+
)
1033+
with self.assertRaises(InvalidArgumentValueError) as cm:
1034+
acstor_validator.validate_enable_azure_container_storage_params(
1035+
storage_pool_type, storage_pool_name, storage_pool_sku, None, None, nodepool_list, agentpools, False, False, False, False, False, None, None, acstor_consts.CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD
1036+
)
1037+
self.assertEqual(str(cm.exception), err)
1038+
1039+
def test_enable_with_insufficient_cores_4(self):
1040+
storage_pool_name = "valid-name"
1041+
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
1042+
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
1043+
nodepool_list = "pool1"
1044+
agentpools = [{"name": "pool1", "vm_size": "Standard_H2", "count": 3, "zoned": False}]
1045+
err = (
1046+
"Cannot operate Azure Container Storage on a node pool consisting of "
1047+
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_H2 "
1048+
"which is assigned for Azure Container Storage has nodes with 2 cores."
1049+
)
1050+
with self.assertRaises(InvalidArgumentValueError) as cm:
1051+
acstor_validator.validate_enable_azure_container_storage_params(
1052+
storage_pool_type, storage_pool_name, storage_pool_sku, None, None, nodepool_list, agentpools, False, False, False, False, False, None, None, acstor_consts.CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD
1053+
)
1054+
self.assertEqual(str(cm.exception), err)
1055+
1056+
def test_enable_with_insufficient_cores_5(self):
1057+
storage_pool_name = "valid-name"
1058+
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
1059+
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
1060+
nodepool_list = "pool1"
1061+
agentpools = [{"name": "pool1", "vm_size": "Standard_D2s", "count": 3, "zoned": False}]
1062+
err = (
1063+
"Cannot operate Azure Container Storage on a node pool consisting of "
1064+
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_D2s "
1065+
"which is assigned for Azure Container Storage has nodes with 2 cores."
1066+
)
1067+
with self.assertRaises(InvalidArgumentValueError) as cm:
1068+
acstor_validator.validate_enable_azure_container_storage_params(
1069+
storage_pool_type, storage_pool_name, storage_pool_sku, None, None, nodepool_list, agentpools, False, False, False, False, False, None, None, acstor_consts.CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD
1070+
)
1071+
self.assertEqual(str(cm.exception), err)
1072+
9881073
def test_enable_with_option_and_non_ephemeral_disk_pool(self):
9891074
storage_pool_name = "valid-name"
9901075
storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_NVME

0 commit comments

Comments
 (0)