Merge "volume upload-to-image fails for iso disk-format"
This commit is contained in:
commit
0ca16b39cf
|
@ -25,6 +25,7 @@ from cinder.api.openstack import api_version_request
|
|||
from cinder.api.openstack import wsgi
|
||||
from cinder import exception
|
||||
from cinder.i18n import _
|
||||
from cinder.image import image_utils
|
||||
from cinder import utils
|
||||
from cinder import volume
|
||||
|
||||
|
@ -237,10 +238,21 @@ class VolumeActionsController(wsgi.Controller):
|
|||
raise webob.exc.HTTPNotFound(explanation=error.msg)
|
||||
|
||||
authorize(context, "upload_image")
|
||||
image_metadata = {"container_format": params.get("container_format",
|
||||
"bare"),
|
||||
"disk_format": params.get("disk_format", "raw"),
|
||||
"name": params["image_name"]}
|
||||
# check for valid disk-format
|
||||
disk_format = params.get("disk_format", "raw")
|
||||
if not image_utils.validate_disk_format(disk_format):
|
||||
msg = _("Invalid disk-format '%(disk_format)s' is specified. "
|
||||
"Allowed disk-formats are %(allowed_disk_formats)s.") % {
|
||||
"disk_format": disk_format,
|
||||
"allowed_disk_formats": ", ".join(
|
||||
image_utils.VALID_DISK_FORMATS)
|
||||
}
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
image_metadata = {"container_format": params.get(
|
||||
"container_format", "bare"),
|
||||
"disk_format": disk_format,
|
||||
"name": params["image_name"]}
|
||||
|
||||
if req_version >= api_version_request.APIVersionRequest('3.1'):
|
||||
|
||||
|
|
|
@ -55,6 +55,17 @@ CONF = cfg.CONF
|
|||
CONF.register_opts(image_helper_opts)
|
||||
|
||||
|
||||
# NOTE(abhishekk): qemu-img convert command supports raw, qcow2, qed,
|
||||
# vdi, vmdk and vhd disk-formats but glance doesn't support qed and
|
||||
# vhd(vpc) disk-formats.
|
||||
# Ref: http://docs.openstack.org/image-guide/convert-images.html
|
||||
VALID_DISK_FORMATS = ('raw', 'vmdk', 'vdi', 'qcow2')
|
||||
|
||||
|
||||
def validate_disk_format(disk_format):
|
||||
return disk_format in VALID_DISK_FORMATS
|
||||
|
||||
|
||||
def qemu_img_info(path, run_as_root=True):
|
||||
"""Return an object containing the parsed output from qemu-img info."""
|
||||
cmd = ('env', 'LC_ALL=C', 'qemu-img', 'info', path)
|
||||
|
|
|
@ -906,6 +906,21 @@ class VolumeImageActionsTest(test.TestCase):
|
|||
id,
|
||||
body)
|
||||
|
||||
def test_copy_volume_to_image_invalid_disk_format(self):
|
||||
id = fake.IMAGE_ID
|
||||
vol = {"container_format": 'bare',
|
||||
"disk_format": 'iso',
|
||||
"image_name": 'image_name',
|
||||
"force": True}
|
||||
body = {"os-volume_upload_image": vol}
|
||||
req = fakes.HTTPRequest.blank('/v2/%s/volumes/%s/action'
|
||||
% (fake.PROJECT_ID, id))
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller._volume_upload_image,
|
||||
req,
|
||||
id,
|
||||
body)
|
||||
|
||||
def test_copy_volume_to_image_valueerror(self):
|
||||
def stub_upload_volume_to_image_service_raise(self, context, volume,
|
||||
metadata, force):
|
||||
|
|
Loading…
Reference in New Issue