diff --git a/src/azure-cli-core/HISTORY.rst b/src/azure-cli-core/HISTORY.rst index 71cd59c95ff..da1a7f3821d 100644 --- a/src/azure-cli-core/HISTORY.rst +++ b/src/azure-cli-core/HISTORY.rst @@ -5,7 +5,7 @@ Release History 2.0.50 ++++++ -* Minor fixes. +* Fix issue where update commands using `--remove` and `--ids` fail after first update is applied to first resource in ids list. 2.0.49 ++++++ diff --git a/src/azure-cli-core/azure/cli/core/commands/arm.py b/src/azure-cli-core/azure/cli/core/commands/arm.py index a2c6a86caa7..8ae445e8a89 100644 --- a/src/azure-cli-core/azure/cli/core/commands/arm.py +++ b/src/azure-cli-core/azure/cli/core/commands/arm.py @@ -794,6 +794,7 @@ def set_properties(instance, expression, force_string): def add_properties(instance, argument_values, force_string): # The first argument indicates the path to the collection to add to. + argument_values = list(argument_values) list_attribute_path = _get_internal_path(argument_values.pop(0)) list_to_add_to = _find_property(instance, list_attribute_path) @@ -833,8 +834,8 @@ def add_properties(instance, argument_values, force_string): def remove_properties(instance, argument_values): - # The first argument indicates the path to the collection to add to. - argument_values = argument_values if isinstance(argument_values, list) else [argument_values] + # The first argument indicates the path to the collection to remove from. + argument_values = list(argument_values) if isinstance(argument_values, list) else [argument_values] list_attribute_path = _get_internal_path(argument_values.pop(0)) list_index = None diff --git a/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/latest/test_resource.py b/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/latest/test_resource.py index 815d7207a05..5023e6bf9c6 100644 --- a/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/latest/test_resource.py +++ b/src/command_modules/azure-cli-resource/azure/cli/command_modules/resource/tests/latest/test_resource.py @@ -155,6 +155,53 @@ def test_resource_id_scenario(self, resource_group): self.cmd('resource delete --id {vnet_id}', checks=self.is_empty()) +class ResourceGenericUpdate(LiveScenarioTest): + @ResourceGroupPreparer(name_prefix='cli_test_resource_id') + def test_resource_id_scenario(self, resource_group): + self.kwargs.update({ + 'stor_1': self.create_random_name(prefix='stor1', length=10), + 'stor_2': self.create_random_name(prefix='stor2', length=10) + }) + + # create storage accounts + self.cmd('az storage account create -g {rg} -n {stor_1}') + self.cmd('az storage account create -g {rg} -n {stor_2}') + + # get ids + self.kwargs['stor_ids'] = " ".join(self.cmd('az storage account list -g {rg} --query "[].id"').get_output_in_json()) + + # update tags + self.cmd('az storage account update --ids {stor_ids} --set tags.isTag=True tags.isNotTag=False') + + self.cmd('az storage account show --name {stor_1} -g {rg}', checks=[ + self.check('tags.isTag', 'True'), + self.check('tags.isNotTag', 'False') + ]) + self.cmd('az storage account show --name {stor_2} -g {rg}', checks=[ + self.check('tags.isTag', 'True'), + self.check('tags.isNotTag', 'False') + ]) + + # delete tags.isTag + self.cmd('az storage account update --ids {stor_ids} --remove tags.isTag') + + self.cmd('az storage account show --name {stor_1} -g {rg} --query "tags"', checks=[ + self.check('isNotTag', 'False'), + self.check('isTag', None) + ]) + self.cmd('az storage account show --name {stor_2} -g {rg} --query "tags"', checks=[ + self.check('isNotTag', 'False'), + self.check('isTag', None) + ]) + + # delete tags.isNotTag + self.cmd('az storage account update --ids {stor_ids} --remove tags.isNotTag') + + # check tags is empty. + self.cmd('az storage account show --name {stor_1} -g {rg} --query "tags"', checks=self.is_empty()) + self.cmd('az storage account show --name {stor_2} -g {rg} --query "tags"', checks=self.is_empty()) + + class ResourceCreateAndShowScenarioTest(ScenarioTest): @ResourceGroupPreparer(name_prefix='cli_test_resource_create')