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')