diff options
author | Mariano Lopez <mariano.lopez@linux.intel.com> | 2015-08-24 19:04:02 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-08-30 12:36:12 +0100 |
commit | 85fd1a7a121daffc3c5c530930f832ecc61ef83d (patch) | |
tree | ee70ad65c0392775d8a4da174bd992e8e760c2e9 | |
parent | d14ffaf6a366442bcf88e44ee3e105f9dea1e69c (diff) | |
download | poky-85fd1a7a121daffc3c5c530930f832ecc61ef83d.tar.gz |
dump: Created new classes for dump host and target
It makes sense to separate the dump commands from the
oeRuntimeTest class, this way it can be used in all
the test context.
These are the changes included in this patch:
- Created classes: BaseDumper, HostDumper, TargetDumper
- Create an instance of HostDumper in imagetest.bbclass
and add it to TestContext class, this way any class
that have access to the TestContext would be able
to dump logs from the host
- Create an instance of TargetDumper in QemuTarget
class after get the runner, this way it is
accessible during the tests.
[YOCTO #8118]
(From OE-Core rev: ad10af6be343b5425fde43055263b0744c161cb3)
Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/testimage.bbclass | 5 | ||||
-rw-r--r-- | meta/lib/oeqa/oetest.py | 52 | ||||
-rw-r--r-- | meta/lib/oeqa/targetcontrol.py | 6 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/dump.py | 77 |
4 files changed, 91 insertions, 49 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass index 1d9464f5e9..824b47f5dd 100644 --- a/meta/classes/testimage.bbclass +++ b/meta/classes/testimage.bbclass | |||
@@ -231,6 +231,7 @@ def testimage_main(d): | |||
231 | import time | 231 | import time |
232 | from oeqa.oetest import loadTests, runTests | 232 | from oeqa.oetest import loadTests, runTests |
233 | from oeqa.targetcontrol import get_target_controller | 233 | from oeqa.targetcontrol import get_target_controller |
234 | from oeqa.utils.dump import get_host_dumper | ||
234 | 235 | ||
235 | pn = d.getVar("PN", True) | 236 | pn = d.getVar("PN", True) |
236 | export = oe.utils.conditional("TEST_EXPORT_ONLY", "1", True, False, d) | 237 | export = oe.utils.conditional("TEST_EXPORT_ONLY", "1", True, False, d) |
@@ -245,6 +246,9 @@ def testimage_main(d): | |||
245 | testslist = get_tests_list(d) | 246 | testslist = get_tests_list(d) |
246 | testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] | 247 | testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] |
247 | 248 | ||
249 | # we need the host dumper in test context | ||
250 | host_dumper = get_host_dumper(d) | ||
251 | |||
248 | # the robot dance | 252 | # the robot dance |
249 | target = get_target_controller(d) | 253 | target = get_target_controller(d) |
250 | 254 | ||
@@ -255,6 +259,7 @@ def testimage_main(d): | |||
255 | self.testsrequired = testsrequired | 259 | self.testsrequired = testsrequired |
256 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") | 260 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") |
257 | self.target = target | 261 | self.target = target |
262 | self.host_dumper = host_dumper | ||
258 | self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() | 263 | self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() |
259 | self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() | 264 | self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() |
260 | manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + ".manifest") | 265 | manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + ".manifest") |
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index fbf6c56376..9cb8a53795 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py | |||
@@ -11,8 +11,6 @@ import os, re, mmap | |||
11 | import unittest | 11 | import unittest |
12 | import inspect | 12 | import inspect |
13 | import subprocess | 13 | import subprocess |
14 | import datetime | ||
15 | import commands | ||
16 | import bb | 14 | import bb |
17 | from oeqa.utils.decorators import LogResults | 15 | from oeqa.utils.decorators import LogResults |
18 | from sys import exc_info, exc_clear | 16 | from sys import exc_info, exc_clear |
@@ -124,51 +122,13 @@ class oeRuntimeTest(oeTest): | |||
124 | # If a test fails or there is an exception | 122 | # If a test fails or there is an exception |
125 | if not exc_info() == (None, None, None): | 123 | if not exc_info() == (None, None, None): |
126 | exc_clear() | 124 | exc_clear() |
127 | dump_dir = self.create_dump_dir() | 125 | self.tc.host_dumper.create_dir(self._testMethodName) |
126 | self.target.target_dumper.dump_target( | ||
127 | self.tc.host_dumper.dump_dir) | ||
128 | self.tc.host_dumper.dump_host() | ||
128 | print ("%s dump data from host and target " | 129 | print ("%s dump data from host and target " |
129 | "stored in %s" % (self._testMethodName, dump_dir)) | 130 | "stored in %s" % (self._testMethodName, |
130 | self.dump_host_logs(dump_dir) | 131 | self.target.target_dumper.dump_dir)) |
131 | self.dump_target_logs(dump_dir) | ||
132 | |||
133 | def create_dump_dir(self): | ||
134 | dump_sub_dir = ("%s_%s" % ( | ||
135 | datetime.datetime.now().strftime('%Y%m%d%H%M'), | ||
136 | self._testMethodName)) | ||
137 | dump_dir = os.path.join(self.target.dump_dir, dump_sub_dir) | ||
138 | os.makedirs(dump_dir) | ||
139 | return dump_dir | ||
140 | |||
141 | def dump_host_logs(self, dump_dir): | ||
142 | for cmd in self.target.dump_host.split('\n'): | ||
143 | cmd = cmd.lstrip() | ||
144 | if not cmd: | ||
145 | continue | ||
146 | output = commands.getoutput(cmd) | ||
147 | filename = "host_%s" % cmd.split()[0] | ||
148 | with open(os.path.join(dump_dir, filename), 'w') as f: | ||
149 | f.write(output) | ||
150 | |||
151 | def dump_target_logs(self, dump_dir): | ||
152 | for cmd in self.target.dump_target.split('\n'): | ||
153 | cmd = cmd.lstrip() | ||
154 | if not cmd: | ||
155 | continue | ||
156 | # This will ping the host from target | ||
157 | if cmd == "_ping": | ||
158 | comm = "ping -c3 %s" % self.target.server_ip | ||
159 | # This will get all the logs from /var/log/ | ||
160 | elif cmd == "_logs": | ||
161 | comm = 'find /var/log/ -type f 2>/dev/null ' | ||
162 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) | ||
163 | comm = '%s-exec echo {} \\; ' % comm | ||
164 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) | ||
165 | comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm | ||
166 | else: | ||
167 | comm = cmd | ||
168 | (status, output) = self.target.run_serial(comm) | ||
169 | filename = "target_%s" % cmd.split()[0] | ||
170 | with open(os.path.join(dump_dir, filename), 'w') as f: | ||
171 | f.write(output) | ||
172 | 132 | ||
173 | #TODO: use package_manager.py to install packages on any type of image | 133 | #TODO: use package_manager.py to install packages on any type of image |
174 | def install_packages(self, packagelist): | 134 | def install_packages(self, packagelist): |
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py index 59cae2eff1..2d58f17ddb 100644 --- a/meta/lib/oeqa/targetcontrol.py +++ b/meta/lib/oeqa/targetcontrol.py | |||
@@ -14,6 +14,7 @@ import logging | |||
14 | from oeqa.utils.sshcontrol import SSHControl | 14 | from oeqa.utils.sshcontrol import SSHControl |
15 | from oeqa.utils.qemurunner import QemuRunner | 15 | from oeqa.utils.qemurunner import QemuRunner |
16 | from oeqa.utils.qemutinyrunner import QemuTinyRunner | 16 | from oeqa.utils.qemutinyrunner import QemuTinyRunner |
17 | from oeqa.utils.dump import TargetDumper | ||
17 | from oeqa.controllers.testtargetloader import TestTargetLoader | 18 | from oeqa.controllers.testtargetloader import TestTargetLoader |
18 | from abc import ABCMeta, abstractmethod | 19 | from abc import ABCMeta, abstractmethod |
19 | 20 | ||
@@ -123,9 +124,6 @@ class QemuTarget(BaseTarget): | |||
123 | self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype) | 124 | self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype) |
124 | self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype) | 125 | self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype) |
125 | self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin') | 126 | self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin') |
126 | self.dump_target = d.getVar("testimage_dump_target", True) | ||
127 | self.dump_host = d.getVar("testimage_dump_host", True) | ||
128 | self.dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", True) | ||
129 | 127 | ||
130 | # Log QemuRunner log output to a file | 128 | # Log QemuRunner log output to a file |
131 | import oe.path | 129 | import oe.path |
@@ -155,6 +153,8 @@ class QemuTarget(BaseTarget): | |||
155 | logfile = self.qemulog, | 153 | logfile = self.qemulog, |
156 | boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True))) | 154 | boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True))) |
157 | 155 | ||
156 | self.target_dumper = TargetDumper(d, self.runner) | ||
157 | |||
158 | def deploy(self): | 158 | def deploy(self): |
159 | try: | 159 | try: |
160 | bb.utils.mkdirhier(self.testdir) | 160 | bb.utils.mkdirhier(self.testdir) |
diff --git a/meta/lib/oeqa/utils/dump.py b/meta/lib/oeqa/utils/dump.py new file mode 100644 index 0000000000..a0fa699a27 --- /dev/null +++ b/meta/lib/oeqa/utils/dump.py | |||
@@ -0,0 +1,77 @@ | |||
1 | import os | ||
2 | import sys | ||
3 | import errno | ||
4 | import datetime | ||
5 | import itertools | ||
6 | from commands import runCmd | ||
7 | |||
8 | def get_host_dumper(d): | ||
9 | return HostDumper(d) | ||
10 | |||
11 | |||
12 | class BaseDumper(object): | ||
13 | |||
14 | def __init__(self, d): | ||
15 | self.parent_dir = d.getVar("TESTIMAGE_DUMP_DIR", True) | ||
16 | |||
17 | def create_dir(self, dir_suffix): | ||
18 | dump_subdir = ("%s_%s" % ( | ||
19 | datetime.datetime.now().strftime('%Y%m%d%H%M'), | ||
20 | dir_suffix)) | ||
21 | dump_dir = os.path.join(self.parent_dir, dump_subdir) | ||
22 | try: | ||
23 | os.makedirs(dump_dir) | ||
24 | except OSError as err: | ||
25 | if err.errno != errno.EEXIST: | ||
26 | raise err | ||
27 | self.dump_dir = dump_dir | ||
28 | |||
29 | def write_dump(self, command, output): | ||
30 | if isinstance(self, HostDumper): | ||
31 | prefix = "host" | ||
32 | elif isinstance(self, TargetDumper): | ||
33 | prefix = "target" | ||
34 | else: | ||
35 | prefix = "unknown" | ||
36 | for i in itertools.count(): | ||
37 | filename = "%s_%02d_%s" % (prefix, i, command) | ||
38 | fullname = os.path.join(self.dump_dir, filename) | ||
39 | if not os.path.exists(fullname): | ||
40 | break | ||
41 | with open(fullname, 'w') as dump_file: | ||
42 | dump_file.write(output) | ||
43 | |||
44 | |||
45 | class HostDumper(BaseDumper): | ||
46 | |||
47 | def __init__(self, d): | ||
48 | super(HostDumper, self).__init__(d) | ||
49 | self.host_cmds = d.getVar("testimage_dump_host", True) | ||
50 | |||
51 | def dump_host(self, dump_dir=""): | ||
52 | if dump_dir: | ||
53 | self.dump_dir = dump_dir | ||
54 | for cmd in self.host_cmds.split('\n'): | ||
55 | cmd = cmd.lstrip() | ||
56 | if not cmd or cmd[0] == '#': | ||
57 | continue | ||
58 | result = runCmd(cmd, ignore_status=True) | ||
59 | self.write_dump(cmd.split()[0], result.output) | ||
60 | |||
61 | |||
62 | class TargetDumper(BaseDumper): | ||
63 | |||
64 | def __init__(self, d, qemurunner): | ||
65 | super(TargetDumper, self).__init__(d) | ||
66 | self.target_cmds = d.getVar("testimage_dump_target", True) | ||
67 | self.runner = qemurunner | ||
68 | |||
69 | def dump_target(self, dump_dir=""): | ||
70 | if dump_dir: | ||
71 | self.dump_dir = dump_dir | ||
72 | for cmd in self.target_cmds.split('\n'): | ||
73 | cmd = cmd.lstrip() | ||
74 | if not cmd or cmd[0] == '#': | ||
75 | continue | ||
76 | (status, output) = self.runner.run_serial(cmd) | ||
77 | self.write_dump(cmd.split()[0], output) | ||