summaryrefslogtreecommitdiffstats
path: root/tests/vm/basevm.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/vm/basevm.py')
-rw-r--r--tests/vm/basevm.py54
1 files changed, 38 insertions, 16 deletions
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 756ccf7aca..a80b616a08 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -61,8 +61,11 @@ class BaseVM(object):
# 4 is arbitrary, but greater than 2,
# since we found we need to wait more than twice as long.
tcg_ssh_timeout_multiplier = 4
- def __init__(self, debug=False, vcpus=None):
+ def __init__(self, debug=False, vcpus=None, genisoimage=None,
+ build_path=None):
self._guest = None
+ self._genisoimage = genisoimage
+ self._build_path = build_path
self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",
suffix=".tmp",
dir="."))
@@ -183,15 +186,15 @@ class BaseVM(object):
"-device", "virtio-blk,drive=drive0,bootindex=0"]
args += self._data_args + extra_args
logging.debug("QEMU args: %s", " ".join(args))
- qemu_bin = os.environ.get("QEMU", "qemu-system-" + self.arch)
- guest = QEMUMachine(binary=qemu_bin, args=args)
+ qemu_path = get_qemu_path(self.arch, self._build_path)
+ guest = QEMUMachine(binary=qemu_path, args=args)
guest.set_machine('pc')
guest.set_console()
try:
guest.launch()
except:
logging.error("Failed to launch QEMU, command line:")
- logging.error(" ".join([qemu_bin] + args))
+ logging.error(" ".join([qemu_path] + args))
logging.error("Log:")
logging.error(guest.get_log())
logging.error("QEMU version >= 2.10 is required")
@@ -317,24 +320,24 @@ class BaseVM(object):
def print_step(self, text):
sys.stderr.write("### %s ...\n" % text)
- def wait_ssh(self, wait_root=False, seconds=300):
+ def wait_ssh(self, wait_root=False, seconds=300, cmd="exit 0"):
# Allow more time for VM to boot under TCG.
if not kvm_available(self.arch):
seconds *= self.tcg_ssh_timeout_multiplier
starttime = datetime.datetime.now()
endtime = starttime + datetime.timedelta(seconds=seconds)
- guest_up = False
+ cmd_success = False
while datetime.datetime.now() < endtime:
- if wait_root and self.ssh_root("exit 0") == 0:
- guest_up = True
+ if wait_root and self.ssh_root(cmd) == 0:
+ cmd_success = True
break
- elif self.ssh("exit 0") == 0:
- guest_up = True
+ elif self.ssh(cmd) == 0:
+ cmd_success = True
break
seconds = (endtime - datetime.datetime.now()).total_seconds()
logging.debug("%ds before timeout", seconds)
time.sleep(1)
- if not guest_up:
+ if not cmd_success:
raise Exception("Timeout while waiting for guest ssh")
def shutdown(self):
@@ -381,15 +384,28 @@ class BaseVM(object):
udata.writelines(["apt:\n",
" proxy: %s" % proxy])
udata.close()
- subprocess.check_call(["genisoimage", "-output", "cloud-init.iso",
+ subprocess.check_call([self._genisoimage, "-output", "cloud-init.iso",
"-volid", "cidata", "-joliet", "-rock",
"user-data", "meta-data"],
- cwd=cidir,
- stdin=self._devnull, stdout=self._stdout,
- stderr=self._stdout)
+ cwd=cidir,
+ stdin=self._devnull, stdout=self._stdout,
+ stderr=self._stdout)
return os.path.join(cidir, "cloud-init.iso")
+def get_qemu_path(arch, build_path=None):
+ """Fetch the path to the qemu binary."""
+ # If QEMU environment variable set, it takes precedence
+ if "QEMU" in os.environ:
+ qemu_path = os.environ["QEMU"]
+ elif build_path:
+ qemu_path = os.path.join(build_path, arch + "-softmmu")
+ qemu_path = os.path.join(qemu_path, "qemu-system-" + arch)
+ else:
+ # Default is to use system path for qemu.
+ qemu_path = "qemu-system-" + arch
+ return qemu_path
+
def parse_args(vmcls):
def get_default_jobs():
@@ -420,10 +436,15 @@ def parse_args(vmcls):
help="build QEMU from source in guest")
parser.add_option("--build-target",
help="QEMU build target", default="check")
+ parser.add_option("--build-path", default=None,
+ help="Path of build directory, "\
+ "for using build tree QEMU binary. ")
parser.add_option("--interactive", "-I", action="store_true",
help="Interactively run command")
parser.add_option("--snapshot", "-s", action="store_true",
help="run tests with a snapshot")
+ parser.add_option("--genisoimage", default="genisoimage",
+ help="iso imaging tool")
parser.disable_interspersed_args()
return parser.parse_args()
@@ -435,7 +456,8 @@ def main(vmcls):
return 1
logging.basicConfig(level=(logging.DEBUG if args.debug
else logging.WARN))
- vm = vmcls(debug=args.debug, vcpus=args.jobs)
+ vm = vmcls(debug=args.debug, vcpus=args.jobs,
+ genisoimage=args.genisoimage, build_path=args.build_path)
if args.build_image:
if os.path.exists(args.image) and not args.force:
sys.stderr.writelines(["Image file exists: %s\n" % args.image,