diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-01-24 16:22:31 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-01-24 16:23:39 +0000 |
commit | 945ab216b0ec2c58d49053e07f8509973959b7da (patch) | |
tree | 14e2a103c5945bc54e563cb0c6d098bab9ec0f13 /morphlib | |
parent | c38753c076f1dcd440ad0fdac152555192581dd9 (diff) | |
download | morph-945ab216b0ec2c58d49053e07f8509973959b7da.tar.gz |
Report build errors in workers back to the controller.
Also, distinguish between running "sudo" and "fakeroot" depending on
whether or not a remote worker builds a system image. For some reason,
sudo in SSH does not seem to work here, so we need to figure that out.
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/buildcontroller.py | 4 | ||||
-rw-r--r-- | morphlib/buildworker.py | 53 |
2 files changed, 42 insertions, 15 deletions
diff --git a/morphlib/buildcontroller.py b/morphlib/buildcontroller.py index 0c8388cf..4a2d8cf1 100644 --- a/morphlib/buildcontroller.py +++ b/morphlib/buildcontroller.py @@ -69,6 +69,10 @@ class BuildController(object): if worker.output: for line in worker.output.split('\n'): self.msg('> %s' % line) + if worker.error: + import morphlib + raise morphlib.execute.CommandFailure(worker.error['command'], + worker.error['error']) # mark all finished workers as being idle for worker in finished: diff --git a/morphlib/buildworker.py b/morphlib/buildworker.py index f75177b3..4b2a52f9 100644 --- a/morphlib/buildworker.py +++ b/morphlib/buildworker.py @@ -46,6 +46,7 @@ class BuildWorker(object): self.process = None self.blob = None self._output = self.manager.list() + self._error = self.manager.dict() def build(self, blob): raise NotImplementedError @@ -68,6 +69,10 @@ class BuildWorker(object): except IndexError: return None + @property + def error(self): + return self._error + def __str__(self): return self.name @@ -77,21 +82,31 @@ class LocalBuildWorker(BuildWorker): def __init__(self, name, ident, app): BuildWorker.__init__(self, name, ident, app) - def run(self, repo, ref, filename, output): + def run(self, repo, ref, filename, output, error): ex = morphlib.execute.Execute('.', self.msg) - stdout = ex.runv(['./morph', '--verbose', '--keep-path', - 'build', repo, ref, filename]) - output.append(stdout) - - # TODO report errors back to the caller + # generate command line options + cmdline = ['morph', 'build', repo, ref, filename] + + # run morph locally in a child process + try: + stdout = ex.runv(cmdline) + output.append(stdout) + except OSError, e: + error['error'] = str(e) + error['command'] = ' '.join(cmdline) + except morphlib.execute.CommandFailure, e: + error['error'] = str(e) + error['command'] = ' '.join(cmdline) + def build(self, blob): self.reset() self.blob = blob args = (blob.morph.treeish.original_repo, blob.morph.treeish.ref, blob.morph.filename, - self._output) + self._output, + self._error) self.process = Process(group=None, target=self.run, args=args) self.process.start() @@ -102,25 +117,33 @@ class RemoteBuildWorker(BuildWorker): BuildWorker.__init__(self, name, ident, app) self.hostname = ident - def run(self, repo, ref, filename, output): + def run(self, repo, ref, filename, sudo, output, error): ex = morphlib.execute.Execute('.', self.msg) # generate command line options cmdline = ['ssh', self.hostname] - cmdline.extend(['fakeroot', 'morph', 'build', repo, ref, filename]) + cmdline.extend(['sudo' if sudo else 'fakeroot-sysv']) + cmdline.extend(['morph', 'build', repo, ref, filename]) # run morph on the other machine - stdout = ex.runv(cmdline) - output.append(stdout) - - # TODO report errors back to the caller - + try: + stdout = ex.runv(cmdline) + output.append(stdout) + except OSError, e: + error['error'] = str(e) + error['command'] = ' '.join(cmdline) + except morphlib.execute.CommandFailure, e: + error['error'] = str(e) + error['command'] = ' '.join(cmdline) + def build(self, blob): self.reset() self.blob = blob args = (blob.morph.treeish.original_repo, blob.morph.treeish.ref, blob.morph.filename, - self._output) + blob.morph.kind == 'system', + self._output, + self._error) self.process = Process(group=None, target=self.run, args=args) self.process.start() |