diff options
Diffstat (limited to 'meta/lib/oeqa/oetest.py')
-rw-r--r-- | meta/lib/oeqa/oetest.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index 22d76b35e1..a3f297acf6 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py | |||
@@ -11,6 +11,7 @@ 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 | ||
14 | import bb | 15 | import bb |
15 | from oeqa.utils.decorators import LogResults | 16 | from oeqa.utils.decorators import LogResults |
16 | 17 | ||
@@ -117,6 +118,42 @@ class oeRuntimeTest(oeTest): | |||
117 | self.target = oeRuntimeTest.tc.target | 118 | self.target = oeRuntimeTest.tc.target |
118 | super(oeRuntimeTest, self).__init__(methodName) | 119 | super(oeRuntimeTest, self).__init__(methodName) |
119 | 120 | ||
121 | def tearDown(self): | ||
122 | # If a test fails or there is an exception | ||
123 | if (self._resultForDoCleanups.failures or | ||
124 | self._resultForDoCleanups.errors): | ||
125 | commands = ["top -bn1", "ps", "free", "df", "_ping", "dmesg", "netstat -a", "ifconfig -a", "_logs"] | ||
126 | dump_dir = "/tmp/oe-saved-tests" | ||
127 | dump_dir = os.path.join(dump_dir, | ||
128 | datetime.datetime.now().strftime('%Y%m%d%H%M')) | ||
129 | os.makedirs(dump_dir) | ||
130 | bb.warn("Test failed, getting data from target " | ||
131 | "and saving it in %s" % dump_dir) | ||
132 | output = self.run_bulk_commands(commands) | ||
133 | for key,msg in output.iteritems(): | ||
134 | filename = key.split()[0] | ||
135 | with open(os.path.join(dump_dir, filename), 'w') as f: | ||
136 | f.write(msg) | ||
137 | |||
138 | def run_bulk_commands(self, commands): | ||
139 | all_output = {} | ||
140 | for command in commands: | ||
141 | # This will ping the host from target | ||
142 | if command == "_ping": | ||
143 | comm = "ping -c3 %s" % self.target.server_ip | ||
144 | # This will get all the logs from /var/log/ | ||
145 | elif command == "_logs": | ||
146 | comm = 'find /var/log/ -type f 2>/dev/null ' | ||
147 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) | ||
148 | comm = '%s-exec echo {} \\; ' % comm | ||
149 | comm = '%s-exec echo "%s" \\; ' % (comm, '='*20) | ||
150 | comm = '%s-exec cat {} \\; -exec echo "" \\;' % comm | ||
151 | else: | ||
152 | comm = command | ||
153 | (status, output) = self.target.run_serial(comm) | ||
154 | all_output[command] = output | ||
155 | return all_output | ||
156 | |||
120 | #TODO: use package_manager.py to install packages on any type of image | 157 | #TODO: use package_manager.py to install packages on any type of image |
121 | def install_packages(self, packagelist): | 158 | def install_packages(self, packagelist): |
122 | for package in packagelist: | 159 | for package in packagelist: |