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