diff options
author | Lauren Perry <lauren.perry@codethink.co.uk> | 2015-04-10 15:29:06 +0100 |
---|---|---|
committer | Richard Ipsum <richardipsum@fastmail.co.uk> | 2015-04-29 16:11:14 +0000 |
commit | 4941d1dd806d1751b1ac0f7a695ec2b6dce93ba0 (patch) | |
tree | 0f39b69358e9af9066b9d2dbc2ceffe4eebb7cf2 /distbuild/initiator_connection.py | |
parent | 84096556ea54d4af236f1fe5f7ccf61c1343016f (diff) | |
download | morph-4941d1dd806d1751b1ac0f7a695ec2b6dce93ba0.tar.gz |
distbuild: Add distbuild status command
Adds a command to get the status of all recently ran distbuilds
for a given server (e.g. Running, Finished, Failed, Cancelled),
so as to tell if a build running via distbuild-start has finished
or otherwise exited without going through the server's log files
Change-Id: I5ce9fe54ae7b1bd8fe3e0d629f615042be8827ed
Diffstat (limited to 'distbuild/initiator_connection.py')
-rw-r--r-- | distbuild/initiator_connection.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/distbuild/initiator_connection.py b/distbuild/initiator_connection.py index 718686dc..7fd45d4d 100644 --- a/distbuild/initiator_connection.py +++ b/distbuild/initiator_connection.py @@ -107,6 +107,12 @@ class InitiatorConnection(distbuild.StateMachine): logging.debug('InitiatorConnection: from %s: %r', self.initiator_name, event.msg) + msg_handler = { + 'build-request': self._handle_build_request, + 'list-requests': self._handle_list_requests, + 'build-cancel': self._handle_build_cancel, + 'build-status': self._handle_build_status, + } try: if event.msg.get('protocol_version') != distbuild.protocol.VERSION: msg = distbuild.message('build-failed', @@ -123,14 +129,7 @@ class InitiatorConnection(distbuild.StateMachine): self.jm.send(msg) self._log_send(msg) return - if event.msg['type'] == 'build-request': - self._handle_build_request(event) - elif event.msg['type'] == 'list-requests': - self._handle_list_requests(event) - elif event.msg['type'] == 'build-cancel': - self._handle_build_cancel(event) - else: - logging.error('Invalid message type: %s', event.msg) + msg_handler[event.msg['type']](event) except (KeyError, ValueError) as ex: logging.error('Invalid message from initiator: %s: exception %s', event.msg, ex) @@ -144,6 +143,7 @@ class InitiatorConnection(distbuild.StateMachine): self, event.msg, self.artifact_cache_server, self.morph_instance) self.mainloop.add_state_machine(build_controller) + self.mainloop.build_info.append(build_controller.build_info) def _handle_list_requests(self, event): requests = self.mainloop.state_machines_of_type( @@ -181,6 +181,24 @@ class InitiatorConnection(distbuild.StateMachine): 'running build IDs.')) self.jm.send(msg) + def _handle_build_status(self, event): + for build_info in self.mainloop.build_info: + if build_info['id'] == event.msg['id']: + msg = distbuild.message('request-output', + message=('\nBuild request ID: %s\n System build: %s\n ' + 'Build status: %s' % (build_info['id'], + build_info['morphology'], + build_info['status']))) + + self.jm.send(msg) + break + else: + msg = distbuild.message('request-output', message=('Given ' + 'build-request ID does not match any ' + 'recent build IDs (the status information ' + 'for this build may have expired).')) + self.jm.send(msg) + def _disconnect(self, event_source, event): for id in self.our_ids: logging.debug('InitiatorConnection: %s: InitiatorDisconnect(%s)', |