Merge lp:~rvb/maas/maas-longpoll-fix into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 289
Proposed branch: lp:~rvb/maas/maas-longpoll-fix
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 169 lines (+44/-18)
6 files modified
src/maas/demo.py (+1/-1)
src/maas/settings.py (+2/-2)
src/maasserver/templates/maasserver/index.html (+2/-2)
src/maasserver/tests/test_views.py (+23/-9)
src/maasserver/urls.py (+14/-2)
src/maasserver/views.py (+2/-2)
To merge this branch: bzr merge lp:~rvb/maas/maas-longpoll-fix
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+97582@code.launchpad.net

Commit message

Fix proxy to txlongpoll.

Description of the change

This branch fixes the dynamic inclusion of the view that acts as a proxy to a txongpoll server. This view should only be served by MaaS if both settings.LONGPOLL_SERVER_URL and settings.LONGPOLL_URL and defined (i.e. if longpoll is enabled (LONGPOLL_URL) and if the url to a txlongpoll is configured (LONGPOLL_SERVER_URL).

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) :
review: Approve
Revision history for this message
Francis J. Lacoste (flacoste) wrote :

Hi Raphaël,

Thank you very much for this fix, and the clarification of LONGPOLL_PATH, and the additional tests.

But unless I'm reading things incorrectly, we still don't have any tests that ensure that the view is setup correctly, right? We have tests get get_proxy_longpoll_enabled() is implemented correctly, but no tests that ensure that the proxy view is set up correctly? I assume we have unit tests that the view itself work properly.

Revision history for this message
Raphaël Badin (rvb) wrote :

The unit tests for the view itself are there: https://code.launchpad.net/~rvb/maas/maas-add-proxy-test/+merge/97593.

