Move job running into own class
Help keep the state of each job the launcher is managing in its own
class. This will make stopping, pre/post playbooks and handling
failures easier.
Change-Id: I8fe77025ca443adcc5c8ca61f3a6b3abde0ba690
diff --git a/tests/base.py b/tests/base.py
index 1c3a86f..9dbd2b0 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -728,7 +728,8 @@
args = json.loads(job.arguments)
args['zuul']['_test'] = dict(test_root=self._test_root)
job.arguments = json.dumps(args)
- super(RecordingLaunchServer, self).launchJob(job)
+ self.job_workers[job.unique] = RecordingAnsibleJob(self, job)
+ self.job_workers[job.unique].run()
def stopJob(self, job):
self.log.debug("handle stop")
@@ -740,25 +741,27 @@
build.release()
super(RecordingLaunchServer, self).stopJob(job)
- def runAnsible(self, jobdir, job):
- build = self.job_builds[job.unique]
+
+class RecordingAnsibleJob(zuul.launcher.server.AnsibleJob):
+ def runAnsible(self, jobdir):
+ build = self.launcher_server.job_builds[self.job.unique]
build.jobdir = jobdir
- if self._run_ansible:
- result = super(RecordingLaunchServer, self).runAnsible(jobdir, job)
+ if self.launcher_server._run_ansible:
+ result = super(RecordingAnsibleJob, self).runAnsible(jobdir)
else:
result = build.run()
- self.lock.acquire()
- self.build_history.append(
+ self.launcher_server.lock.acquire()
+ self.launcher_server.build_history.append(
BuildHistory(name=build.name, result=result, changes=build.changes,
node=build.node, uuid=build.unique,
parameters=build.parameters,
pipeline=build.parameters['ZUUL_PIPELINE'])
)
- self.running_builds.remove(build)
- del self.job_builds[job.unique]
- self.lock.release()
+ self.launcher_server.running_builds.remove(build)
+ del self.launcher_server.job_builds[self.job.unique]
+ self.launcher_server.lock.release()
if build.run_error:
result = None
return result