1# 2# Copyright (C) 2016 Intel Corporation 3# 4# SPDX-License-Identifier: MIT 5# 6 7import os 8import sys 9import signal 10import time 11 12from .ssh import OESSHTarget 13from oeqa.utils.qemurunner import QemuRunner 14 15supported_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic'] 16 17class OEQemuTarget(OESSHTarget): 18 def __init__(self, logger, server_ip, timeout=300, user='root', 19 port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False, 20 dump_dir='', dump_host_cmds='', display='', bootlog='', 21 tmpdir='', dir_image='', boottime=60, **kwargs): 22 23 super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout, 24 user, port) 25 26 self.server_ip = server_ip 27 self.machine = machine 28 self.rootfs = rootfs 29 self.kernel = kernel 30 self.kvm = kvm 31 self.use_slirp = slirp 32 33 self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir, 34 deploy_dir_image=dir_image, display=display, 35 logfile=bootlog, boottime=boottime, 36 use_kvm=kvm, use_slirp=slirp, dump_dir=dump_dir, 37 dump_host_cmds=dump_host_cmds, logger=logger) 38 39 def start(self, params=None, extra_bootparams=None, runqemuparams=''): 40 if self.use_slirp and not self.server_ip: 41 self.logger.error("Could not start qemu with slirp without server ip - provide 'TEST_SERVER_IP'") 42 raise RuntimeError("FAILED to start qemu - check the task log and the boot log") 43 if self.runner.start(params, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams): 44 self.ip = self.runner.ip 45 if self.use_slirp: 46 target_ip_port = self.runner.ip.split(':') 47 if len(target_ip_port) == 2: 48 target_ip = target_ip_port[0] 49 port = target_ip_port[1] 50 self.ip = target_ip 51 self.ssh = self.ssh + ['-p', port] 52 self.scp = self.scp + ['-P', port] 53 else: 54 self.logger.error("Could not get host machine port to connect qemu with slirp, ssh will not be " 55 "able to connect to qemu with slirp") 56 if self.runner.server_ip: 57 self.server_ip = self.runner.server_ip 58 else: 59 self.stop() 60 raise RuntimeError("FAILED to start qemu - check the task log and the boot log") 61 62 def stop(self): 63 self.runner.stop() 64