From 56daea352b2e7a4d6095f7a7ec5cb7ab600829ff Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mar 23 2018 18:15:44 +0000 Subject: inventory-qcow2: Use N host cpus, enable virtio random and rtc clock I'm doing parallel testing inside a VM, and it's obviously a lot faster if we pass through the CPUs; further there's no reason not to use the `host` model and have all features since we don't care about live migration. Further follow some best practices for guests and enable the virtio RNG and rtc clock (based on what libvirt does). --- diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2 index ab8c8bc..fd70634 100755 --- a/inventory/standard-inventory-qcow2 +++ b/inventory/standard-inventory-qcow2 @@ -7,6 +7,7 @@ import os import shutil import shlex import signal +import multiprocessing import socket import subprocess import sys @@ -104,9 +105,14 @@ def start_qemu(image, cloudinit, log, portrange=(2222, 5555)): else: raise RuntimeError("unable to find free local port to map SSH to") - return subprocess.Popen(["/usr/bin/qemu-system-x86_64", "-m", "1024", image, + # Use -cpu host and -smp by default. + # virtio-rng-pci: https://wiki.qemu.org/Features/VirtIORNG + return subprocess.Popen(["/usr/bin/qemu-system-x86_64", + "-cpu", "host", "-smp", "{}".format(multiprocessing.cpu_count()), + "-m", "1024", image, "-enable-kvm", "-snapshot", "-cdrom", cloudinit, "-net", "nic,model=virtio", "-net", "user,hostfwd=tcp:127.0.0.3:{0}-:22".format(port), + "-device", "virtio-rng-pci", "-rtc", "base=utc", "-device", "isa-serial,chardev=pts2", "-chardev", "file,id=pts2,path=" + log, "-display", "none"], stdout=open(log, 'a'), stderr=subprocess.STDOUT), port