Skip to content

Commit

Permalink
Merge pull request #37 from stackhpc/upstream/2023.1-2024-07-15
Browse files Browse the repository at this point in the history
Synchronise 2023.1 with upstream
  • Loading branch information
markgoddard authored Jul 16, 2024
2 parents a33d6aa + edd75b7 commit e177c71
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .zuul.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
description: |
The regular tempest-integrated-storage job but with glance metadata injection
post-run: playbooks/post-check-metadata-injection.yaml
timeout: 10800
vars:
configure_swap_size: 8192
tempest_concurrency: 3
Expand Down Expand Up @@ -235,6 +236,7 @@
"$TEMPEST_CONFIG":
image:
image_caching_enabled: True
disk_formats: qcow2,ari,aki,vhd,vmdk,raw,ami,vdi,iso,vhdx

- job:
name: glance-multistore-cinder-import
Expand Down Expand Up @@ -299,6 +301,7 @@
description: |
This job runs the Tempest tests with scope and new defaults enabled
Glance services.
timeout: 10800
vars:
devstack_localrc:
NOVA_ENFORCE_SCOPE: true
Expand Down
10 changes: 10 additions & 0 deletions glance/async_/flows/base_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ def execute(self, image_id):
'bfile': backing_file}
raise RuntimeError(msg)

try:
data_file = metadata['format-specific']['data']['data-file']
except KeyError:
data_file = None
if data_file is not None:
msg = _("File %(path)s has invalid data-file "
"%(dfile)s, aborting.") % {"path": path,
"dfile": data_file}
raise RuntimeError(msg)

return path

def revert(self, image_id, result, **kwargs):
Expand Down
52 changes: 45 additions & 7 deletions glance/async_/flows/plugins/image_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from taskflow import task

from glance.async_ import utils
from glance.common import format_inspector
from glance.i18n import _, _LI

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -87,8 +88,40 @@ def _execute(self, action, file_path, **kwargs):
'target': target_format}
self.dest_path = dest_path

source_format = action.image_disk_format
inspector_cls = format_inspector.get_inspector(source_format)
if not inspector_cls:
# We cannot convert from disk_format types that qemu-img doesn't
# support (like iso, ploop, etc). The ones it supports overlaps
# with the ones we have inspectors for, so reject conversion for
# any format we don't have an inspector for.
raise RuntimeError(
'Unable to convert from format %s' % source_format)

# Use our own cautious inspector module (if we have one for this
# format) to make sure a file is the format the submitter claimed
# it is and that it passes some basic safety checks _before_ we run
# qemu-img on it.
# See https://bugs.launchpad.net/nova/+bug/2059809 for details.
try:
inspector = inspector_cls.from_file(src_path)
if not inspector.safety_check():
LOG.error('Image failed %s safety check; aborting conversion',
source_format)
raise RuntimeError('Image has disallowed configuration')
except RuntimeError:
raise
except format_inspector.ImageFormatError as e:
LOG.error('Image claimed to be %s format failed format '
'inspection: %s', source_format, e)
raise RuntimeError('Image format detection failed')
except Exception as e:
LOG.exception('Unknown error inspecting image format: %s', e)
raise RuntimeError('Unable to inspect image')

try:
stdout, stderr = putils.trycmd("qemu-img", "info",
"-f", source_format,
"--output=json",
src_path,
prlimit=utils.QEMU_IMG_PROC_LIMITS,
Expand All @@ -105,13 +138,10 @@ def _execute(self, action, file_path, **kwargs):
raise RuntimeError(stderr)

metadata = json.loads(stdout)
try:
source_format = metadata['format']
except KeyError:
msg = ("Failed to do introspection as part of image "
"conversion for %(iid)s: Source format not reported")
LOG.error(msg, {'iid': self.image_id})
raise RuntimeError(msg)
if metadata.get('format') != source_format:
LOG.error('Image claiming to be %s reported as %s by qemu-img',
source_format, metadata.get('format', 'unknown'))
raise RuntimeError('Image metadata disagrees about format')

virtual_size = metadata.get('virtual-size', 0)
action.set_image_attribute(virtual_size=virtual_size)
Expand All @@ -121,6 +151,14 @@ def _execute(self, action, file_path, **kwargs):
raise RuntimeError(
'QCOW images with backing files are not allowed')

try:
data_file = metadata['format-specific']['data']['data-file']
except KeyError:
data_file = None
if data_file is not None:
raise RuntimeError(
'QCOW images with data-file set are not allowed')

if metadata.get('format') == 'vmdk':
create_type = metadata.get(
'format-specific', {}).get(
Expand Down
Loading

0 comments on commit e177c71

Please sign in to comment.