Quota tests fixed

This commit is contained in:
Yulia Portnova 2013-09-17 15:18:47 +03:00
parent 4cdec7dda8
commit 83f2482cae
6 changed files with 41 additions and 16 deletions

View File

@ -213,8 +213,8 @@ class ShareManager(manager.SchedulerDependentManager):
reservations = None
LOG.exception(_("Failed to update usages deleting snapshot"))
if reservations:
QUOTAS.commit(context, reservations, project_id=project_id)
if reservations:
QUOTAS.commit(context, reservations, project_id=project_id)
def allow_access(self, context, access_id):
"""Allow access to some share."""

View File

@ -54,6 +54,7 @@ def stub_snapshot(id, **kwargs):
'project_id': 'fakesnapproject',
'host': 'fakesnaphost',
'share_size': 1,
'size': 1,
'status': 'fakesnapstatus',
'share_name': 'fakesharename',
'display_name': 'displaysnapname',

View File

@ -61,15 +61,16 @@ class ShareActionsTest(test.TestCase):
def test_allow_access(self):
def _stub_allow_access(*args, **kwargs):
pass
return {'fake': 'fake'}
self.stubs.Set(share_api.API, "allow_access", _stub_allow_access)
id = 'fake_share_id'
body = {"os-allow_access": {"access_type": 'fakeip',
"access_to": '127.0.0.1'}}
expected = {'access': {'fake': 'fake'}}
req = fakes.HTTPRequest.blank('/v1/tenant1/shares/%s/action' % id)
res = self.controller._allow_access(req, id, body)
self.assertEqual(res.status_int, 202)
self.assertEqual(res, expected)
def test_deny_access(self):
def _stub_deny_access(*args, **kwargs):

View File

@ -106,6 +106,7 @@ class ShareSnapshotApiTest(test.TestCase):
'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
'status': 'fakesnapstatus',
'name': 'displaysnapname',
'size': 1,
'description': 'displaysnapdesc',
'share_proto': 'fakesnapproto',
'export_location': 'fakesnaplocation',
@ -167,6 +168,7 @@ class ShareSnapshotApiTest(test.TestCase):
'id': 2,
'share_id': 'fakeshareid',
'share_size': 1,
'size': 1,
'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
'status': 'fakesnapstatus',
'name': 'displaysnapname',

View File

@ -630,7 +630,8 @@ class DbQuotaDriverTestCase(test.TestCase):
result,
dict(
shares=10,
gigabytes=1000, ))
gigabytes=1000,
snapshots=10))
def _stub_quota_class_get_all_by_name(self):
# Stub out quota_class_get_all_by_name
@ -647,7 +648,8 @@ class DbQuotaDriverTestCase(test.TestCase):
self.assertEqual(self.calls, ['quota_class_get_all_by_name'])
self.assertEqual(result, dict(shares=10,
gigabytes=500))
gigabytes=500,
snapshots=10))
def test_get_class_quotas_no_defaults(self):
self._stub_quota_class_get_all_by_name()
@ -685,11 +687,15 @@ class DbQuotaDriverTestCase(test.TestCase):
'quota_usage_get_all_by_project',
'quota_class_get_all_by_name', ])
self.assertEqual(result, dict(shares=dict(limit=10,
in_use=2,
reserved=0, ),
in_use=2,
reserved=0, ),
gigabytes=dict(limit=50,
in_use=10,
reserved=0, ), ))
reserved=0, ),
snapshots=dict(limit=10,
in_use=0,
reserved=0, ),
))
def test_get_project_quotas_alt_context_no_class(self):
self._stub_get_by_project()
@ -700,11 +706,15 @@ class DbQuotaDriverTestCase(test.TestCase):
self.assertEqual(self.calls, ['quota_get_all_by_project',
'quota_usage_get_all_by_project', ])
self.assertEqual(result, dict(shares=dict(limit=10,
in_use=2,
reserved=0, ),
in_use=2,
reserved=0, ),
gigabytes=dict(limit=50,
in_use=10,
reserved=0, ), ))
reserved=0, ),
snapshots=dict(limit=10,
in_use=0,
reserved=0, ),
))
def test_get_project_quotas_alt_context_with_class(self):
self._stub_get_by_project()
@ -716,11 +726,15 @@ class DbQuotaDriverTestCase(test.TestCase):
'quota_usage_get_all_by_project',
'quota_class_get_all_by_name', ])
self.assertEqual(result, dict(shares=dict(limit=10,
in_use=2,
reserved=0, ),
in_use=2,
reserved=0, ),
gigabytes=dict(limit=50,
in_use=10,
reserved=0, ), ))
reserved=0, ),
snapshots=dict(limit=10,
in_use=0,
reserved=0, ),
))
def test_get_project_quotas_no_defaults(self):
self._stub_get_by_project()
@ -748,7 +762,8 @@ class DbQuotaDriverTestCase(test.TestCase):
self.assertEqual(self.calls, ['quota_get_all_by_project',
'quota_class_get_all_by_name', ])
self.assertEqual(result, dict(shares=dict(limit=10, ),
gigabytes=dict(limit=50, ), ))
gigabytes=dict(limit=50, ),
snapshots=dict(limit=10)))
def _stub_get_project_quotas(self):
def fake_get_project_quotas(context, resources, project_id,

View File

@ -154,6 +154,7 @@ class ShareAPITestCase(test.TestCase):
'status': "creating",
'progress': '0%',
'share_size': share['size'],
'size': 1,
'display_name': fake_name,
'display_description': fake_desc,
'share_proto': share['share_proto'],
@ -161,9 +162,14 @@ class ShareAPITestCase(test.TestCase):
self.mox.StubOutWithMock(share_api, 'check_policy')
share_api.check_policy(self.context, 'create_snapshot', share)
self.mox.StubOutWithMock(quota.QUOTAS, 'reserve')
quota.QUOTAS.reserve(self.context, snapshots=1, gigabytes=1).\
AndReturn('reservation')
self.mox.StubOutWithMock(db_driver, 'share_snapshot_create')
db_driver.share_snapshot_create(self.context,
options).AndReturn(snapshot)
self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
quota.QUOTAS.commit(self.context, 'reservation')
self.share_rpcapi.create_snapshot(self.context, share, snapshot)
self.mox.ReplayAll()
self.api.create_snapshot(self.context, share, fake_name, fake_desc)