blob: 081c627b017424b4f616fec61bd353fe3c5fe3fb [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05006
7import os
8import sys
9import signal
10import time
11
12from .ssh import OESSHTarget
13from oeqa.utils.qemurunner import QemuRunner
14
Brad Bishop316dfdd2018-06-25 12:45:53 -040015supported_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016
17class OEQemuTarget(OESSHTarget):
Brad Bishop977dc1a2019-02-06 16:01:43 -050018 def __init__(self, logger, server_ip, timeout=300, user='root',
Brad Bishop19323692019-04-05 15:28:33 -040019 port=None, machine='', rootfs='', kernel='', kvm=False, slirp=False,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020 dump_dir='', dump_host_cmds='', display='', bootlog='',
21 tmpdir='', dir_image='', boottime=60, **kwargs):
22
Brad Bishop977dc1a2019-02-06 16:01:43 -050023 super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024 user, port)
25
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026 self.server_ip = server_ip
27 self.machine = machine
28 self.rootfs = rootfs
29 self.kernel = kernel
30 self.kvm = kvm
Brad Bishop19323692019-04-05 15:28:33 -040031 self.use_slirp = slirp
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032
33 self.runner = QemuRunner(machine=machine, rootfs=rootfs, tmpdir=tmpdir,
34 deploy_dir_image=dir_image, display=display,
35 logfile=bootlog, boottime=boottime,
Brad Bishop19323692019-04-05 15:28:33 -040036 use_kvm=kvm, use_slirp=slirp, dump_dir=dump_dir,
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037 dump_host_cmds=dump_host_cmds, logger=logger)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038
Brad Bishop19323692019-04-05 15:28:33 -040039 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):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 self.ip = self.runner.ip
Brad Bishop19323692019-04-05 15:28:33 -040045 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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058 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()