From: Aric Gardner Date: Thu, 6 Aug 2020 20:18:10 +0000 (-0400) Subject: Preform check that disk-format maches X-Git-Tag: v0.35.0~2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F55%2F64955%2F5;p=releng%2Flftools.git Preform check that disk-format maches check that the disk format of the image to be uploaded matches the disk-format specified by the user. (default raw) Issue-ID: RELENG-3149 Signed-off-by: Aric Gardner Change-Id: Ia989e53d2f4fc8ca541f68e17ea8d2663dd7bff4 --- diff --git a/docs/commands/openstack.rst b/docs/commands/openstack.rst index 2dacce9a..d820aa05 100644 --- a/docs/commands/openstack.rst +++ b/docs/commands/openstack.rst @@ -3,6 +3,7 @@ OpenStack ********* Requires a `pip install lftools[openstack]` to activate this command. +Requires `qemu-img` binary to upload images .. program-output:: lftools openstack --help diff --git a/lftools/openstack/cmd.py b/lftools/openstack/cmd.py index 19d56b00..1e683f9f 100644 --- a/lftools/openstack/cmd.py +++ b/lftools/openstack/cmd.py @@ -14,6 +14,8 @@ __author__ = "Thanh Ha" import click +import subprocess +import re from lftools.openstack import image as os_image from lftools.openstack import object as os_object @@ -87,6 +89,16 @@ def share(ctx, image, dest): def upload(ctx, image, name, disk_format): """Upload image to OpenStack cloud.""" name = " ".join(name) + + disktype = subprocess.check_output(["qemu-img", "info", image]).decode("utf-8") + pattern = disk_format + result = re.search(pattern, disktype) + if result: + print("PASS Image format matches {}".format(disk_format)) + else: + print("ERROR Image is not in {} format".format(disk_format)) + exit(1) + os_image.upload(ctx.obj["os_cloud"], image, name, disk_format) diff --git a/releasenotes/notes/openstack-image-a49d486152901765.yaml b/releasenotes/notes/openstack-image-a49d486152901765.yaml new file mode 100644 index 00000000..cf8467ae --- /dev/null +++ b/releasenotes/notes/openstack-image-a49d486152901765.yaml @@ -0,0 +1,13 @@ +--- +upgrade: + - | + lftools image upload command: + NOTE: `qemu-img` is now required to be installed and on the path for image + uploading to work + +fixes: + - | + lftools image upload command: + Previously image was not verified to match the type of image specified + prior to upload. Image is now checked with `qemu-img` before upload to + ensure it is of the correct type.