From 83f2482cae409bf10e9a7d0092cbee5ee9d2a1ce Mon Sep 17 00:00:00 2001 From: Yulia Portnova Date: Tue, 17 Sep 2013 15:18:47 +0300 Subject: [PATCH] Quota tests fixed --- manila/share/manager.py | 4 +- manila/tests/api/contrib/stubs.py | 1 + .../tests/api/contrib/test_share_actions.py | 5 ++- manila/tests/api/v1/test_share_snapshots.py | 2 + manila/tests/test_quota.py | 39 +++++++++++++------ manila/tests/test_share_api.py | 6 +++ 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/manila/share/manager.py b/manila/share/manager.py index a38fa35adc..251ad0e582 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -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.""" diff --git a/manila/tests/api/contrib/stubs.py b/manila/tests/api/contrib/stubs.py index 6a8b931d45..cb95cd8c7b 100644 --- a/manila/tests/api/contrib/stubs.py +++ b/manila/tests/api/contrib/stubs.py @@ -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', diff --git a/manila/tests/api/contrib/test_share_actions.py b/manila/tests/api/contrib/test_share_actions.py index 1c043d5e9f..034c6cba1b 100644 --- a/manila/tests/api/contrib/test_share_actions.py +++ b/manila/tests/api/contrib/test_share_actions.py @@ -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): diff --git a/manila/tests/api/v1/test_share_snapshots.py b/manila/tests/api/v1/test_share_snapshots.py index 231cacbf94..88b521e88b 100644 --- a/manila/tests/api/v1/test_share_snapshots.py +++ b/manila/tests/api/v1/test_share_snapshots.py @@ -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', diff --git a/manila/tests/test_quota.py b/manila/tests/test_quota.py index c71e457f56..cdcdb6fb4d 100644 --- a/manila/tests/test_quota.py +++ b/manila/tests/test_quota.py @@ -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, diff --git a/manila/tests/test_share_api.py b/manila/tests/test_share_api.py index d4213d9f47..b77f6c2553 100644 --- a/manila/tests/test_share_api.py +++ b/manila/tests/test_share_api.py @@ -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)