summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/targetcontrol.py137
1 files changed, 137 insertions, 0 deletions
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
new file mode 100644
index 0000000000..dee38ec1d6
--- /dev/null
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -0,0 +1,137 @@
1# Copyright (C) 2013 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
5# This module is used by testimage.bbclass for setting up and controlling a target machine.
6
7import os
8import shutil
9import subprocess
10import bb
11
12from oeqa.utils.sshcontrol import SSHControl
13from oeqa.utils.qemurunner import QemuRunner
14
15
16def get_target_controller(d):
17 if d.getVar("TEST_TARGET", True) == "qemu":
18 return QemuTarget(d)
19 elif d.getVar("TEST_TARGET", True) == "simpleremote":
20 return SimpleRemoteTarget(d)
21 else:
22 bb.fatal("Please set a valid TEST_TARGET")
23
24
25class BaseTarget(object):
26
27 def __init__(self, d):
28 self.connection = None
29 self.ip = None
30 self.server_ip = None
31 self.datetime = d.getVar('DATETIME', True)
32 self.testdir = d.getVar("TEST_LOG_DIR", True)
33 self.pn = d.getVar("PN", True)
34
35 def deploy(self):
36
37 self.sshlog = os.path.join(self.testdir, "ssh_target_log.%s" % self.datetime)
38 sshloglink = os.path.join(self.testdir, "ssh_target_log")
39 if os.path.islink(sshloglink):
40 os.unlink(sshloglink)
41 os.symlink(self.sshlog, sshloglink)
42 bb.note("SSH log file: %s" % self.sshlog)
43
44 def run(self, cmd, timeout=None):
45 return self.connection.run(cmd, timeout)
46
47 def copy_to(self, localpath, remotepath):
48 return self.connection.copy_to(localpath, remotepath)
49
50 def copy_from(self, remotepath, localpath):
51 return self.connection.copy_from(remotepath, localpath)
52
53
54
55class QemuTarget(BaseTarget):
56
57 def __init__(self, d):
58
59 super(QemuTarget, self).__init__(d)
60
61 self.qemulog = os.path.join(self.testdir, "qemu_boot_log.%s" % self.datetime)
62 self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.ext3')
63 self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.ext3')
64
65 self.runner = QemuRunner(machine=d.getVar("MACHINE", True),
66 rootfs=self.rootfs,
67 tmpdir = d.getVar("TMPDIR", True),
68 deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
69 display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
70 logfile = self.qemulog,
71 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)))
72
73 def deploy(self):
74 try:
75 shutil.copyfile(self.origrootfs, self.rootfs)
76 except Exception as e:
77 bb.fatal("Error copying rootfs: %s" % e)
78
79 qemuloglink = os.path.join(self.testdir, "qemu_boot_log")
80 if os.path.islink(qemuloglink):
81 os.unlink(qemuloglink)
82 os.symlink(self.qemulog, qemuloglink)
83
84 bb.note("rootfs file: %s" % self.rootfs)
85 bb.note("Qemu log file: %s" % self.qemulog)
86 super(QemuTarget, self).deploy()
87
88 def start(self, params=None):
89 if self.runner.start(params):
90 self.ip = self.runner.ip
91 self.server_ip = self.runner.server_ip
92 self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
93 else:
94 raise bb.build.FuncFailed("%s - FAILED to start qemu - check the task log and the boot log" % self.pn)
95
96 def stop(self):
97 self.runner.stop()
98 self.connection = None
99 self.ip = None
100 self.server_ip = None
101
102 def restart(self, params=None):
103 if self.runner.restart(params):
104 self.ip = self.runner.ip
105 self.server_ip = self.runner.server_ip
106 self.connection = SSHControl(ip=self.ip, logfile=self.sshlog)
107 else:
108 raise bb.build.FuncFailed("%s - FAILED to re-start qemu - check the task log and the boot log" % self.pn)
109
110
111class SimpleRemoteTarget(BaseTarget):
112
113 def __init__(self, d):
114 super(SimpleRemoteTarget, self).__init__(d)
115 self.ip = d.getVar("TEST_TARGET_IP", True) or bb.fatal('Please set TEST_TARGET_IP with the IP address of the machine you want to run the tests on.')
116 bb.note("Target IP: %s" % self.ip)
117 self.server_ip = d.getVar("TEST_SERVER_IP", True)
118 if not self.server_ip:
119 try:
120 self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split()[6]
121 except Exception as e:
122 bb.fatal("Failed to determine the host IP address (alternatively you can set TEST_SERVER_IP with the IP address of this machine): %s" % e)
123 bb.note("Server IP: %s" % self.server_ip)
124
125 def deploy(self):
126 super(SimpleRemoteTarget, self).deploy()
127
128 def start(self, params=None):
129 self.connection = SSHControl(self.ip, logfile=self.sshlog)
130
131 def stop(self):
132 self.connection = None
133 self.ip = None
134 self.server_ip = None
135
136 def restart(self, params=None):
137 pass