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 |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 9 | import os, sys, re, pickle, shutil |
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 | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 13 | import kernel, xen, test, profilers, barrier, filesystem, fd_stack, boottool |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 14 | import harness, config |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 15 | |
| 16 | class job: |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 17 | """The actual job against which we do everything. |
| 18 | |
| 19 | Properties: |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 20 | autodir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 21 | The top level autotest directory (/usr/local/autotest). |
| 22 | Comes from os.environ['AUTODIR']. |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 23 | bindir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 24 | <autodir>/bin/ |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 25 | testdir |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 26 | <autodir>/tests/ |
| 27 | profdir |
| 28 | <autodir>/profilers/ |
| 29 | tmpdir |
| 30 | <autodir>/tmp/ |
| 31 | resultdir |
| 32 | <autodir>/results/<jobtag> |
| 33 | stdout |
| 34 | fd_stack object for stdout |
| 35 | stderr |
| 36 | fd_stack object for stderr |
| 37 | profilers |
| 38 | the profilers object for this job |
apw | 504a7dd | 2006-10-12 17:18:37 +0000 | [diff] [blame] | 39 | harness |
| 40 | the server harness object for this job |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 41 | config |
| 42 | the job configuration for this job |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 43 | """ |
| 44 | |
mbligh | 570e93e | 2006-11-26 05:15:56 +0000 | [diff] [blame] | 45 | def __init__(self, control, jobtag, cont, harness_type=''): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 46 | """ |
| 47 | control |
| 48 | The control file (pathname of) |
| 49 | jobtag |
| 50 | The job tag string (eg "default") |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 51 | cont |
| 52 | If this is the continuation of this job |
apw | e68a713 | 2006-12-01 11:21:37 +0000 | [diff] [blame] | 53 | harness_type |
| 54 | An alternative server harness |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 55 | """ |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 56 | self.autodir = os.environ['AUTODIR'] |
mbligh | 0674377 | 2006-05-18 21:30:19 +0000 | [diff] [blame] | 57 | self.bindir = self.autodir + '/bin' |
mbligh | 8264186 | 2006-04-23 06:21:36 +0000 | [diff] [blame] | 58 | self.testdir = self.autodir + '/tests' |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 59 | self.profdir = self.autodir + '/profilers' |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 60 | self.tmpdir = self.autodir + '/tmp' |
mbligh | 24f7da0 | 2006-04-23 06:32:18 +0000 | [diff] [blame] | 61 | self.resultdir = self.autodir + '/results/' + jobtag |
mbligh | a250805 | 2006-05-28 21:29:53 +0000 | [diff] [blame] | 62 | |
apw | 96da1a4 | 2006-11-02 00:23:18 +0000 | [diff] [blame] | 63 | if not cont: |
| 64 | if os.path.exists(self.tmpdir): |
| 65 | system('rm -rf ' + self.tmpdir) |
| 66 | os.mkdir(self.tmpdir) |
| 67 | |
| 68 | if os.path.exists(self.resultdir): |
| 69 | system('rm -rf ' + self.resultdir) |
| 70 | os.mkdir(self.resultdir) |
| 71 | |
| 72 | os.mkdir(self.resultdir + "/debug") |
| 73 | os.mkdir(self.resultdir + "/analysis") |
| 74 | os.mkdir(self.resultdir + "/sysinfo") |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 75 | shutil.copyfile(control, self.resultdir + "/control") |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 76 | |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 77 | self.control = control |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 78 | self.jobtab = jobtag |
| 79 | |
mbligh | 56f1fbb | 2006-10-01 15:10:56 +0000 | [diff] [blame] | 80 | self.stdout = fd_stack.fd_stack(1, sys.stdout) |
| 81 | self.stderr = fd_stack.fd_stack(2, sys.stderr) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 82 | |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 83 | self.config = config.config(self) |
| 84 | |
apw | d27e55f | 2006-12-01 11:22:08 +0000 | [diff] [blame] | 85 | self.harness = harness.select(harness_type, self) |
| 86 | |
mbligh | a35553b | 2006-04-23 15:52:25 +0000 | [diff] [blame] | 87 | self.profilers = profilers.profilers(self) |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 88 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 89 | try: |
apw | 90154af | 2006-12-01 11:23:36 +0000 | [diff] [blame] | 90 | tool = self.config_get('boottool.executable') |
| 91 | self.bootloader = boottool.boottool(tool) |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 92 | except: |
| 93 | pass |
| 94 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 95 | pwd = os.getcwd() |
mbligh | 0674377 | 2006-05-18 21:30:19 +0000 | [diff] [blame] | 96 | os.chdir(self.resultdir + "/sysinfo") |
| 97 | system(self.bindir + '/sysinfo.py') |
| 98 | os.chdir(pwd) |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 99 | |
apw | 357f50f | 2006-12-01 11:22:39 +0000 | [diff] [blame] | 100 | self.harness.run_start() |
| 101 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 102 | |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 103 | def harness_select(self, which): |
| 104 | self.harness = harness.select(which, self) |
| 105 | |
| 106 | |
apw | 059e1b1 | 2006-10-12 17:18:26 +0000 | [diff] [blame] | 107 | def config_set(self, name, value): |
| 108 | self.config.set(name, value) |
| 109 | |
| 110 | |
| 111 | def config_get(self, name): |
| 112 | return self.config.get(name) |
| 113 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 114 | def setup_dirs(self, results_dir, tmp_dir): |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 115 | if not tmp_dir: |
| 116 | tmp_dir = self.tmpdir + '/build' |
| 117 | if not os.path.exists(tmp_dir): |
| 118 | os.mkdir(tmp_dir) |
| 119 | if not os.path.isdir(tmp_dir): |
| 120 | raise "Temp dir (%s) is not a dir - args backwards?" \ |
| 121 | % self.tmpdir |
| 122 | |
| 123 | # We label the first build "build" and then subsequent ones |
| 124 | # as "build.2", "build.3", etc. Whilst this is a little bit |
| 125 | # inconsistent, 99.9% of jobs will only have one build |
| 126 | # (that's not done as kernbench, sparse, or buildtest), |
| 127 | # so it works out much cleaner. One of life's comprimises. |
| 128 | if not results_dir: |
| 129 | results_dir = os.path.join(self.resultdir, 'build') |
| 130 | i = 2 |
| 131 | while os.path.exists(results_dir): |
| 132 | results_dir = os.path.join(self.resultdir, 'build.%d' % i) |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 133 | i += 1 |
mbligh | 1e8858e | 2006-11-24 22:18:35 +0000 | [diff] [blame] | 134 | if not os.path.exists(results_dir): |
| 135 | os.mkdir(results_dir) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 136 | |
mbligh | 8baa2ea | 2006-12-17 23:01:24 +0000 | [diff] [blame] | 137 | return (results_dir, tmp_dir) |
| 138 | |
| 139 | |
| 140 | def xen(self, base_tree, results_dir = '', tmp_dir = '', leave = False, \ |
| 141 | kjob = None ): |
| 142 | """Summon a xen object""" |
| 143 | (results_dir, tmp_dir) = self.setup_dirs(results_dir, tmp_dir) |
| 144 | build_dir = 'xen' |
| 145 | return xen.xen(self, base_tree, results_dir, tmp_dir, build_dir, leave, kjob) |
| 146 | |
| 147 | |
| 148 | def kernel(self, base_tree, results_dir = '', tmp_dir = '', leave = False): |
| 149 | """Summon a kernel object""" |
| 150 | (results_dir, tmp_dir) = self.setup_dirs(results_dir, tmp_dir) |
| 151 | build_dir = 'linux' |
| 152 | return kernel.kernel(self, base_tree, results_dir, tmp_dir, build_dir, leave) |
mbligh | f4c3532 | 2006-03-13 01:01:10 +0000 | [diff] [blame] | 153 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 154 | |
mbligh | fadca20 | 2006-09-23 04:40:01 +0000 | [diff] [blame] | 155 | def barrier(self, *args): |
| 156 | """Create a barrier object""" |
| 157 | return barrier.barrier(*args) |
| 158 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 159 | |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 160 | def setup_dep(self, deps): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 161 | """Set up the dependencies for this test. |
| 162 | |
| 163 | deps is a list of libraries required for this test. |
| 164 | """ |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 165 | for dep in deps: |
| 166 | try: |
| 167 | os.chdir(self.autodir + '/deps/' + dep) |
| 168 | system('./' + dep + '.py') |
| 169 | except: |
| 170 | error = "setting up dependency " + dep + "\n" |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 171 | raise UnhandledError(error) |
mbligh | 4b08966 | 2006-06-14 22:34:58 +0000 | [diff] [blame] | 172 | |
| 173 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 174 | def __runtest(self, url, tag, args, dargs): |
| 175 | try: |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 176 | test.runtest(self, url, tag, args, dargs) |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 177 | except AutotestError: |
| 178 | raise |
| 179 | except: |
| 180 | raise UnhandledError('running test ' + \ |
| 181 | self.__class__.__name__ + "\n") |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 182 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 183 | |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 184 | def runtest(self, tag, url, *args): |
| 185 | raise "Deprecated call to job.runtest. Use run_test instead" |
| 186 | |
| 187 | |
| 188 | def run_test(self, url, *args, **dargs): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 189 | """Summon a test object and run it. |
| 190 | |
| 191 | tag |
| 192 | tag to add to testname |
mbligh | 12a7df7 | 2006-10-06 03:54:33 +0000 | [diff] [blame] | 193 | url |
| 194 | url of the test to run |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 195 | """ |
mbligh | 12a7df7 | 2006-10-06 03:54:33 +0000 | [diff] [blame] | 196 | |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 197 | if not url: |
| 198 | raise "Test name is invalid. Switched arguments?" |
mbligh | 12a7df7 | 2006-10-06 03:54:33 +0000 | [diff] [blame] | 199 | (group, name) = test.testname(url) |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 200 | tag = None |
| 201 | if dargs.has_key('tag'): |
| 202 | tag = dargs['tag'] |
| 203 | del dargs['tag'] |
mbligh | 7880b1b | 2006-05-07 16:57:50 +0000 | [diff] [blame] | 204 | name += '.' + tag |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 205 | try: |
| 206 | try: |
mbligh | d016ecc | 2006-11-25 21:41:07 +0000 | [diff] [blame] | 207 | self.__runtest(url, tag, args, dargs) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 208 | except Exception, detail: |
| 209 | self.record("FAIL " + name + " " + \ |
| 210 | detail.__str__() + "\n") |
| 211 | |
| 212 | raise |
| 213 | else: |
| 214 | self.record("GOOD " + name + \ |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 215 | " completed successfully\n") |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 216 | except TestError: |
| 217 | return 0 |
| 218 | except: |
| 219 | raise |
| 220 | else: |
| 221 | return 1 |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 222 | |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 223 | |
| 224 | def filesystem(self, device, mountpoint = None): |
| 225 | if not mountpoint: |
| 226 | mountpoint = self.tmpdir |
mbligh | b15f963 | 2006-12-04 07:27:57 +0000 | [diff] [blame] | 227 | return filesystem.filesystem(self, device, mountpoint) |
mbligh | d7fb4a6 | 2006-10-01 00:57:53 +0000 | [diff] [blame] | 228 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 229 | |
| 230 | def reboot(self, tag='autotest'): |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 231 | self.harness.run_reboot() |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 232 | self.bootloader.boot_once(tag) |
| 233 | system("reboot") |
apw | 0778a2f | 2006-10-06 03:11:40 +0000 | [diff] [blame] | 234 | self.quit() |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 235 | |
| 236 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 237 | def noop(self, text): |
| 238 | print "job: noop: " + text |
| 239 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 240 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 241 | # Job control primatives. |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 242 | |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 243 | def __parallel_execute(self, func, *args): |
| 244 | func(*args) |
| 245 | |
| 246 | |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 247 | def parallel(self, *tasklist): |
| 248 | """Run tasks in parallel""" |
apw | 8fef4ac | 2006-10-10 22:53:37 +0000 | [diff] [blame] | 249 | |
| 250 | pids = [] |
| 251 | for task in tasklist: |
| 252 | pids.append(fork_start(self.resultdir, |
| 253 | lambda: self.__parallel_execute(*task))) |
| 254 | for pid in pids: |
| 255 | fork_waitfor(self.resultdir, pid) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 256 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 257 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 258 | def quit(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 259 | # XXX: should have a better name. |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 260 | self.harness.run_pause() |
apw | f2c6660 | 2006-04-27 14:11:25 +0000 | [diff] [blame] | 261 | raise JobContinue("more to come") |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 262 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 263 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 264 | def complete(self, status): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 265 | """Clean up and exit""" |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 266 | # We are about to exit 'complete' so clean up the control file. |
| 267 | try: |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 268 | os.unlink(self.control + '.state') |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 269 | except: |
| 270 | pass |
mbligh | 61a6c1a | 2006-12-25 01:26:38 +0000 | [diff] [blame^] | 271 | self.harness.run_complete() |
apw | 1b02190 | 2006-04-03 17:02:56 +0000 | [diff] [blame] | 272 | sys.exit(status) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 273 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 274 | |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 275 | steps = [] |
| 276 | def next_step(self, step): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 277 | """Define the next step""" |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 278 | step[0] = step[0].__name__ |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 279 | self.steps.append(step) |
apw | ecf41b7 | 2006-03-31 14:00:55 +0000 | [diff] [blame] | 280 | pickle.dump(self.steps, open(self.control + '.state', 'w')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 281 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 282 | |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 283 | def step_engine(self): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 284 | """the stepping engine -- if the control file defines |
| 285 | step_init we will be using this engine to drive multiple runs. |
| 286 | """ |
| 287 | """Do the next step""" |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 288 | lcl = dict({'job': self}) |
| 289 | |
| 290 | str = """ |
| 291 | from error import * |
| 292 | from autotest_utils import * |
| 293 | """ |
| 294 | exec(str, lcl, lcl) |
| 295 | execfile(self.control, lcl, lcl) |
| 296 | |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 297 | state = self.control + '.state' |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 298 | # If there is a mid-job state file load that in and continue |
| 299 | # where it indicates. Otherwise start stepping at the passed |
| 300 | # entry. |
| 301 | try: |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 302 | self.steps = pickle.load(open(state, 'r')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 303 | except: |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 304 | if lcl.has_key('step_init'): |
| 305 | self.next_step([lcl['step_init']]) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 306 | |
| 307 | # Run the step list. |
| 308 | while len(self.steps) > 0: |
apw | fd922bb | 2006-04-04 07:47:00 +0000 | [diff] [blame] | 309 | step = self.steps.pop(0) |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 310 | pickle.dump(self.steps, open(state, 'w')) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 311 | |
| 312 | cmd = step.pop(0) |
apw | 83f8d77 | 2006-04-27 14:12:56 +0000 | [diff] [blame] | 313 | cmd = lcl[cmd] |
| 314 | lcl['__cmd'] = cmd |
| 315 | lcl['__args'] = step |
| 316 | exec("__cmd(*__args)", lcl, lcl) |
apw | 0865f48 | 2006-03-30 18:50:19 +0000 | [diff] [blame] | 317 | |
| 318 | # all done, clean up and exit. |
| 319 | self.complete(0) |
| 320 | |
mbligh | caa605c | 2006-10-02 00:37:35 +0000 | [diff] [blame] | 321 | |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 322 | def record(self, msg): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 323 | """Record job-level status""" |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 324 | |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 325 | msg = msg.rstrip() |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 326 | # Ensure any continuation lines are marked so we can |
| 327 | # detect them in the status file to ensure it is parsable. |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 328 | msg = re.sub(r"\n", "\n ", msg) |
apw | 7db8d0b | 2006-10-09 08:10:25 +0000 | [diff] [blame] | 329 | |
apw | de1503a | 2006-10-10 08:34:21 +0000 | [diff] [blame] | 330 | self.harness.test_status(msg) |
apw | f1a8116 | 2006-04-25 10:10:29 +0000 | [diff] [blame] | 331 | print msg |
| 332 | status = self.resultdir + "/status" |
mbligh | d9223fc | 2006-11-26 17:19:54 +0000 | [diff] [blame] | 333 | file(status, "a").write(msg + "\n") |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 334 | |
| 335 | |
mbligh | 570e93e | 2006-11-26 05:15:56 +0000 | [diff] [blame] | 336 | def runjob(control, cont = False, tag = "default", harness_type = ''): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 337 | """The main interface to this module |
| 338 | |
mbligh | 72b88fc | 2006-12-16 18:41:35 +0000 | [diff] [blame] | 339 | control |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 340 | The control file to use for this job. |
| 341 | cont |
| 342 | Whether this is the continuation of a previously started job |
| 343 | """ |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 344 | state = control + '.state' |
| 345 | |
| 346 | # instantiate the job object ready for the control file. |
| 347 | myjob = None |
| 348 | try: |
| 349 | # Check that the control file is valid |
| 350 | if not os.path.exists(control): |
| 351 | raise JobError(control + ": control file not found") |
| 352 | |
| 353 | # When continuing, the job is complete when there is no |
| 354 | # state file, ensure we don't try and continue. |
mbligh | f3fef46 | 2006-09-13 16:05:05 +0000 | [diff] [blame] | 355 | if cont and not os.path.exists(state): |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 356 | sys.exit(1) |
mbligh | f3fef46 | 2006-09-13 16:05:05 +0000 | [diff] [blame] | 357 | if cont == False and os.path.exists(state): |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 358 | os.unlink(state) |
| 359 | |
mbligh | 570e93e | 2006-11-26 05:15:56 +0000 | [diff] [blame] | 360 | myjob = job(control, tag, cont, harness_type) |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 361 | |
| 362 | # Load in the users control file, may do any one of: |
| 363 | # 1) execute in toto |
| 364 | # 2) define steps, and select the first via next_step() |
| 365 | myjob.step_engine() |
| 366 | |
| 367 | # If we get here, then we assume the job is complete and good. |
| 368 | myjob.complete(0) |
| 369 | |
| 370 | except JobContinue: |
| 371 | sys.exit(5) |
| 372 | |
| 373 | except JobError, instance: |
| 374 | print "JOB ERROR: " + instance.args[0] |
| 375 | if myjob != None: |
| 376 | myjob.complete(1) |
| 377 | |
| 378 | except: |
mbligh | 61a6c1a | 2006-12-25 01:26:38 +0000 | [diff] [blame^] | 379 | myjob.harness.run_abort() |
apw | ce9abe9 | 2006-04-27 14:14:04 +0000 | [diff] [blame] | 380 | # Ensure we cannot continue this job, it is in rictus. |
| 381 | if os.path.exists(state): |
| 382 | os.unlink(state) |
| 383 | raise |