Merge "Check if tenant flag is uuid_like for all quota operations"

This commit is contained in:
Jenkins 2013-03-11 16:43:23 +00:00 committed by Gerrit Code Review
commit 5c9fc02468
5 changed files with 28 additions and 12 deletions

View File

@ -362,3 +362,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)

View File

@ -2697,10 +2697,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:
@ -2713,26 +2710,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))

View File

@ -971,7 +971,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': [],

View File

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

View File

@ -987,16 +987,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')