From 34c4690d4943f4a794b9ed8e4ed4f7e778bd2ca0 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 5 May 2020 15:45:46 -0400 Subject: [PATCH] Don't convert bytes into KB in OVA import Doing so can create an image that is 1 sector (512 bytes) too large, which will then break qemu-img because it's stupid (or, VMDK is stupid, I haven't decided which is).. Current Ceph rbd commands seem to accept --size in bytes so this is fine. --- api-daemon/pvcapid/ova.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/api-daemon/pvcapid/ova.py b/api-daemon/pvcapid/ova.py index 216534fc..8fdf004f 100755 --- a/api-daemon/pvcapid/ova.py +++ b/api-daemon/pvcapid/ova.py @@ -177,12 +177,9 @@ def upload_ova(ova_data, pool, name, ova_size): retflag, retdata = pvc_ceph.remove_volume(zk_conn, pool, "ova_{}".format(name)) pvc_common.stopZKConnection(zk_conn) - # Normalize the OVA size to MB - # The function always return XXXXB, so strip off the B and convert to an integer + # Normalize the OVA size to bytes ova_size_bytes = int(pvc_ceph.format_bytes_fromhuman(ova_size)[:-1]) - # Put the size into KB which rbd --size can understand - ova_size_kb = math.ceil(ova_size_bytes / 1024) - ova_size = "{}K".format(ova_size_kb) + ova_size = pvc_ceph.format_bytes_fromhuman(ova_size) # Verify that the cluster has enough space to store the OVA volumes (2x OVA size, temporarily, 1x permanently) zk_conn = pvc_common.startZKConnection(config['coordinators']) @@ -272,11 +269,9 @@ def upload_ova(ova_data, pool, name, ova_size): dev_size_raw = ova_archive.getmember(dev_src).size vm_volume_size = disk.get('capacity') - # Normalize the dev size to KB - # The function always return XXXXB, so strip off the B and convert to an integer + # Normalize the dev size to bytes dev_size_bytes = int(pvc_ceph.format_bytes_fromhuman(dev_size_raw)[:-1]) - dev_size_kb = math.ceil(dev_size_bytes / 1024) - dev_size = "{}K".format(dev_size_kb) + dev_size = pvc_ceph.format_bytes_fromhuman(dev_size_raw) def cleanup_img_maps(): zk_conn = pvc_common.startZKConnection(config['coordinators'])