I've extracted the method get_proxy_longpoll_enabled only to test that the proxy view is setup correctly. But the tiny piece of code that sets up the view itself, I've no idea how to properly test that…

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maas/demo.py'
2--- src/maas/demo.py 2012-03-15 10:27:10 +0000
3+++ src/maas/demo.py 2012-03-15 11:30:24 +0000
4@@ -29,7 +29,7 @@
5
6 # Disable longpoll by default for now. Set it back to 'longpoll/' to
7 # enable it.
8-LONGPOLL_URL = None
9+LONGPOLL_PATH = None
10
11 # This should match the setting in /etc/pserv.yaml.
12 PSERV_URL = "http://localhost:8001/api"
13
14=== modified file 'src/maas/settings.py'
15--- src/maas/settings.py 2012-03-14 18:39:21 +0000
16+++ src/maas/settings.py 2012-03-15 11:30:24 +0000
17@@ -53,7 +53,7 @@
18
19 # The relative path where a proxy to the Longpoll server can be
20 # reached. Longpolling will be disabled in the UI if this is None.
21-LONGPOLL_URL = 'longpoll/'
22+LONGPOLL_PATH = 'longpoll/'
23
24 # Default URL specifying protocol, host, and (if necessary) port where
25 # this MaaS can be found. Configuration can, and probably should,
26@@ -65,7 +65,7 @@
27 LOGOUT_URL = FORCE_SCRIPT_NAME + LOGOUT_URL
28 LOGIN_REDIRECT_URL = FORCE_SCRIPT_NAME + LOGIN_REDIRECT_URL
29 LOGIN_URL = FORCE_SCRIPT_NAME + LOGIN_URL
30- LONGPOLL_URL = FORCE_SCRIPT_NAME + LONGPOLL_URL
31+ LONGPOLL_PATH = FORCE_SCRIPT_NAME + LONGPOLL_PATH
32 DEFAULT_MAAS_URL = urljoin(DEFAULT_MAAS_URL, FORCE_SCRIPT_NAME)
33 # ADMIN_MEDIA_PREFIX will be deprecated in Django 1.4.
34 # Admin's media will be served using staticfiles instead.
35
36=== modified file 'src/maasserver/templates/maasserver/index.html'
37--- src/maasserver/templates/maasserver/index.html 2012-03-13 17:13:01 +0000
38+++ src/maasserver/templates/maasserver/index.html 2012-03-15 11:30:24 +0000
39@@ -50,10 +50,10 @@
40 });
41
42 // Start longpoll.
43- {% if longpoll_queue and LONGPOLL_URL %}
44+ {% if longpoll_queue and LONGPOLL_PATH %}
45 Y.later(0, Y.maas.longpoll, function() {
46 var longpollmanager = Y.maas.longpoll.setupLongPollManager(
47- '{{ longpoll_queue }}', '/{{ LONGPOLL_URL }}');
48+ '{{ longpoll_queue }}', '/{{ LONGPOLL_PATH }}');
49 });
50 {% endif %}
51 });
52
53=== modified file 'src/maasserver/tests/test_views.py'
54--- src/maasserver/tests/test_views.py 2012-03-15 09:09:38 +0000
55+++ src/maasserver/tests/test_views.py 2012-03-15 11:30:24 +0000
56@@ -33,6 +33,7 @@
57 LoggedInTestCase,
58 TestCase,
59 )
60+from maasserver.urls import get_proxy_longpoll_enabled
61 from maasserver.views import (
62 get_longpoll_context,
63 proxy_to_longpoll,
64@@ -147,6 +148,24 @@
65 self.assertEqual(status_code, response.status_code)
66
67
68+class TestGetLongpollenabled(TestCase):
69+
70+ def test_longpoll_not_included_if_LONGPOLL_SERVER_URL_None(self):
71+ self.patch(settings, 'LONGPOLL_PATH', factory.getRandomString())
72+ self.patch(settings, 'LONGPOLL_SERVER_URL', None)
73+ self.assertFalse(get_proxy_longpoll_enabled())
74+
75+ def test_longpoll_not_included_if_LONGPOLL_PATH_None(self):
76+ self.patch(settings, 'LONGPOLL_PATH', None)
77+ self.patch(settings, 'LONGPOLL_SERVER_URL', factory.getRandomString())
78+ self.assertFalse(get_proxy_longpoll_enabled())
79+
80+ def test_longpoll_included_if_LONGPOLL_PATH_and_LONGPOLL_SERVER_URL(self):
81+ self.patch(settings, 'LONGPOLL_PATH', factory.getRandomString())
82+ self.patch(settings, 'LONGPOLL_SERVER_URL', factory.getRandomString())
83+ self.assertTrue(get_proxy_longpoll_enabled())
84+
85+
86 class TestComboLoaderView(TestCase):
87 """Test combo loader view."""
88
89@@ -190,30 +209,25 @@
90
91 class TestUtilities(TestCase):
92
93- def patch_settings(self, name, value):
94- old_value = getattr(settings, name)
95- setattr(settings, name, value)
96- self.addCleanup(setattr, settings, name, old_value)
97-
98 def test_get_longpoll_context_empty_if_rabbitmq_publish_is_none(self):
99 self.patch(settings, 'RABBITMQ_PUBLISH', None)
100 self.patch(views, 'messaging', get_messaging())
101 self.assertEqual({}, get_longpoll_context())
102
103 def test_get_longpoll_context_empty_if_longpoll_url_is_None(self):
104- self.patch(settings, 'LONGPOLL_URL', None)
105+ self.patch(settings, 'LONGPOLL_PATH', None)
106 self.patch(views, 'messaging', get_messaging())
107 self.assertEqual({}, get_longpoll_context())
108
109 def test_get_longpoll_context(self):
110 longpoll = factory.getRandomString()
111- self.patch(settings, 'LONGPOLL_URL', longpoll)
112+ self.patch(settings, 'LONGPOLL_PATH', longpoll)
113 self.patch(settings, 'RABBITMQ_PUBLISH', True)
114 self.patch(views, 'messaging', get_messaging())
115 context = get_longpoll_context()
116 self.assertItemsEqual(
117- ['LONGPOLL_URL', 'longpoll_queue'], list(context))
118- self.assertEqual(longpoll, context['LONGPOLL_URL'])
119+ ['LONGPOLL_PATH', 'longpoll_queue'], list(context))
120+ self.assertEqual(longpoll, context['LONGPOLL_PATH'])
121
122
123 class UserPrefsViewTest(LoggedInTestCase):
124
125=== modified file 'src/maasserver/urls.py'
126--- src/maasserver/urls.py 2012-03-14 22:52:50 +0000
127+++ src/maasserver/urls.py 2012-03-15 11:30:24 +0000
128@@ -77,10 +77,22 @@
129 r'^nodes/create/$', NodesCreateView.as_view(), name='node-create'),
130 )
131
132-if django_settings.LONGPOLL_SERVER_URL is not None:
133+
134+def get_proxy_longpoll_enabled():
135+ """Should MaaS act as a proxy to a txlongpoll server?
136+
137+ This should only be true if longpoll is enabled (LONGPOLL_PATH) and
138+ if the url to a txlongpoll is configured (LONGPOLL_SERVER_URL).
139+ """
140+ return (
141+ django_settings.LONGPOLL_SERVER_URL is not None and
142+ django_settings.LONGPOLL_PATH is not None)
143+
144+
145+if get_proxy_longpoll_enabled():
146 urlpatterns += patterns('maasserver.views',
147 url(
148- r'^%s$' % re.escape(django_settings.LONGPOLL_SERVER_URL),
149+ r'^%s$' % re.escape(django_settings.LONGPOLL_PATH),
150 proxy_to_longpoll, name='proxy-to-longpoll'),
151 )
152
153
154=== modified file 'src/maasserver/views.py'
155--- src/maasserver/views.py 2012-03-15 09:09:38 +0000
156+++ src/maasserver/views.py 2012-03-15 11:30:24 +0000
157@@ -71,10 +71,10 @@
158
159
160 def get_longpoll_context():
161- if messaging is not None and django_settings.LONGPOLL_URL is not None:
162+ if messaging is not None and django_settings.LONGPOLL_PATH is not None:
163 return {
164 'longpoll_queue': messaging.getQueue().name,
165- 'LONGPOLL_URL': django_settings.LONGPOLL_URL,
166+ 'LONGPOLL_PATH': django_settings.LONGPOLL_PATH,
167 }
168 else:
169 return {}