Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with update --remove --ids #7643

Merged
merged 3 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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