From be4102b0577937c0193703ace9ae7591197341de Mon Sep 17 00:00:00 2001 From: liyingjun Date: Fri, 22 Nov 2013 12:15:49 +0800 Subject: [PATCH] Remove unused reservation methods from db.api There are several unused reservation methods are not called directly, so it could be removed from the db API. closes-bug: #1255925 Change-Id: I8dffa1d4222da162e55ddd6cfce656b4620f3fad --- cinder/db/api.py | 25 -------------- cinder/db/sqlalchemy/api.py | 48 --------------------------- cinder/tests/test_db_api.py | 66 ++++--------------------------------- cinder/tests/test_quota.py | 6 +--- 4 files changed, 7 insertions(+), 138 deletions(-) diff --git a/cinder/db/api.py b/cinder/db/api.py index 602a3084d..8881e80e9 100644 --- a/cinder/db/api.py +++ b/cinder/db/api.py @@ -690,31 +690,6 @@ def quota_usage_get_all_by_project(context, project_id): ################### -def reservation_create(context, uuid, usage, project_id, resource, delta, - expire): - """Create a reservation for the given project and resource.""" - return IMPL.reservation_create(context, uuid, usage, project_id, - resource, delta, expire) - - -def reservation_get(context, uuid): - """Retrieve a reservation or raise if it does not exist.""" - return IMPL.reservation_get(context, uuid) - - -def reservation_get_all_by_project(context, project_id): - """Retrieve all reservations associated with a given project.""" - return IMPL.reservation_get_all_by_project(context, project_id) - - -def reservation_destroy(context, uuid): - """Destroy the reservation or raise if it does not exist.""" - return IMPL.reservation_destroy(context, uuid) - - -################### - - def quota_reserve(context, resources, quotas, deltas, expire, until_refresh, max_age, project_id=None): """Check quotas and create appropriate reservations.""" diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 16a0402b4..b3244577d 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -630,39 +630,6 @@ def _quota_usage_create(context, project_id, resource, in_use, reserved, ################### -@require_context -def _reservation_get(context, uuid, session=None): - result = model_query(context, models.Reservation, session=session, - read_deleted="no").\ - filter_by(uuid=uuid).first() - - if not result: - raise exception.ReservationNotFound(uuid=uuid) - - return result - - -@require_context -def reservation_get(context, uuid): - return _reservation_get(context, uuid) - - -@require_context -def reservation_get_all_by_project(context, project_id): - authorize_project_context(context, project_id) - - rows = model_query(context, models.Reservation, read_deleted="no").\ - filter_by(project_id=project_id).all() - - result = {'project_id': project_id} - for row in rows: - result.setdefault(row.resource, {}) - result[row.resource][row.uuid] = row.delta - - return result - - -@require_admin_context def _reservation_create(context, uuid, usage, project_id, resource, delta, expire, session=None): reservation_ref = models.Reservation() @@ -676,21 +643,6 @@ def _reservation_create(context, uuid, usage, project_id, resource, delta, return reservation_ref -@require_admin_context -def reservation_create(context, uuid, usage, project_id, resource, delta, - expire): - return _reservation_create(context, uuid, usage, project_id, resource, - delta, expire) - - -@require_admin_context -def reservation_destroy(context, uuid): - session = get_session() - with session.begin(): - reservation_ref = _reservation_get(context, uuid, session=session) - reservation_ref.delete(session=session) - - ################### diff --git a/cinder/tests/test_db_api.py b/cinder/tests/test_db_api.py index 07bb71faa..ddd0726fd 100644 --- a/cinder/tests/test_db_api.py +++ b/cinder/tests/test_db_api.py @@ -917,26 +917,6 @@ class DBAPIReservationTestCase(BaseTest): 'usage': {'id': 1} } - def test_reservation_create(self): - reservation = db.reservation_create(self.ctxt, **self.values) - self._assertEqualObjects(self.values, reservation, ignored_keys=( - 'deleted', 'updated_at', - 'deleted_at', 'id', - 'created_at', 'usage', - 'usage_id')) - self.assertEqual(reservation['usage_id'], self.values['usage']['id']) - - def test_reservation_get(self): - reservation = db.reservation_create(self.ctxt, **self.values) - reservation_db = db.reservation_get(self.ctxt, self.values['uuid']) - self._assertEqualObjects(reservation, reservation_db) - - def test_reservation_get_nonexistent(self): - self.assertRaises(exception.ReservationNotFound, - db.reservation_get, - self.ctxt, - 'non-exitent-resevation-uuid') - def test_reservation_commit(self): reservations = _quota_reserve(self.ctxt, 'project1') expected = {'project_id': 'project1', @@ -946,12 +926,7 @@ class DBAPIReservationTestCase(BaseTest): self.assertEqual(expected, db.quota_usage_get_all_by_project( self.ctxt, 'project1')) - db.reservation_get(self.ctxt, reservations[0]) db.reservation_commit(self.ctxt, reservations, 'project1') - self.assertRaises(exception.ReservationNotFound, - db.reservation_get, - self.ctxt, - reservations[0]) expected = {'project_id': 'project1', 'volumes': {'reserved': 0, 'in_use': 1}, 'gigabytes': {'reserved': 0, 'in_use': 2}, @@ -971,12 +946,7 @@ class DBAPIReservationTestCase(BaseTest): db.quota_usage_get_all_by_project( self.ctxt, 'project1')) - db.reservation_get(self.ctxt, reservations[0]) db.reservation_rollback(self.ctxt, reservations, 'project1') - self.assertRaises(exception.ReservationNotFound, - db.reservation_get, - self.ctxt, - reservations[0]) expected = {'project_id': 'project1', 'volumes': {'reserved': 0, 'in_use': 0}, 'gigabytes': {'reserved': 0, 'in_use': 0}, @@ -986,16 +956,6 @@ class DBAPIReservationTestCase(BaseTest): self.ctxt, 'project1')) - def test_reservation_get_all_by_project(self): - reservations = _quota_reserve(self.ctxt, 'project1') - r1 = db.reservation_get(self.ctxt, reservations[0]) - r2 = db.reservation_get(self.ctxt, reservations[1]) - expected = {'project_id': 'project1', - r1['resource']: {r1['uuid']: r1['delta']}, - r2['resource']: {r2['uuid']: r2['delta']}} - self.assertEqual(expected, db.reservation_get_all_by_project( - self.ctxt, 'project1')) - def test_reservation_expire(self): self.values['expire'] = datetime.datetime.utcnow() + \ datetime.timedelta(days=1) @@ -1010,15 +970,6 @@ class DBAPIReservationTestCase(BaseTest): self.ctxt, 'project1')) - def test_reservation_destroy(self): - reservations = _quota_reserve(self.ctxt, 'project1') - r1 = db.reservation_get(self.ctxt, reservations[0]) - db.reservation_destroy(self.ctxt, reservations[1]) - expected = {'project_id': 'project1', - r1['resource']: {r1['uuid']: r1['delta']}} - self.assertEqual(expected, db.reservation_get_all_by_project( - self.ctxt, 'project1')) - class DBAPIQuotaClassTestCase(BaseTest): @@ -1117,11 +1068,11 @@ class DBAPIQuotaTestCase(BaseTest): def test_quota_reserve(self): reservations = _quota_reserve(self.ctxt, 'project1') self.assertEqual(len(reservations), 2) - res_names = ['gigabytes', 'volumes'] - for uuid in reservations: - reservation = db.reservation_get(self.ctxt, uuid) - self.assertIn(reservation.resource, res_names) - res_names.remove(reservation.resource) + quota_usage = db.quota_usage_get_all_by_project(self.ctxt, 'project1') + self.assertEqual({'project_id': 'project1', + 'gigabytes': {'reserved': 2, 'in_use': 0}, + 'volumes': {'reserved': 1, 'in_use': 0}}, + quota_usage) def test_quota_destroy(self): db.quota_create(self.ctxt, 'project1', 'resource1', 41) @@ -1131,18 +1082,13 @@ class DBAPIQuotaTestCase(BaseTest): self.ctxt, 'project1', 'resource1') def test_quota_destroy_all_by_project(self): - reservations = _quota_reserve(self.ctxt, 'project1') + _quota_reserve(self.ctxt, 'project1') db.quota_destroy_all_by_project(self.ctxt, 'project1') self.assertEqual(db.quota_get_all_by_project(self.ctxt, 'project1'), {'project_id': 'project1'}) self.assertEqual(db.quota_usage_get_all_by_project(self.ctxt, 'project1'), {'project_id': 'project1'}) - for r in reservations: - self.assertRaises(exception.ReservationNotFound, - db.reservation_get, - self.ctxt, - r) def test_quota_usage_get_nonexistent(self): self.assertRaises(exception.QuotaUsageNotFound, diff --git a/cinder/tests/test_quota.py b/cinder/tests/test_quota.py index 62a87d555..269bf8c37 100644 --- a/cinder/tests/test_quota.py +++ b/cinder/tests/test_quota.py @@ -161,16 +161,12 @@ class QuotaIntegrationTestCase(test.TestCase): snap_ref2 = volume.API().create_snapshot(self.context, vol_ref, '', '') - # Make sure no reservation was created for snapshot gigabytes. - reservations = db.reservation_get_all_by_project(self.context, - self.project_id) - self.assertIsNone(reservations.get('gigabytes')) - # Make sure the snapshot volume_size isn't included in usage. vol_ref2 = volume.API().create(self.context, 10, '', '') usages = db.quota_usage_get_all_by_project(self.context, self.project_id) self.assertEqual(usages['gigabytes']['in_use'], 20) + self.assertEqual(usages['gigabytes']['reserved'], 0) db.snapshot_destroy(self.context, snap_ref['id']) db.snapshot_destroy(self.context, snap_ref2['id']) -- 2.45.2