From 59cd09d06fb7cb9d6a6c451c89a8416aa0b583ca Mon Sep 17 00:00:00 2001 From: Alfred Bratterud Date: Fri, 27 Jan 2017 14:59:28 +0100 Subject: [PATCH] boot/vmrunner: don't assume image name in config and don't look for SUCCESS in boot --- etc/boot | 3 +++ vmrunner/vmrunner.py | 63 ++++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/etc/boot b/etc/boot index 1cfd322b97..fcee55c285 100755 --- a/etc/boot +++ b/etc/boot @@ -111,6 +111,9 @@ for vm_ in vmrunner.vms: if vm_._config.has_key("image") and vm_._config["image"].startswith(image_name): vm = vm_ +# Don't listen to events needed by testrunner +vm.on_success(lambda: None, do_exit = False) + if (args.clean): print INFO, "Cleaning build" vm.clean() diff --git a/vmrunner/vmrunner.py b/vmrunner/vmrunner.py index 7e049034ad..5d3099104a 100644 --- a/vmrunner/vmrunner.py +++ b/vmrunner/vmrunner.py @@ -109,36 +109,39 @@ def abstract(): # (It seems to be recommended for "new style classes" to inherit object) class hypervisor(object): - def __init__(self, config): - self._config = config; + def __init__(self, config): + self._config = config; - # Boot a VM, returning a hypervisor handle for reuse - def boot(self): - abstract() + # Boot a VM, returning a hypervisor handle for reuse + def boot(self): + abstract() - # Stop the VM booted by boot - def stop(self): - abstract() + # Stop the VM booted by boot + def stop(self): + abstract() - # Read a line of output from vm - def readline(self): - abstract() + # Read a line of output from vm + def readline(self): + abstract() - # Verify that the hypervisor is available - def available(self, config_data = None): - abstract() + # Verify that the hypervisor is available + def available(self, config_data = None): + abstract() - # Wait for this VM to exit - def wait(self): - abstract() + # Wait for this VM to exit + def wait(self): + abstract() - # Wait for this VM to exit - def poll(self): - abstract() + # Wait for this VM to exit + def poll(self): + abstract() - # A descriptive name - def name(self): - abstract() + # A descriptive name + def name(self): + abstract() + + def image_name(self): + abstract() # Qemu Hypervisor interface @@ -149,6 +152,7 @@ def __init__(self, config): self._proc = None self._stopped = False self._sudo = False + self._image_name = self._config if "image" in self._config else self.name() + " vm" # Pretty printing self.info = Logger(color.INFO("<" + type(self).__name__ + ">")) @@ -156,6 +160,9 @@ def __init__(self, config): def name(self): return "Qemu" + def image_name(serlf): + return self._image_name + def drive_arg(self, filename, drive_type = "virtio", drive_format = "raw", media_type = "disk"): return ["-drive","file=" + filename + ",format=" + drive_format @@ -219,6 +226,8 @@ def boot(self, multiboot, kernel_args = "", image_name = None): if not image_name: image_name = self._config["image"] + self._image_name = image_name + # multiboot - e.g. boot with '-kernel' and no bootloader if multiboot: @@ -294,7 +303,7 @@ def stop(self): parent = psutil.Process(self._proc.pid) children = parent.children() - info ("Stopping", self._config["image"], "PID",self._proc.pid, "with", signal) + info ("Stopping", self._image_name, "PID",self._proc.pid, "with", signal) for child in children: info (" + child process ", child.pid) @@ -421,8 +430,10 @@ def panic(self, panic_line): def on_output(self, output, callback): self._on_output[ output ] = callback - def on_success(self, callback): - self._on_output["SUCCESS"] = lambda(line) : [callback(line), self._on_success(line)] + def on_success(self, callback, do_exit = True): + if do_exit: + self._on_output["SUCCESS"] = lambda(line) : [callback(line), self._on_success(line)] + else: self._on_output["SUCCESS"] = callback def on_panic(self, callback): self._on_output["PANIC"] = lambda(line) : [callback(line), self._on_panic(line)]