From 235c4e60aa6a7e0072b3f9fee8ba0c66dafcb19b Mon Sep 17 00:00:00 2001 From: M V P Nitesh Date: Mon, 24 Apr 2017 17:25:45 +0530 Subject: [PATCH] Now empty tags are not added to Networks Added a check if the tag values is empty or not before adding that tag to the network. Change-Id: I92659da97fe829a7715d0bef5570a4d9c5db95da Closes-Bug: #1603292 --- neutronclient/neutron/v2_0/tag.py | 3 +++ neutronclient/tests/unit/test_cli20_tag.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/neutronclient/neutron/v2_0/tag.py b/neutronclient/neutron/v2_0/tag.py index 4582716..ff59b74 100644 --- a/neutronclient/neutron/v2_0/tag.py +++ b/neutronclient/neutron/v2_0/tag.py @@ -50,6 +50,9 @@ class AddTag(neutronv20.NeutronCommand): def take_action(self, parsed_args): client = self.get_client() + if not parsed_args.tag: + raise exceptions.CommandError( + _('Cannot add an empty value as tag')) resource_type, resource_id = _convert_resource_args(client, parsed_args) client.add_tag(resource_type, resource_id, parsed_args.tag) diff --git a/neutronclient/tests/unit/test_cli20_tag.py b/neutronclient/tests/unit/test_cli20_tag.py index edd70a7..1b04be6 100644 --- a/neutronclient/tests/unit/test_cli20_tag.py +++ b/neutronclient/tests/unit/test_cli20_tag.py @@ -81,6 +81,14 @@ class CLITestV20Tag(test_cli20.CLITestV20Base): '--tag', 'red'] self._test_tag_operation(cmd, path, 'PUT', args, "tag-add") + def test_add_tag_empty_tag(self): + cmd = tag.AddTag(test_cli20.MyApp(sys.stdout), None) + path = self._make_tag_path('network', 'myid', '') + args = ['--resource-type', 'network', '--resource', 'myid', + '--tag', ''] + self.assertRaises(exceptions.CommandError, self._test_tag_operation, + cmd, path, 'PUT', args, "tag-add") + def test_replace_tag(self): cmd = tag.ReplaceTag(test_cli20.MyApp(sys.stdout), None) path = self._make_tags_path('network', 'myid')