Skip to content

Commit

Permalink
Some regex fix + unit test added
Browse files Browse the repository at this point in the history
  • Loading branch information
mukhoakash committed Aug 27, 2024
1 parent 5a1c7c0 commit 3984671
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def get_desired_resource_value_args(
# Returns -1 if there is a problem with parsing the vm_size.
def get_cores_from_sku(vm_size):
cpu_value = -1
pattern = r'standard_([a-z]+)(\d+)([a-z]*)(?:_[^_]+)*_v(\d+)'
pattern = r'(\d+)([a-z])*(?=_v(\d+)[^_]*$|$)'
match = re.search(pattern, vm_size.lower())
if match:
series_prefix = match.group(1)
Expand Down
85 changes: 85 additions & 0 deletions src/aks-preview/azext_aks_preview/tests/latest/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,91 @@ def test_enable_with_premiumv2_sku_and_azure_disk(self):
)
self.assertEqual(str(cm.exception), err)

def test_enable_with_insufficient_cores_1(self):
storage_pool_name = "valid-name"
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
nodepool_list = "pool1"
agentpools = [{"name": "pool1", "vm_size": "Standard_D2s_v2", "count": 3, "zoned": False}]
err = (
"Cannot operate Azure Container Storage on a node pool consisting of "
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_D2s_v2 "
"which is assigned for Azure Container Storage has nodes with 2 cores."
)
with self.assertRaises(InvalidArgumentValueError) as cm:
acstor_validator.validate_enable_azure_container_storage_params(
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
)
self.assertEqual(str(cm.exception), err)

def test_enable_with_insufficient_cores_2(self):
storage_pool_name = "valid-name"
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
nodepool_list = "pool1"
agentpools = [{"name": "pool1", "vm_size": "Standard_H100-D2s_v2", "count": 3, "zoned": False}]
err = (
"Cannot operate Azure Container Storage on a node pool consisting of "
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_H100-D2s_v2 "
"which is assigned for Azure Container Storage has nodes with 2 cores."
)
with self.assertRaises(InvalidArgumentValueError) as cm:
acstor_validator.validate_enable_azure_container_storage_params(
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
)
self.assertEqual(str(cm.exception), err)

def test_enable_with_insufficient_cores_3(self):
storage_pool_name = "valid-name"
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
nodepool_list = "pool1"
agentpools = [{"name": "pool1", "vm_size": "Standard_H100-D2s", "count": 3, "zoned": False}]
err = (
"Cannot operate Azure Container Storage on a node pool consisting of "
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_H100-D2s "
"which is assigned for Azure Container Storage has nodes with 2 cores."
)
with self.assertRaises(InvalidArgumentValueError) as cm:
acstor_validator.validate_enable_azure_container_storage_params(
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
)
self.assertEqual(str(cm.exception), err)

def test_enable_with_insufficient_cores_4(self):
storage_pool_name = "valid-name"
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
nodepool_list = "pool1"
agentpools = [{"name": "pool1", "vm_size": "Standard_H2", "count": 3, "zoned": False}]
err = (
"Cannot operate Azure Container Storage on a node pool consisting of "
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_H2 "
"which is assigned for Azure Container Storage has nodes with 2 cores."
)
with self.assertRaises(InvalidArgumentValueError) as cm:
acstor_validator.validate_enable_azure_container_storage_params(
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
)
self.assertEqual(str(cm.exception), err)

def test_enable_with_insufficient_cores_2(self):
storage_pool_name = "valid-name"
storage_pool_sku = acstor_consts.CONST_STORAGE_POOL_SKU_PREMIUM_LRS
storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_AZURE_DISK
nodepool_list = "pool1"
agentpools = [{"name": "pool1", "vm_size": "Standard_D2s", "count": 3, "zoned": False}]
err = (
"Cannot operate Azure Container Storage on a node pool consisting of "
"nodes with cores less than 4. Node pool: pool1 with node size: Standard_D2s "
"which is assigned for Azure Container Storage has nodes with 2 cores."
)
with self.assertRaises(InvalidArgumentValueError) as cm:
acstor_validator.validate_enable_azure_container_storage_params(
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
)
self.assertEqual(str(cm.exception), err)

def test_enable_with_option_and_non_ephemeral_disk_pool(self):
storage_pool_name = "valid-name"
storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_NVME
Expand Down

0 comments on commit 3984671

Please sign in to comment.