From 8d0bf2017d467aa64604fe1712a1e9a2c65539df Mon Sep 17 00:00:00 2001 From: Akash Mukhopadhyay Date: Thu, 27 Jun 2024 23:44:19 -0700 Subject: [PATCH 1/2] Add additional validations to ephemeral disk operation --- src/aks-preview/HISTORY.rst | 4 ++ .../azurecontainerstorage/_validators.py | 21 ++++++++- .../tests/latest/test_validators.py | 47 +++++++++++++++++++ src/aks-preview/setup.py | 2 +- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/aks-preview/HISTORY.rst b/src/aks-preview/HISTORY.rst index 209aa65225f..cb3c40c4088 100644 --- a/src/aks-preview/HISTORY.rst +++ b/src/aks-preview/HISTORY.rst @@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to Pending +++++++ +5.0.0b3 +++++++++ +* Add validation to `az aks create` and `az aks update` while modifying the `--ephemeral-disk-volume-type` and `--ephemeral-disk-nvme-perf-tier` values. + 5.0.0b2 ++++++++ * Add option `--ephemeral-disk-volume-type` to `az aks create` and `az aks update` for Azure Container Storage operations. diff --git a/src/aks-preview/azext_aks_preview/azurecontainerstorage/_validators.py b/src/aks-preview/azext_aks_preview/azurecontainerstorage/_validators.py index 44592a41ca6..05b62908afa 100644 --- a/src/aks-preview/azext_aks_preview/azurecontainerstorage/_validators.py +++ b/src/aks-preview/azext_aks_preview/azurecontainerstorage/_validators.py @@ -303,20 +303,37 @@ def validate_enable_azure_container_storage_params( # pylint: disable=too-many- f'already enabled for storage pool option {enabled_options}.' ) else: - if ephemeral_disk_volume_type is not None and ephemeral_disk_nvme_perf_tier is None and \ + if required_type_installed_for_disk_vol_type and \ + ephemeral_disk_volume_type is not None and \ + ephemeral_disk_nvme_perf_tier is None and \ existing_ephemeral_disk_volume_type.lower() == ephemeral_disk_volume_type.lower(): raise InvalidArgumentValueError( 'Azure Container Storage is already configured with --ephemeral-disk-volume-type ' f'value set to {existing_ephemeral_disk_volume_type}.' ) - if ephemeral_disk_nvme_perf_tier is not None and ephemeral_disk_volume_type is None and \ + if required_type_installed_for_nvme_perf_tier and \ + ephemeral_disk_nvme_perf_tier is not None and \ + ephemeral_disk_volume_type is None and \ existing_ephemeral_disk_nvme_perf_tier.lower() == ephemeral_disk_nvme_perf_tier.lower(): raise InvalidArgumentValueError( 'Azure Container Storage is already configured with --ephemeral-disk-nvme-perf-tier ' f'value set to {existing_ephemeral_disk_nvme_perf_tier}.' ) + # pylint: disable=too-many-boolean-expressions + if required_type_installed_for_disk_vol_type and \ + ephemeral_disk_volume_type is not None and \ + existing_ephemeral_disk_volume_type.lower() == ephemeral_disk_volume_type.lower() and \ + required_type_installed_for_nvme_perf_tier and \ + ephemeral_disk_nvme_perf_tier is not None and \ + existing_ephemeral_disk_nvme_perf_tier.lower() == ephemeral_disk_nvme_perf_tier.lower(): + raise InvalidArgumentValueError( + 'Azure Container Storage is already configured with --ephemeral-disk-volume-type ' + f'value set to {existing_ephemeral_disk_volume_type} and --ephemeral-disk-nvme-perf-tier ' + f'value set to {existing_ephemeral_disk_nvme_perf_tier}.' + ) + if storage_pool_option == CONST_ACSTOR_ALL: raise InvalidArgumentValueError( f'Cannot set --storage-pool-option value as {CONST_ACSTOR_ALL} ' diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py b/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py index b3fba1c3fbe..89e466e488c 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py @@ -969,6 +969,53 @@ def test_enable_with_ephemeral_disk_nvme_perf_tier_and_ephemeral_temp_disk_pool( ) self.assertEqual(str(cm.exception), err) + def test_enable_with_same_ephemeral_disk_nvme_perf_tier_already_set(self): + storage_pool_name = "valid-name" + perf_tier = acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM + storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK + storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_SSD + err = ( + "Azure Container Storage is already configured with --ephemeral-disk-nvme-perf-tier " + f"value set to {perf_tier}." + ) + with self.assertRaises(InvalidArgumentValueError) as cm: + acstor_validator.validate_enable_azure_container_storage_params( + storage_pool_type, storage_pool_name, None, storage_pool_option, None, None, None, True, False, False, False, True, None, perf_tier, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM + ) + self.assertEqual(str(cm.exception), err) + + def test_enable_with_same_ephemeral_disk_volume_type_already_set(self): + storage_pool_name = "valid-name" + disk_vol_type = acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION + storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK + storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_SSD + err = ( + "Azure Container Storage is already configured with --ephemeral-disk-volume-type " + f"value set to {disk_vol_type}." + ) + with self.assertRaises(InvalidArgumentValueError) as cm: + acstor_validator.validate_enable_azure_container_storage_params( + storage_pool_type, storage_pool_name, None, storage_pool_option, None, None, None, True, False, False, False, True, disk_vol_type, None, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM + ) + self.assertEqual(str(cm.exception), err) + + def test_enable_with_same_ephemeral_disk_nvme_perf_tier_and_ephemeral_temp_disk_pool_already_set(self): + storage_pool_name = "valid-name" + perf_tier = acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD + disk_vol_type = acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION + storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK + storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_SSD + err = ( + "Azure Container Storage is already configured with --ephemeral-disk-volume-type " + f"value set to {disk_vol_type} and --ephemeral-disk-nvme-perf-tier " + f"value set to {perf_tier}." + ) + with self.assertRaises(InvalidArgumentValueError) as cm: + acstor_validator.validate_enable_azure_container_storage_params( + storage_pool_type, storage_pool_name, None, storage_pool_option, None, None, None, True, False, False, False, True, disk_vol_type, perf_tier, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD + ) + self.assertEqual(str(cm.exception), err) + def test_enable_with_option_all_and_ephemeral_disk_pool(self): storage_pool_name = "valid-name" storage_pool_option = acstor_consts.CONST_ACSTOR_ALL diff --git a/src/aks-preview/setup.py b/src/aks-preview/setup.py index 9b90d5ff453..9f2ab7bc028 100644 --- a/src/aks-preview/setup.py +++ b/src/aks-preview/setup.py @@ -9,7 +9,7 @@ from setuptools import setup, find_packages -VERSION = "5.0.0b2" +VERSION = "5.0.0b3" CLASSIFIERS = [ "Development Status :: 4 - Beta", From f84b98ca0a7d70ce7485ed2f8246967fa5a3e221 Mon Sep 17 00:00:00 2001 From: Akash Mukhopadhyay Date: Fri, 28 Jun 2024 00:06:23 -0700 Subject: [PATCH 2/2] Fixing the test case --- .../tests/latest/test_validators.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py b/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py index 89e466e488c..c836b1f9f2a 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_validators.py @@ -970,41 +970,35 @@ def test_enable_with_ephemeral_disk_nvme_perf_tier_and_ephemeral_temp_disk_pool( self.assertEqual(str(cm.exception), err) def test_enable_with_same_ephemeral_disk_nvme_perf_tier_already_set(self): - storage_pool_name = "valid-name" perf_tier = acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK - storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_SSD err = ( "Azure Container Storage is already configured with --ephemeral-disk-nvme-perf-tier " f"value set to {perf_tier}." ) with self.assertRaises(InvalidArgumentValueError) as cm: acstor_validator.validate_enable_azure_container_storage_params( - storage_pool_type, storage_pool_name, None, storage_pool_option, None, None, None, True, False, False, False, True, None, perf_tier, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM + storage_pool_type, None, None, None, None, None, None, True, False, False, False, True, None, perf_tier, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM ) self.assertEqual(str(cm.exception), err) def test_enable_with_same_ephemeral_disk_volume_type_already_set(self): - storage_pool_name = "valid-name" disk_vol_type = acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK - storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_SSD err = ( "Azure Container Storage is already configured with --ephemeral-disk-volume-type " f"value set to {disk_vol_type}." ) with self.assertRaises(InvalidArgumentValueError) as cm: acstor_validator.validate_enable_azure_container_storage_params( - storage_pool_type, storage_pool_name, None, storage_pool_option, None, None, None, True, False, False, False, True, disk_vol_type, None, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM + storage_pool_type, None, None, None, None, None, None, True, False, False, False, True, disk_vol_type, None, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_PREMIUM ) self.assertEqual(str(cm.exception), err) def test_enable_with_same_ephemeral_disk_nvme_perf_tier_and_ephemeral_temp_disk_pool_already_set(self): - storage_pool_name = "valid-name" perf_tier = acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD disk_vol_type = acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION storage_pool_type = acstor_consts.CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK - storage_pool_option = acstor_consts.CONST_STORAGE_POOL_OPTION_SSD err = ( "Azure Container Storage is already configured with --ephemeral-disk-volume-type " f"value set to {disk_vol_type} and --ephemeral-disk-nvme-perf-tier " @@ -1012,7 +1006,7 @@ def test_enable_with_same_ephemeral_disk_nvme_perf_tier_and_ephemeral_temp_disk_ ) with self.assertRaises(InvalidArgumentValueError) as cm: acstor_validator.validate_enable_azure_container_storage_params( - storage_pool_type, storage_pool_name, None, storage_pool_option, None, None, None, True, False, False, False, True, disk_vol_type, perf_tier, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD + storage_pool_type, None, None, None, None, None, None, True, False, False, False, True, disk_vol_type, perf_tier, acstor_consts.CONST_DISK_TYPE_PV_WITH_ANNOTATION, acstor_consts.CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD ) self.assertEqual(str(cm.exception), err)