blob: 7a161a32319162b8241f94c1465d9abae5e6da18 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001# Copyright (C) 2016 Intel Corporation
2# Released under the MIT license (see COPYING.MIT)
3
4import os
5import sys
6import signal
7import time
8
9from .ssh import OESSHTarget
10from oeqa.utils.qemurunner import QemuRunner
11
Brad Bishop316dfdd2018-06-25 12:45:53 -040012supported_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013
14class OEQemuTarget(OESSHTarget):
Brad Bishop977dc1a2019-02-06 16:01:43 -050015 def __init__(self, logger, server_ip, timeout=300, user='root',
Brad Bishop19323692019-04-05 15:28:33 -040016 port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017 dump_dir='', dump_host_cmds='', display='', bootlog='',
18 tmpdir='', dir_image='', boottime=60, **kwargs):
19
Brad Bishop977dc1a2019-02-06 16:01:43 -050020 super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021 user, port)
22
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 self.server_ip = server_ip
24 self.machine = machine
25 self.rootfs = rootfs
26 self.kernel = kernel
27 self.kvm = kvm
Brad Bishop19323692019-04-05 15:28:33 -040028 self.use_slirp = slirp
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029
30 self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
31 deploy_dir_image=dir_image, display=display,
32 logfile=bootlog, boottime=boottime,
Brad Bishop19323692019-04-05 15:28:33 -040033 use_kvm=kvm, use_slirp=slirp, dump_dir=dump_dir,
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034 dump_host_cmds=dump_host_cmds, logger=logger)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035
Brad Bishop19323692019-04-05 15:28:33 -040036 def start(self, params=None, extra_bootparams=None, runqemuparams=''):
37 if self.use_slirp and not self.server_ip:
38 self.logger.error("Could not start qemu with slirp without server ip - provide 'TEST_SERVER_IP'")
39 raise RuntimeError("FAILED to start qemu - check the task log and the boot log")
40 if self.runner.start(params, extra_bootparams=extra_bootparams, runqemuparams=runqemuparams):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041 self.ip = self.runner.ip
Brad Bishop19323692019-04-05 15:28:33 -040042 if self.use_slirp:
43 target_ip_port = self.runner.ip.split(':')
44 if len(target_ip_port) == 2:
45 target_ip = target_ip_port[0]
46 port = target_ip_port[1]
47 self.ip = target_ip
48 self.ssh = self.ssh + ['-p', port]
49 self.scp = self.scp + ['-P', port]
50 else:
51 self.logger.error("Could not get host machine port to connect qemu with slirp, ssh will not be "
52 "able to connect to qemu with slirp")
53 if self.runner.server_ip:
54 self.server_ip = self.runner.server_ip
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055 else:
56 self.stop()
57 raise RuntimeError("FAILED to start qemu - check the task log and the boot log")
58
59 def stop(self):
60 self.runner.stop()