]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove unused reservation methods from db.api
authorliyingjun <liyingjun1988@gmail.com>
Fri, 22 Nov 2013 04:15:49 +0000 (12:15 +0800)
committerliyingjun <liyingjun1988@gmail.com>
Thu, 17 Apr 2014 04:58:28 +0000 (12:58 +0800)
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
cinder/db/sqlalchemy/api.py
cinder/tests/test_db_api.py
cinder/tests/test_quota.py

index 602a3084d08828f49555fe0d7f136f13b13e2ae4..8881e80e9d47b8453225c993c151f0ed17d1f028 100644 (file)
@@ -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."""
index 16a0402b4117ddf5595f3a1f7ace93cc894bf6e9..b3244577d90ec7dafea5ae167afe42d8b70153e0 100644 (file)
@@ -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)
-
-
 ###################
 
 
index 07bb71faa832a763fd270bab967ec5b122979a2a..ddd0726fd7815b4ac6393871af7f3893b62f1e60 100644 (file)
@@ -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,
index 62a87d555b478bde9f22c37020eb8ab37fa937de..269bf8c378ee87d8c5d4d06b5f3997be2821b543 100644 (file)
@@ -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'])