Skip to content

Commit df958f8

Browse files
committed
improve messaging
1 parent 21b8782 commit df958f8

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ def get_extension_installed_and_cluster_configs(
291291

292292

293293
def should_delete_extension(storage_options_to_remove) -> bool:
294-
return (storage_options_to_remove in [True, CONST_ACSTOR_ALL] or
295-
isinstance(storage_options_to_remove, list) and CONST_ACSTOR_ALL in storage_options_to_remove)
294+
return (
295+
storage_options_to_remove in [True, CONST_ACSTOR_ALL] or
296+
(isinstance(storage_options_to_remove, list) and CONST_ACSTOR_ALL in storage_options_to_remove)
297+
)
296298

297299

298300
def get_container_storage_extension_installed(

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,14 @@ def validate_enable_azure_container_storage_params(
464464
for option in enablement_option_arr:
465465
if option not in [CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK, CONST_STORAGE_POOL_TYPE_ELASTIC_SAN]:
466466
raise InvalidArgumentValueError(
467-
f"Unsupported Azure Container Storage option '{option}'. "
467+
f"Unsupported storage option '{option}'. "
468468
f"Supported values are '{CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK}' "
469469
f"and '{CONST_STORAGE_POOL_TYPE_ELASTIC_SAN}'."
470470
)
471471
if is_ephemeral_disk_enabled == enable_ephemeral_disk and is_elastic_san_enabled == enable_elastic_san:
472+
options_display = "', '".join(enablement_option_arr)
472473
raise InvalidArgumentValueError(
473-
f"Cannot enable Azure Container Storage option(s) '{enablement_option}' "
474+
f"Cannot enable the requested storage options ('{options_display}') "
474475
"as they are already enabled on the cluster."
475476
)
476477

@@ -530,13 +531,14 @@ def validate_disable_azure_container_storage_params(
530531
actionable = actionable or is_elastic_san_enabled
531532
else:
532533
raise InvalidArgumentValueError(
533-
f"Cannot disable unsupported Azure Container Storage option '{disable_option}'. "
534+
f"Cannot disable unsupported storage option '{disable_option}'. "
534535
f"Supported values are '{CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK}', "
535536
f"'{CONST_STORAGE_POOL_TYPE_ELASTIC_SAN}' and '{CONST_ACSTOR_ALL}'."
536537
)
537538
if not actionable:
539+
options_display = "', '".join(disablement_option_arr)
538540
raise InvalidArgumentValueError(
539-
f"Cannot disable Azure Container Storage option(s) '{disablement_option}' "
541+
f"Cannot disable the requested storage options ('{options_display}') "
540542
"as they could not be found on the cluster."
541543
)
542544

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9272,15 +9272,19 @@ def update_azure_container_storage(self, mc: ManagedCluster) -> ManagedCluster:
92729272
)
92739273
from azure.cli.command_modules.acs.azurecontainerstorage._helpers import should_delete_extension
92749274
if not should_delete_extension(disable_azure_container_storage_param):
9275-
storage_option_str = disable_azure_container_storage_param
9275+
storage_option_display = storage_option_param_str = disable_azure_container_storage_param
92769276
if isinstance(disable_azure_container_storage_param, list):
9277-
storage_option_str = " ".join(disable_azure_container_storage_param)
9277+
storage_options = disable_azure_container_storage_param
9278+
storage_option_param_str = " ".join(storage_options)
9279+
if len(storage_options) > 2:
9280+
storage_options = [storage_options[:-1].join("', '"), storage_options[-1]]
9281+
storage_option_display = "' and '".join(storage_options)
92789282
msg = (
92799283
"Please make sure there are no existing PVs and PVCs that are provisioned by Azure Container Storage "
9280-
f"for {disable_azure_container_storage_param} before disabling. If storage options are disabled "
9284+
f"for '{storage_option_display}' before disabling. If storage options are disabled "
92819285
"with remaining PVs and PVCs, any data associated with those PVs and PVCs will not be erased "
92829286
"and the nodes will be left in an unclean state. The PVs and PVCs can only be cleaned up "
9283-
f"after re-enabling it by running 'az aks update --enable-azure-container-storage {storage_option_str}'. "
9287+
f"after re-enabling it by running 'az aks update --enable-azure-container-storage {storage_option_param_str}'. "
92849288
"Would you like to proceed with the disabling?"
92859289
)
92869290
if not self.context.get_yes() and not prompt_y_n(msg, default="n"):

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ def test_disable_unsupported_type(self):
16411641
storage_pool_type, True, False, False, "", "", "", "",
16421642
)
16431643
err = (
1644-
f"Cannot disable unsupported Azure Container Storage option '{storage_pool_type}'. "
1644+
f"Cannot disable unsupported storage option '{storage_pool_type}'. "
16451645
"Supported values are 'ephemeralDisk', 'elasticSan' and 'all'."
16461646
)
16471647
self.assertEqual(str(cm.exception), err)
@@ -1653,7 +1653,7 @@ def test_disable_already_disabled_type(self):
16531653
storage_pool_type, True, False, False, "", "", "", "",
16541654
)
16551655
err = (
1656-
f"Cannot disable Azure Container Storage option(s) '{storage_pool_type}' "
1656+
f"Cannot disable the requested storage options ('{storage_pool_type}') "
16571657
"as they could not be found on the cluster."
16581658
)
16591659
self.assertEqual(str(cm.exception), err)
@@ -1770,7 +1770,7 @@ def test_enable_supported_type_when_already_enabled(self):
17701770
storage_type, True, True, False, False, "", None, None, None, None,
17711771
)
17721772
err = (
1773-
f"Cannot enable Azure Container Storage option(s) '{storage_type}' "
1773+
f"Cannot enable the requested storage options ('{storage_type}') "
17741774
"as they are already enabled on the cluster."
17751775
)
17761776
self.assertEqual(str(cm.exception), err)
@@ -1794,7 +1794,7 @@ def test_enable_multiple_types_when_all_are_already_enabled(self):
17941794
storage_types, True, True, True, False, "", None, None, None, None,
17951795
)
17961796
err = (
1797-
f"Cannot enable Azure Container Storage option(s) '{storage_types}' "
1797+
f"Cannot enable the requested storage options ('{storage_types[0]}', '{storage_types[1]}') "
17981798
"as they are already enabled on the cluster."
17991799
)
18001800
self.assertEqual(str(cm.exception), err)
@@ -1808,7 +1808,7 @@ def test_enable_multiple_types_when_some_are_unsupported(self):
18081808
storage_types, False, False, False, False, "", None, None, None, None,
18091809
)
18101810
err = (
1811-
f"Unsupported Azure Container Storage option '{unsupported_storage_type}'. "
1811+
f"Unsupported storage option '{unsupported_storage_type}'. "
18121812
"Supported values are 'ephemeralDisk' and 'elasticSan'."
18131813
)
18141814
self.assertEqual(str(cm.exception), err)
@@ -1820,7 +1820,7 @@ def test_enable_unsupported_type(self):
18201820
storage_type, False, False, False, False, "", None, None, None, None,
18211821
)
18221822
err = (
1823-
f"Unsupported Azure Container Storage option '{storage_type}'. "
1823+
f"Unsupported storage option '{storage_type}'. "
18241824
"Supported values are 'ephemeralDisk' and 'elasticSan'."
18251825
)
18261826
self.assertEqual(str(cm.exception), err)
@@ -1850,7 +1850,7 @@ def test_enable_with_storage_pool_sku(self):
18501850
f'Please remove --storage-pool-sku {storage_pool_sku} from the command and try again.'
18511851
)
18521852
self.assertEqual(str(cm.exception), err)
1853-
1853+
18541854
def test_enable_with_storage_pool_option(self):
18551855
storage_pool_option = "valid-option"
18561856
with self.assertRaises(InvalidArgumentValueError) as cm:

0 commit comments

Comments
 (0)