diff options
author | Joe Gordon <jogo@cloudscaling.com> | 2013-03-05 01:55:30 +0000 |
---|---|---|
committer | Joe Gordon <jogo@cloudscaling.com> | 2013-03-07 14:55:55 -0800 |
commit | 1882b99734f5b0091d3b8c2662fea26980f05327 (patch) | |
tree | a43b689c21f64a051989cb53b381d3760595255d | |
parent | 8ac304f7f577ffe7d0264e1248e4ae87bd74fc65 (diff) | |
download | python-novaclient-1882b99734f5b0091d3b8c2662fea26980f05327.tar.gz |
Check if tenant flag is uuid_like for all quota operations
Fix bug 1145706
Change-Id: I9089ea4f968797b248f80bf84027a602e59ccd00
-rw-r--r-- | novaclient/utils.py | 7 | ||||
-rw-r--r-- | novaclient/v1_1/shell.py | 11 | ||||
-rw-r--r-- | tests/v1_1/fakes.py | 2 | ||||
-rw-r--r-- | tests/v1_1/test_quotas.py | 2 | ||||
-rw-r--r-- | tests/v1_1/test_shell.py | 18 |
5 files changed, 28 insertions, 12 deletions
diff --git a/novaclient/utils.py b/novaclient/utils.py index 8c63452c..d528c99b 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -358,3 +358,10 @@ def is_uuid_like(val): return False except (TypeError, ValueError, AttributeError): return False + + +def check_uuid_like(val): + if not is_uuid_like(val): + raise exceptions.CommandError( + "error: Invalid tenant-id %s supplied" + % val) diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 79799db3..ef426dea 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -2694,10 +2694,7 @@ def _quota_show(quotas): def _quota_update(manager, identifier, args): updates = {} - if not utils.is_uuid_like(identifier): - raise exceptions.CommandError( - "error: Invalid tenant-id %s supplied for update" - % identifier) + utils.check_uuid_like(identifier) for resource in _quota_resources: val = getattr(args, resource, None) if val is not None: @@ -2710,26 +2707,28 @@ def _quota_update(manager, identifier, args): @utils.arg('--tenant', metavar='<tenant-id>', default=None, - help='UUID or name of tenant to list the quotas for.') + help='UUID of tenant to list the quotas for.') def do_quota_show(cs, args): """List the quotas for a tenant.""" if not args.tenant: _quota_show(cs.quotas.get(cs.client.tenant_id)) else: + utils.check_uuid_like(args.tenant) _quota_show(cs.quotas.get(args.tenant)) @utils.arg('--tenant', metavar='<tenant-id>', default=None, - help='UUID or name of tenant to list the default quotas for.') + help='UUID of tenant to list the default quotas for.') def do_quota_defaults(cs, args): """List the default quotas for a tenant.""" if not args.tenant: _quota_show(cs.quotas.defaults(cs.client.tenant_id)) else: + utils.check_uuid_like(args.tenant) _quota_show(cs.quotas.defaults(args.tenant)) diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index 70923631..5ff06c79 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -954,7 +954,7 @@ class FakeHTTPClient(base_client.HTTPClient): 'security_groups': 1, 'security_group_rules': 1}}) - def get_os_quota_sets_test_defaults(self): + def get_os_quota_sets_97f4c221bff44578b0300df4ef119353_defaults(self): return (200, {}, {'quota_set': { 'tenant_id': 'test', 'metadata_items': [], diff --git a/tests/v1_1/test_quotas.py b/tests/v1_1/test_quotas.py index 27cdb26e..80877cc3 100644 --- a/tests/v1_1/test_quotas.py +++ b/tests/v1_1/test_quotas.py @@ -29,7 +29,7 @@ class QuotaSetsTest(utils.TestCase): cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id) def test_tenant_quotas_defaults(self): - tenant_id = 'test' + tenant_id = '97f4c221bff44578b0300df4ef119353' cs.quotas.defaults(tenant_id) cs.assert_called('GET', '/os-quota-sets/%s/defaults' % tenant_id) diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py index 5bb954f0..0f8e7f2a 100644 --- a/tests/v1_1/test_shell.py +++ b/tests/v1_1/test_shell.py @@ -895,16 +895,26 @@ class ShellTest(utils.TestCase): self.assert_called('GET', '/os-hypervisors/statistics') def test_quota_show(self): - self.run_command('quota-show --tenant test') - self.assert_called('GET', '/os-quota-sets/test') + self.run_command('quota-show --tenant ' + '97f4c221bff44578b0300df4ef119353') + self.assert_called('GET', + '/os-quota-sets/97f4c221bff44578b0300df4ef119353') + self.assertRaises(exceptions.CommandError, + self.run_command, + 'quota-show --tenant not_uuid') def test_quota_show_no_tenant(self): self.run_command('quota-show') self.assert_called('GET', '/os-quota-sets/tenant_id') def test_quota_defaults(self): - self.run_command('quota-defaults --tenant test') - self.assert_called('GET', '/os-quota-sets/test/defaults') + self.run_command('quota-defaults --tenant ' + '97f4c221bff44578b0300df4ef119353') + self.assert_called('GET', + '/os-quota-sets/97f4c221bff44578b0300df4ef119353/defaults') + self.assertRaises(exceptions.CommandError, + self.run_command, + 'quota-defaults --tenant not_uuid') def test_quota_defaults_no_nenant(self): self.run_command('quota-defaults') |