summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-02-15 23:34:08 +0000
committerGerrit Code Review <review@openstack.org>2023-02-15 23:34:08 +0000
commit81da9ccbdee88e77f06e42c4f121b68cf2c1389e (patch)
treec53f1e519bba2eea7ed63d90be06640099f4dd7d
parentce8251f8e1656105834456db1adb1deaeced3903 (diff)
parent943124ed6c0f2e8caf9ceb296174e71b47fc6f4f (diff)
downloadglance-81da9ccbdee88e77f06e42c4f121b68cf2c1389e.tar.gz
Merge "Further robustification of format_inspector"
-rw-r--r--glance/location.py16
-rw-r--r--glance/tests/unit/test_store_image.py31
2 files changed, 43 insertions, 4 deletions
diff --git a/glance/location.py b/glance/location.py
index 13e73e21a..cf05fcdb2 100644
--- a/glance/location.py
+++ b/glance/location.py
@@ -584,15 +584,23 @@ class ImageProxy(glance.domain.proxy.Image):
self._upload_to_store(data, verifier, backend, size)
- if fmt and fmt.format_match and fmt.virtual_size:
- self.image.virtual_size = fmt.virtual_size
- LOG.info('Image format matched and virtual size computed: %i',
- self.image.virtual_size)
+ virtual_size = 0
+ if fmt and fmt.format_match:
+ try:
+ virtual_size = fmt.virtual_size
+ LOG.info('Image format matched and virtual size computed: %i',
+ virtual_size)
+ except Exception as e:
+ LOG.error(_LE('Unable to determine virtual_size because: %s'),
+ e)
elif fmt:
LOG.warning('Image format %s did not match; '
'unable to calculate virtual size',
self.image.disk_format)
+ if virtual_size:
+ self.image.virtual_size = fmt.virtual_size
+
if set_active and self.image.status != 'active':
self.image.status = 'active'
diff --git a/glance/tests/unit/test_store_image.py b/glance/tests/unit/test_store_image.py
index 50bda54a2..01b1fc4ff 100644
--- a/glance/tests/unit/test_store_image.py
+++ b/glance/tests/unit/test_store_image.py
@@ -283,6 +283,37 @@ class TestStoreImage(utils.BaseTestCase):
self.assertEqual('active', image.status)
self.assertEqual(0, image.virtual_size)
+ @mock.patch('glance.common.format_inspector.QcowInspector.virtual_size',
+ new_callable=mock.PropertyMock)
+ @mock.patch('glance.common.format_inspector.QcowInspector.format_match',
+ new_callable=mock.PropertyMock)
+ def test_image_set_data_inspector_virtual_size_failure(self, mock_fm,
+ mock_vs):
+ # Force our format to match
+ mock_fm.return_value = True
+
+ # Make virtual_size fail in some unexpected way
+ mock_vs.side_effect = ValueError('some error')
+
+ context = glance.context.RequestContext(user=USER1)
+ image_stub = ImageStub(UUID2, status='queued', locations=[])
+ image_stub.disk_format = 'qcow2'
+ # We are going to pass an iterable data source, so use the
+ # FakeStoreAPIReader that actually reads from that data
+ store_api = unit_test_utils.FakeStoreAPIReader()
+ image = glance.location.ImageProxy(image_stub, context,
+ store_api, self.store_utils)
+
+ # Make sure set_data proceeds even though the format clearly
+ # does not match
+ image.set_data(iter(['YYYY']), 4)
+ self.assertEqual(4, image.size)
+ # NOTE(markwash): FakeStore returns image_id for location
+ self.assertEqual(UUID2, image.locations[0]['url'])
+ self.assertEqual('Z', image.checksum)
+ self.assertEqual('active', image.status)
+ self.assertEqual(0, image.virtual_size)
+
@mock.patch('glance.common.format_inspector.get_inspector')
def test_image_set_data_inspector_not_needed(self, mock_gi):
context = glance.context.RequestContext(user=USER1)