Merge "Fix image-volume cache to use volume object when evicting"
This commit is contained in:
@@ -20,6 +20,7 @@ from oslo_log import log as logging
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from cinder.i18n import _LW
|
||||
from cinder import objects
|
||||
from cinder import rpc
|
||||
|
||||
CONF = cfg.CONF
|
||||
@@ -191,10 +192,10 @@ class ImageVolumeCache(object):
|
||||
|
||||
def _delete_image_volume(self, context, cache_entry):
|
||||
"""Delete a volume and remove cache entry."""
|
||||
volume_ref = self.db.volume_get(context, cache_entry['volume_id'])
|
||||
volume = objects.Volume.get_by_id(context, cache_entry['volume_id'])
|
||||
|
||||
# Delete will evict the cache entry.
|
||||
self.volume_api.delete(context, volume_ref)
|
||||
self.volume_api.delete(context, volume)
|
||||
|
||||
def _should_update_entry(self, cache_entry, image_meta):
|
||||
"""Ensure that the cache entry image data is still valid."""
|
||||
|
||||
@@ -144,7 +144,8 @@ class ImageVolumeCacheTestCase(test.TestCase):
|
||||
self.assertEqual(image_id, msg['payload']['image_id'])
|
||||
self.assertEqual(1, len(self.notifier.notifications))
|
||||
|
||||
def test_get_entry_needs_update(self):
|
||||
@mock.patch('cinder.objects.Volume.get_by_id')
|
||||
def test_get_entry_needs_update(self, mock_volume_by_id):
|
||||
cache = self._build_cache()
|
||||
entry = self._build_entry()
|
||||
volume_ref = {
|
||||
@@ -160,8 +161,9 @@ class ImageVolumeCacheTestCase(test.TestCase):
|
||||
}
|
||||
(self.mock_db.
|
||||
image_volume_cache_get_and_update_last_used.return_value) = entry
|
||||
mock_volume = mock.Mock()
|
||||
self.mock_db.volume_get.return_value = mock_volume
|
||||
|
||||
mock_volume = mock.MagicMock()
|
||||
mock_volume_by_id.return_value = mock_volume
|
||||
|
||||
found_entry = cache.get_entry(self.context,
|
||||
volume_ref,
|
||||
|
||||
Reference in New Issue
Block a user