chiark / gitweb /
calculate correct size for buildserver-box in makebuildserver
authorHans-Christoph Steiner <hans@eds.org>
Mon, 22 May 2017 14:57:47 +0000 (16:57 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Tue, 23 May 2017 18:04:08 +0000 (20:04 +0200)
https://gitlab.com/fdroid/fdroidserver/issues/238#note_24000153
"Our hard-coded image size meta-data (1000) is for some interpreted as less
than the size of the box-image by my kvm setup. This makes grub/initrd
refuse to boot. So I've changed the metadata size to 9999 which resulted in
an actually booting vm. I can log in on the builder-vm via virt-manager
and virsh.

makebuildserver

index e91a9282c7cc9a5900b2499a1383de47a63ff3c5..2fc75d8232790038cdf81a0c7d1835bdf182b6a0 100755 (executable)
@@ -12,6 +12,8 @@ import tarfile
 import vagrant
 import hashlib
 import yaml
+import math
+import json
 from clint.textui import progress
 from optparse import OptionParser
 import fdroidserver.tail
@@ -334,12 +336,13 @@ def kvm_package(boxfile):
         subprocess.check_call(['sudo', '/bin/chmod', '-R', 'a+rX', '/var/lib/libvirt/images'])
         shutil.copy2(imagepath, 'box.img')
         subprocess.check_call(['qemu-img', 'rebase', '-p', '-b', '', 'box.img'])
-        metadata = """{
-    "provider": "libvirt",
-    "format": "qcow2",
-    "virtual_size": 1000
-}
-"""
+        img_info_raw = subprocess.check_output('sudo qemu-img info --output=json box.img', shell=True)
+        img_info = json.loads(img_info_raw.decode('utf-8'))
+        metadata = {"provider": "libvirt",
+                    "format": img_info['format'],
+                    "virtual_size": math.ceil(img_info['virtual-size'] / 1024.**3),
+                    }
+
         vagrantfile = """Vagrant.configure("2") do |config|
   config.ssh.username = "vagrant"
   config.ssh.password = "vagrant"
@@ -355,7 +358,7 @@ def kvm_package(boxfile):
 end
 """
         with open('metadata.json', 'w') as fp:
-            fp.write(metadata)
+            fp.write(json.dumps(metadata))
         with open('Vagrantfile', 'w') as fp:
             fp.write(vagrantfile)
         with tarfile.open(boxfile, 'w:gz') as tar: