summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauren Perry <lauren.perry@codethink.co.uk>2015-04-21 11:25:29 +0100
committerBaserock Gerrit <gerrit@baserock.org>2015-04-29 16:03:05 +0000
commit4a1c2d118511da067fcadf2253fdc2a49d04e4fa (patch)
treeae1bbe9ed147e6ffad5b8f541af1eab9dc051fd9
parent8875e9cac2789b421c7160145bc1800db4ad1a55 (diff)
downloadmorph-4a1c2d118511da067fcadf2253fdc2a49d04e4fa.tar.gz
distbuild: Add protocol version checking for list-jobs command
Currently, the distbuild-list-jobs command will fail if morph is outdated (i.e. protocol version for client and distbuild network don't match); a protocol_version field has been added to the list-jobs request message to fix this. Moved version check outside build-request message to reduce duplication in new functions. Generalised the list-request output to reduce duplication for any further additions that may require a message output. Change-Id: I28e733cbfe8c89e8c11427df5d40ab275abd313c
-rw-r--r--distbuild/initiator.py14
-rw-r--r--distbuild/initiator_connection.py28
-rw-r--r--distbuild/protocol.py3
3 files changed, 30 insertions, 15 deletions
diff --git a/distbuild/initiator.py b/distbuild/initiator.py
index 0119ecd6..332d54a1 100644
--- a/distbuild/initiator.py
+++ b/distbuild/initiator.py
@@ -285,6 +285,7 @@ class InitiatorListJobs(distbuild.StateMachine):
self._app.status(msg='Requesting currently running distbuilds.')
msg = distbuild.message('list-requests',
id=msg_uuid,
+ protocol_version=distbuild.protocol.VERSION
)
self._jm.send(msg)
logging.debug('Initiator: sent to controller: %s', repr(msg))
@@ -295,13 +296,22 @@ class InitiatorListJobs(distbuild.StateMachine):
logging.debug('Initiator: from controller: %s', str(event.msg))
handlers = {
- 'list-request-output': self._handle_list_request_output,
+ # set build-failed rather than request-failed so old versions of
+ # morph recognise the message and don't ignore it
+ 'build-failed': self._handle_request_failed,
+ 'request-output': self._handle_request_output,
}
handler = handlers[event.msg['type']]
handler(event.msg)
- def _handle_list_request_output(self, msg):
+ def _handle_request_failed(self, msg):
+ self._app.status(msg=str(msg['reason']))
+ self.mainloop.queue_event(self, _Failed(msg))
+ self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
+ self._jm.close()
+
+ def _handle_request_output(self, msg):
self._app.status(msg=str(msg['message']))
self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
self._jm.close()
diff --git a/distbuild/initiator_connection.py b/distbuild/initiator_connection.py
index 54322f6a..fdb1dab5 100644
--- a/distbuild/initiator_connection.py
+++ b/distbuild/initiator_connection.py
@@ -98,6 +98,21 @@ class InitiatorConnection(distbuild.StateMachine):
event.msg)
try:
+ if event.msg.get('protocol_version') != distbuild.protocol.VERSION:
+ msg = distbuild.message('build-failed',
+ # use build-failed as it is understood by older versions of
+ # morph; if morph is old enough (protocol_version < 1) it
+ # won't understand a new message and ignore it or cause the
+ # request to hang
+ id=event.msg['id'],
+ reason=('Protocol version mismatch between server & '
+ 'initiator: distbuild network uses distbuild '
+ 'protocol version %i, but client uses version %i.'
+ % (distbuild.protocol.VERSION,
+ event.msg.get('protocol_version'))))
+ 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':
@@ -109,17 +124,6 @@ class InitiatorConnection(distbuild.StateMachine):
event.msg, ex)
def _handle_build_request(self, event):
- if event.msg.get('protocol_version') != distbuild.protocol.VERSION:
- msg = distbuild.message('build-failed',
- id=event.msg['id'],
- reason=('Protocol version mismatch between server & initiator:'
- ' distbuild network uses distbuild protocol version %i'
- ', but client uses version %i.' % (
- distbuild.protocol.VERSION,
- event.msg.get('protocol_version'))))
- self.jm.send(msg)
- self._log_send(msg)
- return
new_id = self._idgen.next()
self.our_ids.add(new_id)
self._route_map.add(event.msg['id'], new_id)
@@ -143,7 +147,7 @@ class InitiatorConnection(distbuild.StateMachine):
build.get_request()['repo'],
build.get_request()['ref'],
build.get_request()['morphology']))
- msg = distbuild.message('list-request-output',
+ msg = distbuild.message('request-output',
message=('\n\n'.join(output_msg)))
self.jm.send(msg)
diff --git a/distbuild/protocol.py b/distbuild/protocol.py
index 0f936946..2fbfa085 100644
--- a/distbuild/protocol.py
+++ b/distbuild/protocol.py
@@ -87,8 +87,9 @@ _required_fields = {
],
'list-requests': [
'id',
+ 'protocol_version',
],
- 'list-request-output': [
+ 'request-output': [
'message',
],
}