Preform check that disk-format maches 55/64955/5
authorAric Gardner <agardner@linuxfoundation.org>
Thu, 6 Aug 2020 20:18:10 +0000 (16:18 -0400)
committerAric Gardner <agardner@linuxfoundation.org>
Mon, 10 Aug 2020 18:32:55 +0000 (14:32 -0400)
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 <agardner@linuxfoundation.org>
Change-Id: Ia989e53d2f4fc8ca541f68e17ea8d2663dd7bff4

docs/commands/openstack.rst
lftools/openstack/cmd.py
releasenotes/notes/openstack-image-a49d486152901765.yaml [new file with mode: 0644]

index 2dacce9..d820aa0 100644 (file)
@@ -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
 
index 19d56b0..1e683f9 100644 (file)
@@ -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 (file)
index 0000000..cf8467a
--- /dev/null
@@ -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.