mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 1 | """The main job wrapper |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 2 | |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 3 | This is the core infrastructure. |
| 4 | """ |
| 5 | |
| 6 | __author__ = """Copyright Andy Whitcroft, Martin J. Bligh 2006""" |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 7 | |
mbligh | 8f243ec | 2006-10-10 05:55:49 +0000 | [diff] [blame] | 8 | # standard stuff |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 9 | import os, sys, re, pickle, shutil, time, traceback |
mbligh | 8f243ec | 2006-10-10 05:55:49 +0000 | [diff] [blame] | 10 | # autotest stuff |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 11 | from autotest_utils import * |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 12 | from parallel import * |
mbligh | f31b0c0 | 2007-11-29 18:19:22 +0000 | [diff] [blame] | 13 | from common.error import * |
mbligh | 65938a2 | 2007-12-10 16:58:52 +0000 | [diff] [blame^] | 14 | from common import barrier |
mbligh | e1417fa | 2007-12-10 16:55:13 +0000 | [diff] [blame] | 15 | import kernel, xen, test, profilers, filesystem, fd_stack, boottool |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 16 | import harness, config |
mbligh | 83ac994 | 2007-11-05 18:59:37 +0000 | [diff] [blame] | 17 | import sysinfo |
mbligh | 65938a2 | 2007-12-10 16:58:52 +0000 | [diff] [blame^] | 18 | import cpuset |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 19 | |
| 20 | class job: |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 21 | """The actual job against which we do everything. |
| 22 | |
| 23 | Properties: |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 24 | autodir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 25 | The top level autotest directory (/usr/local/autotest). |
| 26 | Comes from os.environ['AUTODIR']. |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 27 | bindir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 28 | <autodir>/bin/ |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 29 | testdir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 30 | <autodir>/tests/ |
| 31 | profdir |
| 32 | <autodir>/profilers/ |
| 33 | tmpdir |
| 34 | <autodir>/tmp/ |
| 35 | resultdir |
| 36 | <autodir>/results/<jobtag> |
| 37 | stdout |
| 38 | fd_stack object for stdout |
| 39 | stderr |
| 40 | fd_stack object for stderr |
| 41 | profilers |
| 42 | the profilers object for this job |
apw | 504a7dd | 2006-10-12 17:18:37 +0000 | [diff] [blame] | 43 | harness |
| 44 | the server harness object for this job |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 45 | config |
| 46 | the job configuration for this job |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 47 | """ |
| 48 | |
mbligh | 362ab3d | 2007-08-30 11:24:04 +0000 | [diff] [blame] | 49 | def __init__(self, control, jobtag, cont, harness_type=None): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 50 | """ |
| 51 | control |
| 52 | The control file (pathname of) |
| 53 | jobtag |
| 54 | The job tag string (eg "default") |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 55 | cont |
| 56 | If this is the continuation of this job |
apw | e68a713 | 2006-12-01 11:21:37 +0000 | [diff] [blame] | 57 | harness_type |
| 58 | An alternative server harness |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 59 | """ |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 60 | self.autodir = os.environ['AUTODIR'] |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 61 | self.bindir = os.path.join(self.autodir, 'bin') |
| 62 | self.testdir = os.path.join(self.autodir, 'tests') |
| 63 | self.profdir = os.path.join(self.autodir, 'profilers') |
| 64 | self.tmpdir = os.path.join(self.autodir, 'tmp') |
| 65 | self.resultdir = os.path.join(self.autodir, 'results', jobtag) |
mbligh | 8d83cdc | 2007-12-03 18:09:18 +0000 | [diff] [blame] | 66 | self.control = os.path.abspath(control) |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 67 | |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 68 | if not cont: |
| 69 | if os.path.exists(self.tmpdir): |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 70 | system('umount -f %s > /dev/null 2> /dev/null'%\ |
| 71 | self.tmpdir, ignorestatus=True) |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 72 | system('rm -rf ' + self.tmpdir) |
| 73 | os.mkdir(self.tmpdir) |
| 74 | |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 75 | results = os.path.join(self.autodir, 'results') |
| 76 | if not os.path.exists(results): |
| 77 | os.mkdir(results) |
mbligh | fbfb77d | 2007-02-15 18:54:03 +0000 | [diff] [blame] | 78 | |
apw | f3d2862 | 2007-09-25 16:49:17 +0000 | [diff] [blame] | 79 | download = os.path.join(self.testdir, 'download') |
| 80 | if os.path.exists(download): |
| 81 | system('rm -rf ' + download) |
| 82 | os.mkdir(download) |
| 83 | |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 84 | if os.path.exists(self.resultdir): |
| 85 | system('rm -rf ' + self.resultdir) |
| 86 | os.mkdir(self.resultdir) |
| 87 | |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 88 | os.mkdir(os.path.join(self.resultdir, 'debug')) |
| 89 | os.mkdir(os.path.join(self.resultdir, 'analysis')) |
| 90 | os.mkdir(os.path.join(self.resultdir, 'sysinfo')) |
| 91 | |
mbligh | 8d83cdc | 2007-12-03 18:09:18 +0000 | [diff] [blame] | 92 | shutil.copyfile(self.control, |
| 93 | os.path.join(self.resultdir, 'control')) |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 94 | |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 95 | self.control = control |
mbligh | 2711360 | 2007-10-31 21:07:51 +0000 | [diff] [blame] | 96 | self.jobtag = jobtag |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 97 | |
mbligh | 56f1fbb | 2006-10-01 15:10:56 +0000 | [diff] [blame] | 98 | self.stdout = fd_stack.fd_stack(1, sys.stdout) |
| 99 | self.stderr = fd_stack.fd_stack(2, sys.stderr) |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 100 | self.group_level = 0 |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 101 | |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 102 | self.config = config.config(self) |
| 103 | |
apw | d27e55f | 2006-12-01 11:22:08 +0000 | [diff] [blame] | 104 | self.harness = harness.select(harness_type, self) |
| 105 | |
mbligh | a35553b | 2006-04-23 15:52:25 +0000 | [diff] [blame] | 106 | self.profilers = profilers.profilers(self) |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 107 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 108 | try: |
apw | 90154af | 2006-12-01 11:23:36 +0000 | [diff] [blame] | 109 | tool = self.config_get('boottool.executable') |
| 110 | self.bootloader = boottool.boottool(tool) |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 111 | except: |
| 112 | pass |
| 113 | |
mbligh | 83ac994 | 2007-11-05 18:59:37 +0000 | [diff] [blame] | 114 | # log "before each step" sysinfo |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 115 | pwd = os.getcwd() |
mbligh | 83ac994 | 2007-11-05 18:59:37 +0000 | [diff] [blame] | 116 | try: |
| 117 | os.chdir(os.path.join(self.resultdir, 'sysinfo')) |
| 118 | sysinfo.before_each_step() |
| 119 | finally: |
| 120 | os.chdir(pwd) |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 121 | |
mbligh | 3027030 | 2007-11-05 20:33:52 +0000 | [diff] [blame] | 122 | if not cont: |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 123 | self.record('START', None, None) |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 124 | self.group_level = 1 |
apw | 357f50f | 2006-12-01 11:22:39 +0000 | [diff] [blame] | 125 | |
apw | f91efaf | 2007-11-24 17:32:13 +0000 | [diff] [blame] | 126 | self.harness.run_start() |
| 127 | |
mbligh | 0692e47 | 2007-08-30 16:07:53 +0000 | [diff] [blame] | 128 | |
| 129 | def relative_path(self, path): |
| 130 | """\ |
| 131 | Return a patch relative to the job results directory |
| 132 | """ |
mbligh | 1c250ca | 2007-08-30 16:31:38 +0000 | [diff] [blame] | 133 | head = len(self.resultdir) + 1 # remove the / inbetween |
| 134 | return path[head:] |
mbligh | 0692e47 | 2007-08-30 16:07:53 +0000 | [diff] [blame] | 135 | |
| 136 | |
mbligh | 362ab3d | 2007-08-30 11:24:04 +0000 | [diff] [blame] | 137 | def control_get(self): |
| 138 | return self.control |
| 139 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 140 | |
mbligh | 8d83cdc | 2007-12-03 18:09:18 +0000 | [diff] [blame] | 141 | def control_set(self, control): |
| 142 | self.control = os.path.abspath(control) |
| 143 | |
| 144 | |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 145 | def harness_select(self, which): |
| 146 | self.harness = harness.select(which, self) |
| 147 | |
| 148 | |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 149 | def config_set(self, name, value): |
| 150 | self.config.set(name, value) |
| 151 | |
| 152 | |
| 153 | def config_get(self, name): |
| 154 | return self.config.get(name) |
| 155 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 156 | def setup_dirs(self, results_dir, tmp_dir): |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 157 | if not tmp_dir: |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 158 | tmp_dir = os.path.join(self.tmpdir, 'build') |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 159 | if not os.path.exists(tmp_dir): |
| 160 | os.mkdir(tmp_dir) |
| 161 | if not os.path.isdir(tmp_dir): |
| 162 | raise "Temp dir (%s) is not a dir - args backwards?" \ |
| 163 | % self.tmpdir |
| 164 | |
| 165 | # We label the first build "build" and then subsequent ones |
| 166 | # as "build.2", "build.3", etc. Whilst this is a little bit |
| 167 | # inconsistent, 99.9% of jobs will only have one build |
| 168 | # (that's not done as kernbench, sparse, or buildtest), |
| 169 | # so it works out much cleaner. One of life's comprimises. |
| 170 | if not results_dir: |
| 171 | results_dir = os.path.join(self.resultdir, 'build') |
| 172 | i = 2 |
| 173 | while os.path.exists(results_dir): |
| 174 | results_dir = os.path.join(self.resultdir, 'build.%d' % i) |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 175 | i += 1 |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 176 | if not os.path.exists(results_dir): |
| 177 | os.mkdir(results_dir) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 178 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 179 | return (results_dir, tmp_dir) |
| 180 | |
| 181 | |
| 182 | def xen(self, base_tree, results_dir = '', tmp_dir = '', leave = False, \ |
| 183 | kjob = None ): |
| 184 | """Summon a xen object""" |
| 185 | (results_dir, tmp_dir) = self.setup_dirs(results_dir, tmp_dir) |
| 186 | build_dir = 'xen' |
| 187 | return xen.xen(self, base_tree, results_dir, tmp_dir, build_dir, leave, kjob) |
| 188 | |
| 189 | |
| 190 | def kernel(self, base_tree, results_dir = '', tmp_dir = '', leave = False): |
| 191 | """Summon a kernel object""" |
mbligh | 669caa1 | 2007-11-05 18:32:13 +0000 | [diff] [blame] | 192 | (results_dir, tmp_dir) = self.setup_dirs(results_dir, tmp_dir) |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 193 | build_dir = 'linux' |
mbligh | 6ee7ee0 | 2007-11-13 23:49:05 +0000 | [diff] [blame] | 194 | return kernel.auto_kernel(self, base_tree, results_dir, |
| 195 | tmp_dir, build_dir, leave) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 196 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 197 | |
mbligh | fadca20 | 2006-09-23 04:40:01 +0000 | [diff] [blame] | 198 | def barrier(self, *args): |
| 199 | """Create a barrier object""" |
| 200 | return barrier.barrier(*args) |
| 201 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 202 | |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 203 | def setup_dep(self, deps): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 204 | """Set up the dependencies for this test. |
| 205 | |
| 206 | deps is a list of libraries required for this test. |
| 207 | """ |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 208 | for dep in deps: |
| 209 | try: |
apw | 870988b | 2007-09-25 16:50:53 +0000 | [diff] [blame] | 210 | os.chdir(os.path.join(self.autodir, 'deps', dep)) |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 211 | system('./' + dep + '.py') |
| 212 | except: |
| 213 | error = "setting up dependency " + dep + "\n" |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 214 | raise UnhandledError(error) |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 215 | |
| 216 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 217 | def __runtest(self, url, tag, args, dargs): |
| 218 | try: |
mbligh | 53c4150 | 2007-10-23 20:45:04 +0000 | [diff] [blame] | 219 | l = lambda : test.runtest(self, url, tag, args, dargs) |
| 220 | pid = fork_start(self.resultdir, l) |
| 221 | fork_waitfor(self.resultdir, pid) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 222 | except AutotestError: |
| 223 | raise |
| 224 | except: |
| 225 | raise UnhandledError('running test ' + \ |
| 226 | self.__class__.__name__ + "\n") |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 227 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 228 | |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 229 | def run_test(self, url, *args, **dargs): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 230 | """Summon a test object and run it. |
| 231 | |
| 232 | tag |
| 233 | tag to add to testname |
mbligh | 12a7df7 | 2006-10-06 03:54:33 +0000 | [diff] [blame] | 234 | url |
| 235 | url of the test to run |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 236 | """ |
mbligh | 12a7df7 | 2006-10-06 03:54:33 +0000 | [diff] [blame] | 237 | |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 238 | if not url: |
| 239 | raise "Test name is invalid. Switched arguments?" |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 240 | (group, testname) = test.testname(url) |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 241 | tag = dargs.pop('tag', None) |
mbligh | 65938a2 | 2007-12-10 16:58:52 +0000 | [diff] [blame^] | 242 | self.container = None |
| 243 | container = dargs.pop('container', None) |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 244 | subdir = testname |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 245 | if tag: |
| 246 | subdir += '.' + tag |
| 247 | |
mbligh | 65938a2 | 2007-12-10 16:58:52 +0000 | [diff] [blame^] | 248 | if container: |
| 249 | container_name = container.pop('container_name', None) |
| 250 | cpu = container.get('cpu', None) |
| 251 | root_container = container.get('root', 'sys') |
| 252 | if not container_name: |
| 253 | container_name = testname |
| 254 | if not grep('cpusets', '/proc/filesystems'): |
| 255 | |
| 256 | self.container = cpuset.cpuset(container_name, |
| 257 | container['mem'], |
| 258 | os.getpid(), |
| 259 | root = root_container, |
| 260 | cpus = cpu) |
| 261 | # We are running in a container now... |
| 262 | |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 263 | def group_func(): |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 264 | try: |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 265 | self.__runtest(url, tag, args, dargs) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 266 | except Exception, detail: |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 267 | self.record('FAIL', subdir, testname, |
| 268 | str(detail)) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 269 | raise |
| 270 | else: |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 271 | self.record('GOOD', subdir, testname, |
| 272 | 'completed successfully') |
mbligh | cfc6dd3 | 2007-11-20 00:44:35 +0000 | [diff] [blame] | 273 | result, exc_info = self.__rungroup(subdir, group_func) |
mbligh | 65938a2 | 2007-12-10 16:58:52 +0000 | [diff] [blame^] | 274 | if self.container: |
| 275 | self.container.release() |
| 276 | self.container = None |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 277 | |
| 278 | if exc_info and isinstance(exc_info[1], TestError): |
| 279 | return False |
| 280 | elif exc_info: |
| 281 | raise exc_info[0], exc_info[1], exc_info[2] |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 282 | else: |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 283 | return True |
| 284 | |
| 285 | |
| 286 | def __rungroup(self, name, function, *args, **dargs): |
| 287 | """\ |
| 288 | name: |
| 289 | name of the group |
| 290 | function: |
| 291 | subroutine to run |
| 292 | *args: |
| 293 | arguments for the function |
| 294 | |
| 295 | Returns a 2-tuple (result, exc_info) where result |
| 296 | is the return value of function, and exc_info is |
| 297 | the sys.exc_info() of the exception thrown by the |
| 298 | function (which may be None). |
| 299 | """ |
| 300 | |
| 301 | result, exc_info = None, None |
| 302 | try: |
| 303 | self.record('START', None, name) |
| 304 | self.group_level += 1 |
| 305 | result = function(*args, **dargs) |
| 306 | self.group_level -= 1 |
| 307 | self.record('END GOOD', None, name) |
| 308 | except Exception, e: |
| 309 | exc_info = sys.exc_info() |
| 310 | self.group_level -= 1 |
mbligh | 51144e0 | 2007-11-20 20:38:18 +0000 | [diff] [blame] | 311 | err_msg = str(e) + '\n' + format_error() |
| 312 | self.record('END FAIL', None, name, err_msg) |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 313 | |
| 314 | return result, exc_info |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 315 | |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 316 | |
apw | 1da244b | 2007-09-27 17:18:01 +0000 | [diff] [blame] | 317 | def run_group(self, function, *args, **dargs): |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 318 | """\ |
| 319 | function: |
| 320 | subroutine to run |
| 321 | *args: |
| 322 | arguments for the function |
| 323 | """ |
| 324 | |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 325 | # Allow the tag for the group to be specified |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 326 | name = function.__name__ |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 327 | tag = dargs.pop('tag', None) |
| 328 | if tag: |
| 329 | name = tag |
apw | 1da244b | 2007-09-27 17:18:01 +0000 | [diff] [blame] | 330 | |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 331 | result, exc_info = self.__rungroup(name, function, |
| 332 | *args, **dargs) |
apw | 1da244b | 2007-09-27 17:18:01 +0000 | [diff] [blame] | 333 | |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 334 | # if there was a non-TestError exception, raise it |
| 335 | if exc_info and isinstance(exc_info[1], TestError): |
| 336 | err = ''.join(traceback.format_exception(*exc_info)) |
| 337 | raise TestError(name + ' failed\n' + err) |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 338 | |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 339 | # pass back the actual return value from the function |
apw | 08403ca | 2007-09-27 17:17:22 +0000 | [diff] [blame] | 340 | return result |
| 341 | |
mbligh | 88ab90f | 2007-08-29 15:52:49 +0000 | [diff] [blame] | 342 | |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 343 | # Check the passed kernel identifier against the command line |
| 344 | # and the running kernel, abort the job on missmatch. |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 345 | def kernel_check_ident(self, expected_when, expected_id, expected_cl, subdir, type = 'src'): |
| 346 | print "POST BOOT: checking booted kernel mark=%d identity='%s' changelist=%s type='%s'" \ |
| 347 | % (expected_when, expected_id, expected_cl, type) |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 348 | |
| 349 | running_id = running_os_ident() |
| 350 | |
| 351 | cmdline = read_one_line("/proc/cmdline") |
| 352 | |
| 353 | find_sum = re.compile(r'.*IDENT=(\d+)') |
| 354 | m = find_sum.match(cmdline) |
| 355 | cmdline_when = -1 |
| 356 | if m: |
| 357 | cmdline_when = int(m.groups()[0]) |
| 358 | |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 359 | cl_re = re.compile(r'\d{7,}') |
| 360 | cl_match = cl_re.search(system_output('uname -v').split()[1]) |
| 361 | if cl_match: |
| 362 | current_cl = cl_match.group() |
| 363 | else: |
| 364 | current_cl = None |
| 365 | |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 366 | # We have all the facts, see if they indicate we |
| 367 | # booted the requested kernel or not. |
| 368 | bad = False |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 369 | if (type == 'src' and expected_id != running_id or |
| 370 | type == 'rpm' and not running_id.startswith(expected_id + '::')): |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 371 | print "check_kernel_ident: kernel identifier mismatch" |
| 372 | bad = True |
| 373 | if expected_when != cmdline_when: |
| 374 | print "check_kernel_ident: kernel command line mismatch" |
| 375 | bad = True |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 376 | if expected_cl and current_cl and str(expected_cl) != current_cl: |
| 377 | print 'check_kernel_ident: kernel changelist mismatch' |
| 378 | bad = True |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 379 | |
| 380 | if bad: |
| 381 | print " Expected Ident: " + expected_id |
| 382 | print " Running Ident: " + running_id |
| 383 | print " Expected Mark: %d" % (expected_when) |
| 384 | print "Command Line Mark: %d" % (cmdline_when) |
mbligh | da0311e | 2007-10-25 16:03:33 +0000 | [diff] [blame] | 385 | print " Expected P4 CL: %s" % expected_cl |
| 386 | print " P4 CL: %s" % current_cl |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 387 | print " Command Line: " + cmdline |
| 388 | |
mbligh | 3027030 | 2007-11-05 20:33:52 +0000 | [diff] [blame] | 389 | raise JobError("boot failure", "reboot.verify") |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 390 | |
mbligh | 3027030 | 2007-11-05 20:33:52 +0000 | [diff] [blame] | 391 | self.record('GOOD', subdir, 'reboot.verify') |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 392 | |
| 393 | |
mbligh | c235985 | 2007-08-28 18:11:48 +0000 | [diff] [blame] | 394 | def filesystem(self, device, mountpoint = None, loop_size = 0): |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 395 | if not mountpoint: |
| 396 | mountpoint = self.tmpdir |
mbligh | c235985 | 2007-08-28 18:11:48 +0000 | [diff] [blame] | 397 | return filesystem.filesystem(self, device, mountpoint,loop_size) |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 398 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 399 | |
| 400 | def reboot(self, tag='autotest'): |
mbligh | 3027030 | 2007-11-05 20:33:52 +0000 | [diff] [blame] | 401 | self.record('GOOD', None, 'reboot.start') |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 402 | self.harness.run_reboot() |
apw | 11985b7 | 2007-10-04 15:44:47 +0000 | [diff] [blame] | 403 | default = self.config_get('boot.set_default') |
| 404 | if default: |
| 405 | self.bootloader.set_default(tag) |
| 406 | else: |
| 407 | self.bootloader.boot_once(tag) |
mbligh | f3b7893 | 2007-11-07 16:52:47 +0000 | [diff] [blame] | 408 | system("(sleep 5; reboot) </dev/null >/dev/null 2>&1 &") |
apw | 0778a2f | 2006-10-06 03:11:40 +0000 | [diff] [blame] | 409 | self.quit() |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 410 | |
| 411 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 412 | def noop(self, text): |
| 413 | print "job: noop: " + text |
| 414 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 415 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 416 | # Job control primatives. |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 417 | |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 418 | def __parallel_execute(self, func, *args): |
| 419 | func(*args) |
| 420 | |
| 421 | |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 422 | def parallel(self, *tasklist): |
| 423 | """Run tasks in parallel""" |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 424 | |
| 425 | pids = [] |
| 426 | for task in tasklist: |
| 427 | pids.append(fork_start(self.resultdir, |
| 428 | lambda: self.__parallel_execute(*task))) |
| 429 | for pid in pids: |
| 430 | fork_waitfor(self.resultdir, pid) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 431 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 432 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 433 | def quit(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 434 | # XXX: should have a better name. |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 435 | self.harness.run_pause() |
apw | f2c6660 | 2006-04-27 14:11:25 +0000 | [diff] [blame] | 436 | raise JobContinue("more to come") |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 437 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 438 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 439 | def complete(self, status): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 440 | """Clean up and exit""" |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 441 | # We are about to exit 'complete' so clean up the control file. |
| 442 | try: |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 443 | os.unlink(self.control + '.state') |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 444 | except: |
| 445 | pass |
mbligh | 61a6c1a | 2006-12-25 01:26:38 +0000 | [diff] [blame] | 446 | self.harness.run_complete() |
apw | 1b02190 | 2006-04-03 17:02:56 +0000 | [diff] [blame] | 447 | sys.exit(status) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 448 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 449 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 450 | steps = [] |
| 451 | def next_step(self, step): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 452 | """Define the next step""" |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 453 | if not isinstance(step[0], basestring): |
| 454 | step[0] = step[0].__name__ |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 455 | self.steps.append(step) |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 456 | pickle.dump(self.steps, open(self.control + '.state', 'w')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 457 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 458 | |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 459 | def next_step_prepend(self, step): |
| 460 | """Insert a new step, executing first""" |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 461 | if not isinstance(step[0], basestring): |
| 462 | step[0] = step[0].__name__ |
mbligh | 237bed3 | 2007-09-05 13:05:57 +0000 | [diff] [blame] | 463 | self.steps.insert(0, step) |
| 464 | pickle.dump(self.steps, open(self.control + '.state', 'w')) |
| 465 | |
| 466 | |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 467 | def step_engine(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 468 | """the stepping engine -- if the control file defines |
| 469 | step_init we will be using this engine to drive multiple runs. |
| 470 | """ |
| 471 | """Do the next step""" |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 472 | lcl = dict({'job': self}) |
| 473 | |
| 474 | str = """ |
mbligh | f31b0c0 | 2007-11-29 18:19:22 +0000 | [diff] [blame] | 475 | from common.error import * |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 476 | from autotest_utils import * |
| 477 | """ |
| 478 | exec(str, lcl, lcl) |
| 479 | execfile(self.control, lcl, lcl) |
| 480 | |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 481 | state = self.control + '.state' |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 482 | # If there is a mid-job state file load that in and continue |
| 483 | # where it indicates. Otherwise start stepping at the passed |
| 484 | # entry. |
| 485 | try: |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 486 | self.steps = pickle.load(open(state, 'r')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 487 | except: |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 488 | if lcl.has_key('step_init'): |
| 489 | self.next_step([lcl['step_init']]) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 490 | |
| 491 | # Run the step list. |
| 492 | while len(self.steps) > 0: |
apw | fd922bb | 2006-04-04 07:47:00 +0000 | [diff] [blame] | 493 | step = self.steps.pop(0) |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 494 | pickle.dump(self.steps, open(state, 'w')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 495 | |
| 496 | cmd = step.pop(0) |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 497 | lcl['__args'] = step |
apw | ce73d89 | 2007-09-25 16:53:05 +0000 | [diff] [blame] | 498 | exec(cmd + "(*__args)", lcl, lcl) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 499 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 500 | |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 501 | def record(self, status_code, subdir, operation, status = ''): |
| 502 | """ |
| 503 | Record job-level status |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 504 | |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 505 | The intent is to make this file both machine parseable and |
| 506 | human readable. That involves a little more complexity, but |
| 507 | really isn't all that bad ;-) |
| 508 | |
| 509 | Format is <status code>\t<subdir>\t<operation>\t<status> |
| 510 | |
| 511 | status code: (GOOD|WARN|FAIL|ABORT) |
| 512 | or START |
| 513 | or END (GOOD|WARN|FAIL|ABORT) |
| 514 | |
| 515 | subdir: MUST be a relevant subdirectory in the results, |
| 516 | or None, which will be represented as '----' |
| 517 | |
| 518 | operation: description of what you ran (e.g. "dbench", or |
| 519 | "mkfs -t foobar /dev/sda9") |
| 520 | |
| 521 | status: error message or "completed sucessfully" |
| 522 | |
| 523 | ------------------------------------------------------------ |
| 524 | |
| 525 | Initial tabs indicate indent levels for grouping, and is |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 526 | governed by self.group_level |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 527 | |
| 528 | multiline messages have secondary lines prefaced by a double |
| 529 | space (' ') |
| 530 | """ |
| 531 | |
mbligh | b0570ad | 2007-09-19 18:18:11 +0000 | [diff] [blame] | 532 | if subdir: |
| 533 | if re.match(r'[\n\t]', subdir): |
| 534 | raise "Invalid character in subdir string" |
| 535 | substr = subdir |
| 536 | else: |
| 537 | substr = '----' |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 538 | |
| 539 | if not re.match(r'(START|(END )?(GOOD|WARN|FAIL|ABORT))$', \ |
| 540 | status_code): |
| 541 | raise "Invalid status code supplied: %s" % status_code |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame] | 542 | if not operation: |
| 543 | operation = '----' |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 544 | if re.match(r'[\n\t]', operation): |
| 545 | raise "Invalid character in operation string" |
| 546 | operation = operation.rstrip() |
| 547 | status = status.rstrip() |
| 548 | status = re.sub(r"\t", " ", status) |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 549 | # Ensure any continuation lines are marked so we can |
| 550 | # detect them in the status file to ensure it is parsable. |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 551 | status = re.sub(r"\n", "\n" + "\t" * self.group_level + " ", status) |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 552 | |
mbligh | 3027030 | 2007-11-05 20:33:52 +0000 | [diff] [blame] | 553 | # Generate timestamps for inclusion in the logs |
| 554 | epoch_time = int(time.time()) # seconds since epoch, in UTC |
| 555 | local_time = time.localtime(epoch_time) |
| 556 | epoch_time_str = "timestamp=%d" % (epoch_time,) |
| 557 | local_time_str = time.strftime("localtime=%b %d %H:%M:%S", |
| 558 | local_time) |
| 559 | |
| 560 | msg = '\t'.join(str(x) for x in (status_code, substr, operation, |
| 561 | epoch_time_str, local_time_str, |
| 562 | status)) |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 563 | msg = '\t' * self.group_level + msg |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 564 | |
apw | 4b2e4fb | 2007-09-25 16:52:30 +0000 | [diff] [blame] | 565 | self.harness.test_status_detail(status_code, substr, |
| 566 | operation, status) |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 567 | self.harness.test_status(msg) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 568 | print msg |
mbligh | 09f288a | 2007-09-18 21:34:57 +0000 | [diff] [blame] | 569 | status_file = os.path.join(self.resultdir, 'status') |
mbligh | 7dd510c | 2007-11-13 17:11:22 +0000 | [diff] [blame] | 570 | open(status_file, "a").write(msg + "\n") |
mbligh | b0570ad | 2007-09-19 18:18:11 +0000 | [diff] [blame] | 571 | if subdir: |
| 572 | status_file = os.path.join(self.resultdir, subdir, 'status') |
| 573 | open(status_file, "a").write(msg + "\n") |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 574 | |
| 575 | |
mbligh | 570e93e | 2006-11-26 05:15:56 +0000 | [diff] [blame] | 576 | def runjob(control, cont = False, tag = "default", harness_type = ''): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 577 | """The main interface to this module |
| 578 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 579 | control |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 580 | The control file to use for this job. |
| 581 | cont |
| 582 | Whether this is the continuation of a previously started job |
| 583 | """ |
mbligh | b4eef24 | 2007-07-23 18:22:49 +0000 | [diff] [blame] | 584 | control = os.path.abspath(control) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 585 | state = control + '.state' |
| 586 | |
| 587 | # instantiate the job object ready for the control file. |
| 588 | myjob = None |
| 589 | try: |
| 590 | # Check that the control file is valid |
| 591 | if not os.path.exists(control): |
| 592 | raise JobError(control + ": control file not found") |
| 593 | |
| 594 | # When continuing, the job is complete when there is no |
| 595 | # state file, ensure we don't try and continue. |
mbligh | f3fef46 | 2006-09-13 16:05:05 +0000 | [diff] [blame] | 596 | if cont and not os.path.exists(state): |
apw | b832e1b | 2007-11-24 20:24:38 +0000 | [diff] [blame] | 597 | raise JobComplete("all done") |
mbligh | f3fef46 | 2006-09-13 16:05:05 +0000 | [diff] [blame] | 598 | if cont == False and os.path.exists(state): |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 599 | os.unlink(state) |
| 600 | |
mbligh | 570e93e | 2006-11-26 05:15:56 +0000 | [diff] [blame] | 601 | myjob = job(control, tag, cont, harness_type) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 602 | |
| 603 | # Load in the users control file, may do any one of: |
| 604 | # 1) execute in toto |
| 605 | # 2) define steps, and select the first via next_step() |
| 606 | myjob.step_engine() |
| 607 | |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 608 | except JobContinue: |
| 609 | sys.exit(5) |
| 610 | |
apw | b832e1b | 2007-11-24 20:24:38 +0000 | [diff] [blame] | 611 | except JobComplete: |
| 612 | sys.exit(1) |
| 613 | |
mbligh | 4768171 | 2007-11-16 21:41:51 +0000 | [diff] [blame] | 614 | except JobError, instance: |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 615 | print "JOB ERROR: " + instance.args[0] |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame] | 616 | if myjob: |
mbligh | 3027030 | 2007-11-05 20:33:52 +0000 | [diff] [blame] | 617 | command = None |
| 618 | if len(instance.args) > 1: |
| 619 | command = instance.args[1] |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 620 | myjob.group_level = 0 |
mbligh | 3027030 | 2007-11-05 20:33:52 +0000 | [diff] [blame] | 621 | myjob.record('ABORT', None, command, instance.args[0]) |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 622 | myjob.record('END ABORT', None, None) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 623 | myjob.complete(1) |
apw | b832e1b | 2007-11-24 20:24:38 +0000 | [diff] [blame] | 624 | else: |
| 625 | sys.exit(1) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 626 | |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 627 | except Exception, e: |
mbligh | 51144e0 | 2007-11-20 20:38:18 +0000 | [diff] [blame] | 628 | msg = str(e) + '\n' + format_error() |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 629 | print "JOB ERROR: " + msg |
mbligh | fbfb77d | 2007-02-15 18:54:03 +0000 | [diff] [blame] | 630 | if myjob: |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 631 | myjob.group_level = 0 |
| 632 | myjob.record('ABORT', None, None, msg) |
| 633 | myjob.record('END ABORT', None, None) |
mbligh | 9c5ac32 | 2007-10-31 18:01:59 +0000 | [diff] [blame] | 634 | myjob.complete(1) |
apw | b832e1b | 2007-11-24 20:24:38 +0000 | [diff] [blame] | 635 | else: |
| 636 | sys.exit(1) |
mbligh | 892d37f | 2007-03-01 17:03:25 +0000 | [diff] [blame] | 637 | |
| 638 | # If we get here, then we assume the job is complete and good. |
mbligh | c343016 | 2007-11-14 23:57:19 +0000 | [diff] [blame] | 639 | myjob.group_level = 0 |
| 640 | myjob.record('END GOOD', None, None) |
mbligh | 892d37f | 2007-03-01 17:03:25 +0000 | [diff] [blame] | 641 | myjob.complete(0) |