Merge lp:~blake-rouse/maas/fix-1628213-1628213 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 5419
Proposed branch: lp:~blake-rouse/maas/fix-1628213-1628213
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 53 lines (+28/-1)
2 files modified
src/maasserver/websockets/tests/test_websockets.py (+10/-1)
src/maasserver/websockets/websockets.py (+18/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1628213-1628213
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+307198@code.launchpad.net

Commit message

Fix websocket protocol in Twisted 16.3+.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!, but there's a comment inline that needs to be addressed before landing.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/websockets/tests/test_websockets.py'
--- src/maasserver/websockets/tests/test_websockets.py 2016-02-23 00:06:54 +0000
+++ src/maasserver/websockets/tests/test_websockets.py 2016-09-30 13:23:49 +0000
@@ -50,12 +50,21 @@
50)50)
51from twisted.web.test.test_web import (51from twisted.web.test.test_web import (
52 DummyChannel,52 DummyChannel,
53 DummyRequest,53 DummyRequest as DummyRequestBase,
54)54)
55from zope.interface import implementer55from zope.interface import implementer
56from zope.interface.verify import verifyObject56from zope.interface.verify import verifyObject
5757
5858
59class DummyRequest(DummyRequestBase):
60
61 content = None
62
63 def _cleanup(self):
64 """Called to cleanup the request."""
65 pass
66
67
59class TestFrameHelpers(MAASTestCase):68class TestFrameHelpers(MAASTestCase):
60 """69 """
61 Test functions helping building and parsing WebSockets frames.70 Test functions helping building and parsing WebSockets frames.
6271
=== modified file 'src/maasserver/websockets/websockets.py'
--- src/maasserver/websockets/websockets.py 2015-11-29 23:59:47 +0000
+++ src/maasserver/websockets/websockets.py 2016-09-30 13:23:49 +0000
@@ -719,6 +719,24 @@
719 transport.protocol = protocol719 transport.protocol = protocol
720 protocol.makeConnection(transport)720 protocol.makeConnection(transport)
721721
722 # Starting with Twisted 16.3+ `_cleanup` must be called on the request
723 # so the socket is placed back into the reactor. `_cleanup` has always
724 # existed, but was not required to be called until Twisted 16.3+.
725 # `_cleanup` in Twisted 16.3+ checks to ensure that if content is None
726 # to not call close, in previous versions it does not. To make this
727 # code work on both all Twisted versions we must set content to
728 # EmptyContent so an `AttributeError` is not raied when the content is
729 # None. Only then can `_cleanup` be called safely. `finalize` also
730 # exists on the request and is actually the public API, but this
731 # method cannot be called because it will write invalid content to the
732 # socket which will break the websocket connection.
733 if request.content is None:
734 class EmptyContent:
735 def close(*args, **kwargs):
736 pass
737 request.content = EmptyContent()
738 request._cleanup()
739
722 return NOT_DONE_YET740 return NOT_DONE_YET
723741
724742