Skip to content

Commit

Permalink
Fixed bug with update --remove --ids (#7643)
Browse files Browse the repository at this point in the history
* Fixed bug where if update --remove is called with --ids, the correct params aren't passed in subsequent iterations of the update command.

* Fixed Pep8 issues

* Fixed bug by changing generic update logic instead of copying CLI params.
  • Loading branch information
adewaleo authored and tjprescott committed Oct 24, 2018
1 parent df6b8e3 commit d30992a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/azure-cli-core/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
++++++
Expand Down
5 changes: 3 additions & 2 deletions src/azure-cli-core/azure/cli/core/commands/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit d30992a

Please sign in to comment.