def qemu_start(self): """Start QEMU and wait until VM boot. :returns: VM node info. :rtype: dict """ cmd_opts = OptionString() cmd_opts.add(f"{Constants.QEMU_BIN_PATH}/qemu-system-{self._arch}") cmd_opts.extend(self._params) message = f"QEMU: Start failed on {self._node[u'host']}!" try: DUTSetup.check_huge_page( self._node, u"/dev/hugepages", int(self._opt.get(u"mem"))) exec_cmd_no_error( self._node, cmd_opts, timeout=300, sudo=True, message=message ) self._wait_until_vm_boot() except RuntimeError: self.qemu_kill_all() raise return self._vm_info
def qemu_start(self): """Start QEMU and wait until VM boot. :returns: VM node info. :rtype: dict """ cmd_opts = OptionString() cmd_opts.add('{bin_path}/qemu-system-{arch}'.format( bin_path=Constants.QEMU_BIN_PATH, arch=Topology.get_node_arch(self._node))) cmd_opts.extend(self._params) message = ('QEMU: Start failed on {host}!'. format(host=self._node['host'])) try: DUTSetup.check_huge_page( self._node, '/dev/hugepages', self._opt.get('mem')) exec_cmd_no_error( self._node, cmd_opts, timeout=300, sudo=True, message=message) self._wait_until_vm_boot() except RuntimeError: self.qemu_kill_all() raise return self._vm_info
def qemu_start(self): """Start QEMU and wait until VM boot. .. note:: First set at least node to run QEMU on. :returns: VM node info. :rtype: dict """ # Qemu binary path bin_path = ('{qemu_path}{qemu_bin}'. format(qemu_path=self._qemu_opt.get('qemu_path'), qemu_bin=self._qemu_opt.get('qemu_bin'))) # Memory and huge pages mem = ('-object memory-backend-file,id=mem,size={mem_size}M,' 'mem-path={path},share=on -m {mem_size} -numa node,memdev=mem'. format(mem_size=self._qemu_opt.get('mem_size'), path=self._qemu_opt.get('huge_mnt'))) # Drive option drive = ('-drive file={disk_image},format=raw,cache=none,if=virtio' '{locking}'. format(disk_image=self._qemu_opt.get('disk_image'), locking=',file.locking=off'\ if self._qemu_version_is_greater('2.10') else '')) # SSH forwarding ssh = ('-net user,hostfwd=tcp::{ssh_fwd_port}-:22'. format(ssh_fwd_port=self._qemu_opt.get('ssh_fwd_port'))) # Setup QMP via unix socket qmp = ('-qmp unix:{qmp_sock},server,nowait'. format(qmp_sock=self._qemu_opt.get('qmp_sock'))) # Setup QGA via chardev (unix socket) and isa-serial channel qga = ('-chardev socket,path={qga_sock},server,nowait,id=qga0 ' '-device isa-serial,chardev=qga0'. format(qga_sock=self._qemu_opt.get('qga_sock'))) # Setup serial console serial = ('-chardev socket,host=127.0.0.1,port={serial_port},id=gnc0,' 'server,nowait -device isa-serial,chardev=gnc0'. format(serial_port=self._qemu_opt.get('serial_port'))) # Graphic setup graphic = '-monitor none -display none -vga none' # PID file pid = ('-pidfile {pid_file}'. format(pid_file=self._qemu_opt.get('pid_file'))) # By default check only if hugepages are available. # If 'huge_allocate' is set to true try to allocate as well. DUTSetup.check_huge_page(self._node, self._qemu_opt.get('huge_mnt'), self._qemu_opt.get('mem_size'), allocate=self._qemu_opt.get('huge_allocate')) # Run QEMU cmd = ('{bin_path} {smp} {mem} {ssh} {options} {drive} {qmp} {serial} ' '{qga} {graphic} {pid}'. format(bin_path=bin_path, smp=self._qemu_opt.get('smp'), mem=mem, ssh=ssh, options=self._qemu_opt.get('options'), drive=drive, qmp=qmp, serial=serial, qga=qga, graphic=graphic, pid=pid)) try: ret_code, _, _ = self._ssh.exec_command_sudo(cmd, timeout=300) if int(ret_code) != 0: raise RuntimeError('QEMU start failed on {host}'. format(host=self._node['host'])) # Wait until VM boot self._wait_until_vm_boot() except (RuntimeError, SSHTimeout): self.qemu_kill_all() self.qemu_clear_socks() raise logger.trace('QEMU started successfully.') # Update interface names in VM node dict self._update_vm_interfaces() # Return VM node dict return self._vm_info