]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix errors in volume usage audit script
authorMichael Kerrin <michael.kerrin@hp.com>
Tue, 3 Sep 2013 12:53:34 +0000 (12:53 +0000)
committerMichael Kerrin <michael.kerrin@hp.com>
Tue, 3 Sep 2013 13:05:11 +0000 (13:05 +0000)
The snapshot_get_active_by_window DB query was returning snapshots
where we couldn't access the related volume object. This was due to
a) the volume not been loaded and the join failing due to detached
session object.
and b) the related volume was deleted so it didn't show return from
the join

Fixes bug: 1220140

Change-Id: I0de993ba0ca482fa9ab80d4d5cdb0ff5cc8e4d7a

cinder/db/sqlalchemy/api.py
cinder/db/sqlalchemy/models.py
cinder/tests/test_volume.py

index 55ff173e3bb9885b72f5682adfef068fa547841a..d8a40eb5d99abea392b56a8cf9dd467c5c991eab 100644 (file)
@@ -1584,6 +1584,7 @@ def snapshot_get_active_by_window(context, begin, end=None, project_id=None):
     query = model_query(context, models.Snapshot, read_deleted="yes")
     query = query.filter(or_(models.Snapshot.deleted_at == None,
                              models.Snapshot.deleted_at > begin))
+    query = query.options(joinedload(models.Snapshot.volume))
     if end:
         query = query.filter(models.Snapshot.created_at < end)
     if project_id:
index 363c765058b3de130c015a6a264a4095bc5582d2..66f44a40a634014ee44843ae119e698473060a7d 100644 (file)
@@ -375,9 +375,7 @@ class Snapshot(BASE, CinderBase):
 
     volume = relationship(Volume, backref="snapshots",
                           foreign_keys=volume_id,
-                          primaryjoin='and_('
-                          'Snapshot.volume_id == Volume.id,'
-                          'Snapshot.deleted == False)')
+                          primaryjoin='Snapshot.volume_id == Volume.id')
 
 
 class SnapshotMetadata(BASE, CinderBase):
index a6f9469e55c80f56aa806579653f95113d2f8561..86d3f3827cc1f6ad50adab64396b734465e42363 100644 (file)
@@ -1869,8 +1869,11 @@ class GetActiveByWindowTestCase(BaseVolumeTestCase):
             datetime.datetime(1, 4, 1, 1, 1, 1))
         self.assertEqual(len(snapshots), 3)
         self.assertEqual(snapshots[0].id, u'2')
+        self.assertEqual(snapshots[0].volume.id, u'1')
         self.assertEqual(snapshots[1].id, u'3')
+        self.assertEqual(snapshots[1].volume.id, u'1')
         self.assertEqual(snapshots[2].id, u'4')
+        self.assertEqual(snapshots[2].volume.id, u'1')
 
 
 class DriverTestCase(test.TestCase):