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