updating quotas and tests with the format which recently landed in nova

This commit is contained in:
Jake Dahn 2011-08-16 13:36:45 -07:00
parent 5a53520698
commit 0476cb6b75
3 changed files with 54 additions and 50 deletions

View File

@ -58,4 +58,4 @@ class QuotaSetManager(base.ManagerWithFind):
def defaults(self, tenant_id):
return self._get('/os-quota-sets/%s/defaults' % tenant_id,
'quota_set_list')
'quota_set')

View File

@ -34,9 +34,11 @@ class FakeHTTPClient(base_client.HTTPClient):
munged_url = url.strip('/').replace('/', '_').replace('.', '_')
munged_url = munged_url.replace('-', '_')
callback = "%s_%s" % (method.lower(), munged_url)
if not hasattr(self, callback):
raise AssertionError('Called unknown API method: %s %s' % (method,
url))
raise AssertionError('Called unknown API method: %s %s, '
'expected fakes method name: %s' %
(method, url, callback))
# Note the call
self.callstack.append((method, url, kwargs.get('body', None)))
@ -394,42 +396,47 @@ class FakeHTTPClient(base_client.HTTPClient):
return (202, r)
#
# Quotas
# Quotas
#
def get_os_quotas(self, *kw):
return (200, {'quota_set_list': [{
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'volumes': 1,
'gigabytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
}]})
def get_os_quotas_test(self, *kw):
return (200, {'quota_set': {
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'volumes': 1,
'gigabytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1,
}})
def get_os_quota_sets_test(self, **kw):
return (200, {'quota_set': {
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'volumes': 1,
'gigabytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1}})
def delete_os_quotas_test(self, **kw):
return (202, None)
def get_os_quota_sets_test_defaults(self):
return (200, {'quota_set': {
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'volumes': 1,
'gigabytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1}})
def put_os_quotas_test(self, body, **kw):
def put_os_quota_sets_test(self, body, **kw):
assert body.keys() == ['quota_set']
fakes.assert_has_keys(body['quota_set'],
required=['tenant_id'])
r = self.get_os_quotas_test()[1]
return (200, r)
return (200, {'quota_set': {
'tenant_id': 'test',
'metadata_items': [],
'injected_file_content_bytes': 1,
'volumes': 2,
'gigabytes': 1,
'ram': 1,
'floating_ips': 1,
'instances': 1,
'injected_files': 1,
'cores': 1}})

View File

@ -22,22 +22,19 @@ from tests import utils
cs = fakes.FakeClient()
class QuoatsTest(utils.TestCase):
def test_list_quotas(self):
qs = cs.quotas.list()
cs.assert_called('GET', '/os-quotas')
[self.assertTrue(isinstance(q, quotas.QuotaSet)) for q in qs]
class QuotaSetsTest(utils.TestCase):
def test_delete_quota(self):
q = cs.quotas.list()[0]
q.delete()
cs.assert_called('DELETE', '/os-quotas/test')
cs.quotas.delete('test')
cs.assert_called('DELETE', '/os-quotas/test')
cs.quotas.delete(q)
cs.assert_called('DELETE', '/os-quotas/test')
def test_tenant_quotas_get(self):
tenant_id = 'test'
qs = cs.quotas.get(tenant_id)
cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id)
def test_tenant_quotas_defaults(self):
tenant_id = 'test'
q = cs.quotas.defaults(tenant_id)
cs.assert_called('GET', '/os-quota-sets/%s/defaults' % tenant_id)
def test_update_quota(self):
q = cs.quotas.list()[0]
q = cs.quotas.get('test')
q.update(volumes=2)
cs.assert_called('PUT', '/os-quotas/test')
cs.assert_called('PUT', '/os-quota-sets/test')