Fix multiple bugs in util.get_kvm_binary
authorNikos Skalkotos <skalkoto@grnet.gr>
Sat, 3 Aug 2013 09:34:33 +0000 (12:34 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Sat, 3 Aug 2013 13:00:05 +0000 (16:00 +0300)
The machine hardware name fetched by `uname -m' should have been
stripped, and a --enable-kvm option should be added if the returned
executable was qemu-system-<arch>

image_creator/os_type/windows.py
image_creator/util.py

index 5d56a05..690a569 100644 (file)
@@ -768,18 +768,21 @@ class _VM(object):
         # Use ganeti's VNC port range for a random vnc port
         self.display = random.randint(11000, 14999) - 5900
 
         # Use ganeti's VNC port range for a random vnc port
         self.display = random.randint(11000, 14999) - 5900
 
-        kvm = get_kvm_binary()
+        kvm, needed_args = get_kvm_binary()
 
         if kvm is None:
             FatalError("Can't find the kvm binary")
 
 
         if kvm is None:
             FatalError("Can't find the kvm binary")
 
-        args = [
-            kvm, '-smp', '1', '-m', '1024', '-drive',
+        args = [kvm]
+        args.extend(needed_args)
+
+        args.extend([
+            '-smp', '1', '-m', '1024', '-drive',
             'file=%s,format=raw,cache=unsafe,if=virtio' % self.disk,
             '-netdev', 'type=user,hostfwd=tcp::445-:445,id=netdev0',
             '-device', 'virtio-net-pci,mac=%s,netdev=netdev0' % random_mac(),
             '-vnc', ':%d' % self.display, '-serial', 'file:%s' % self.serial,
             'file=%s,format=raw,cache=unsafe,if=virtio' % self.disk,
             '-netdev', 'type=user,hostfwd=tcp::445-:445,id=netdev0',
             '-device', 'virtio-net-pci,mac=%s,netdev=netdev0' % random_mac(),
             '-vnc', ':%d' % self.display, '-serial', 'file:%s' % self.serial,
-            '-monitor', 'stdio']
+            '-monitor', 'stdio'])
 
         self.process = subprocess.Popen(args, stdin=subprocess.PIPE,
                                         stdout=subprocess.PIPE)
 
         self.process = subprocess.Popen(args, stdin=subprocess.PIPE,
                                         stdout=subprocess.PIPE)
index fcf5dd5..e5fab41 100644 (file)
@@ -65,21 +65,23 @@ def get_command(command):
 
 
 def get_kvm_binary():
 
 
 def get_kvm_binary():
-    """Returns the path to the kvm binary"""
+    """Returns the path to the kvm binary and some extra arguments if needed"""
 
     uname = get_command('uname')
     which = get_command('which')
 
 
     uname = get_command('uname')
     which = get_command('which')
 
-    machine = str(uname('-m'))
+    machine = str(uname('-m')).strip()
     if re.match('i[3-6]86', machine):
         machine = 'i386'
 
     binary = which('qemu-system-%s' % machine)
 
     if re.match('i[3-6]86', machine):
         machine = 'i386'
 
     binary = which('qemu-system-%s' % machine)
 
+    needed_args = "--enable-kvm",
+
     if binary is None:
     if binary is None:
-        return which('kvm')
+        return which('kvm'), tuple()
 
 
-    return binary
+    return binary, needed_args
 
 
 def try_fail_repeat(command, *args):
 
 
 def try_fail_repeat(command, *args):