def load_configs(config_path="."): global vms # Clear out the default unconfigured vm if (not vms[0]._config): vms = [] print color.HEADER("IncludeOS vmrunner loading VM configs") schema_path = package_path + "/vm.schema.json" print INFO, "Validating JSON according to schema ", schema_path validate_vm.load_schema(schema_path) validate_vm.load_configs(config_path) if validate_vm.valid_vms: print INFO, "Loaded VM specification(s) from JSON" for spec in validate_vm.valid_vms: print INFO, "Found VM spec: " print color.DATA(spec.__str__()) vms.append(vm(spec)) else: print color.WARNING( nametag), "No VM specification JSON found, trying default config" vms.append(vm(default_config)) return vms
def boot(self, multiboot, kernel_args = "", image_name = None): self._stopped = False # Use provided image name if set, otherwise try to find it in json-config if not image_name: image_name = self._config["image"] # multiboot - e.g. boot with '-kernel' and no bootloader if multiboot: # TODO: Remove .img-extension from vm.json in tests to avoid this hack if (image_name.endswith(".img")): image_name = image_name.split(".")[0] kernel_args = ["-kernel", image_name, "-append", kernel_args] disk_args = [] print self.INFO, "Booting", image_name, "directly without bootloader (multiboot / -kernel args)" else: kernel_args = [] disk_args = self.drive_arg(image_name, "ide") print self.INFO, "Booting", image_name, "with a bootable disk image" if "bios" in self._config: kernel_args.extend(["-bios", self._config["bios"]]) if "drives" in self._config: for disk in self._config["drives"]: disk_args += self.drive_arg(disk["file"], disk["type"], disk["format"], disk["media"]) net_args = [] i = 0 if "net" in self._config: for net in self._config["net"]: net_args += self.net_arg(net["backend"], net["device"], "net"+str(i), net["mac"]) i+=1 mem_arg = [] if "mem" in self._config: mem_arg = ["-m", str(self._config["mem"])] vga_arg = ["-nographic" ] if "vga" in self._config: vga_arg = ["-vga", str(self._config["vga"])] # TODO: sudo is only required for tap networking and kvm. Check for those. command = ["sudo", "qemu-system-x86_64"] if self.kvm_present(): command.append("--enable-kvm") command += kernel_args command += disk_args + net_args + mem_arg + vga_arg print self.INFO, "command:" print color.DATA(" ".join(command)) try: self.start_process(command) except Exception as e: print self.INFO,"Starting subprocess threw exception:", e raise e
def wait_status(self): self.print_start() # Start and wait for the process self.output_ = self.proc_.communicate() if self.proc_.returncode == 0: print pretty.PASS_INLINE() else: print pretty.FAIL_INLINE() print pretty.INFO("Process stdout") print pretty.DATA(self.output_[0]) print pretty.INFO("Process stderr") print pretty.DATA(self.output_[1]) return self.proc_.returncode
def boot(self, multiboot, kernel_args): self._nametag = "<" + type(self).__name__ + ">" print color.INFO(self._nametag), "booting", self._config["image"] # multiboot if multiboot: print color.INFO( self._nametag), "Booting with multiboot (-kernel args)" kernel_args = [ "-kernel", self._config["image"].split(".")[0], "-append", kernel_args ] else: kernel_args = [] disk_args = self.drive_arg(self._config["image"], "ide") if "drives" in self._config: for disk in self._config["drives"]: disk_args += self.drive_arg(disk["file"], disk["type"], disk["format"], disk["media"]) net_args = [] i = 0 if "net" in self._config: for net in self._config["net"]: net_args += self.net_arg(net["backend"], net["device"], "net" + str(i), net["mac"]) i += 1 mem_arg = [] if "mem" in self._config: mem_arg = ["-m", str(self._config["mem"])] command = ["qemu-system-x86_64"] if self.kvm_present(): command.append("--enable-kvm") command += kernel_args command += ["-nographic"] + disk_args + net_args + mem_arg print color.INFO(self._nametag), "command:" print color.DATA(command.__str__()) self._proc = start_process(command)
def DHCP_test(): print "<Test.py> Got IP" ip_string = vm.readline() print "<Test.py> Assigned address: ", ip_string print "<Test.py> Trying to ping" try: command = [ "ping", ip_string.rstrip(), "-c", str(ping_count), "-i", "0.2" ] print color.DATA(" ".join(command)) print subprocess.check_output(command) print "<Test.py> Ping SUCCESS - Process returned 0 exit status" vm.exit(0, "SUCCESS") except Exception as e: print "<Test.py> Ping FAILED Process threw exception:" print e return False
print color.HEADER("IncludeOS vmrunner initializing tests") print color.INFO(nametag), "Validating test service" validate_test.load_schema( os.environ.get( "INCLUDEOS_SRC", os.path.realpath(os.path.join(os.getcwd(), os.path.dirname( __file__))).split('/test')[0]) + "/test/vm.schema.json") validate_test.has_required_stuff(".") default_spec = {"image": "test.img"} # Provide a list of VM's with validated specs vms = [] if validate_test.valid_vms: print print color.INFO(nametag), "Loaded VM specification(s) from JSON" for spec in validate_test.valid_vms: print color.INFO(nametag), "Found VM spec: " print color.DATA(spec.__str__()) vms.append(vm(spec)) else: print print color.WARNING( nametag ), "No VM specification JSON found, trying default: ", default_spec vms.append(vm(default_spec))