launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #07153
[Merge] lp:~rvb/maas/longpoll-cleanup into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/longpoll-cleanup into lp:maas with lp:~rvb/maas/frontend-bug-984728 as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/longpoll-cleanup/+merge/102493
This branch removes all the code that was used to get Django to act as a proxy to txlongpoll. Now that nginx is doing that, all that ugly code can go.
--
https://code.launchpad.net/~rvb/maas/longpoll-cleanup/+merge/102493
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/longpoll-cleanup into lp:maas.
=== modified file 'src/maas/demo.py'
--- src/maas/demo.py 2012-04-18 11:55:26 +0000
+++ src/maas/demo.py 2012-04-18 11:55:26 +0000
@@ -33,9 +33,6 @@
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
-# In dev mode: Django should act as a proxy to txlongpoll.
-LONGPOLL_SERVER_URL = "http://localhost:5242/"
-
# Enable longpoll. Set LONGPOLL_PATH to None to disable it.
LONGPOLL_PATH = '/longpoll/'
=== modified file 'src/maas/settings.py'
--- src/maas/settings.py 2012-04-17 13:45:55 +0000
+++ src/maas/settings.py 2012-04-18 11:55:26 +0000
@@ -50,12 +50,6 @@
# The MAAS CLI.
MAAS_CLI = 'sudo maas'
-# The location of the Longpoll server.
-# Set LONGPOLL_SERVER_URL to have the web app proxy requests to
-# a txlongpoll (note that this should only be required in a dev
-# environment).
-LONGPOLL_SERVER_URL = None
-
# The relative path where a proxy to the Longpoll server can be
# reached. Longpolling will be disabled in the UI if this is None.
LONGPOLL_PATH = '/longpoll/'
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py 2012-04-17 09:20:48 +0000
+++ src/maasserver/tests/test_views.py 2012-04-18 11:55:26 +0000
@@ -12,10 +12,8 @@
__metaclass__ = type
__all__ = []
-from collections import namedtuple
import httplib
import os
-import urllib2
from urlparse import urlparse
from xmlrpclib import Fault
@@ -55,15 +53,10 @@
LoggedInTestCase,
TestCase,
)
-from maasserver.urls import (
- get_proxy_longpoll_enabled,
- make_path_relative,
- )
from maasserver.views import (
get_longpoll_context,
get_yui_location,
NodeEdit,
- proxy_to_longpoll,
)
from maastesting.rabbit import uses_rabbit_fixture
from provisioningserver.enum import PSERV_FAULT
@@ -173,63 +166,6 @@
'select#id_after_commissioning_action')
-class TestProxyView(LoggedInTestCase):
- """Test the (dev) view used to proxy request to a txlongpoll server."""
-
- def test_proxy_to_longpoll(self):
- # Set LONGPOLL_SERVER_URL (to a random string).
- longpoll_server_url = factory.getRandomString()
- self.patch(settings, 'LONGPOLL_SERVER_URL', longpoll_server_url)
-
- # Create content of the fake reponse.
- query_string = factory.getRandomString()
- mimetype = factory.getRandomString()
- content = factory.getRandomString()
- status_code = factory.getRandomStatusCode()
-
- # Monkey patch urllib2.urlopen to make it return a (fake) response
- # with status_code=code, headers.typeheader=mimetype and a
- # 'read' method that will return 'content'.
- def urlopen(url):
- # Assert that urlopen is called on the longpoll url (plus
- # additional parameters taken from the original request's
- # query string).
- self.assertEqual(
- '%s?%s' % (longpoll_server_url, query_string), url)
- FakeProxiedResponse = namedtuple(
- 'FakeProxiedResponse', 'code headers read')
- headers = namedtuple('Headers', 'typeheader')(mimetype)
- return FakeProxiedResponse(status_code, headers, lambda: content)
- self.patch(urllib2, 'urlopen', urlopen)
-
- # Create a fake request.
- request = namedtuple(
- 'FakeRequest', ['META'])({'QUERY_STRING': query_string})
- response = proxy_to_longpoll(request)
-
- self.assertEqual(content, response.content)
- self.assertEqual(mimetype, response['Content-Type'])
- self.assertEqual(status_code, response.status_code)
-
-
-class TestGetLongpollenabled(TestCase):
-
- def test_longpoll_not_included_if_LONGPOLL_SERVER_URL_None(self):
- self.patch(settings, 'LONGPOLL_PATH', factory.getRandomString())
- self.patch(settings, 'LONGPOLL_SERVER_URL', None)
- self.assertFalse(get_proxy_longpoll_enabled())
-
- def test_longpoll_not_included_if_LONGPOLL_PATH_None(self):
- self.patch(settings, 'LONGPOLL_PATH', None)
- self.patch(settings, 'LONGPOLL_SERVER_URL', factory.getRandomString())
- self.assertFalse(get_proxy_longpoll_enabled())
-
- def test_longpoll_included_if_LONGPOLL_PATH_and_LONGPOLL_SERVER_URL(self):
- self.patch(settings, 'LONGPOLL_PATH', factory.getRandomString())
- self.patch(settings, 'LONGPOLL_SERVER_URL', factory.getRandomString())
- self.assertTrue(get_proxy_longpoll_enabled())
-
-
class TestComboLoaderView(TestCase):
"""Test combo loader view."""
@@ -318,16 +254,6 @@
['LONGPOLL_PATH', 'longpoll_queue'], list(context))
self.assertEqual(longpoll, context['LONGPOLL_PATH'])
- def test_make_path_relative_if_prefix(self):
- url_without_prefix = factory.getRandomString()
- url = '/%s' % url_without_prefix
- self.assertEqual(url_without_prefix, make_path_relative(url))
-
- def test_make_path_relative_if_no_prefix(self):
- url_without_prefix = factory.getRandomString()
- self.assertEqual(
- url_without_prefix, make_path_relative(url_without_prefix))
-
class UserPrefsViewTest(LoggedInTestCase):
=== modified file 'src/maasserver/urls.py'
--- src/maasserver/urls.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/urls.py 2012-04-18 11:55:26 +0000
@@ -40,7 +40,6 @@
NodeListView,
NodesCreateView,
NodeView,
- proxy_to_longpoll,
settings,
settings_add_archive,
SSHKeyCreateView,
@@ -98,32 +97,6 @@
)
-def get_proxy_longpoll_enabled():
- """Should MAAS act as a proxy to a txlongpoll server?
-
- This should only be true if longpoll is enabled (LONGPOLL_PATH) and
- if the url to a txlongpoll is configured (LONGPOLL_SERVER_URL).
- """
- return (
- django_settings.LONGPOLL_SERVER_URL is not None and
- django_settings.LONGPOLL_PATH is not None)
-
-
-def make_path_relative(url):
- if url.startswith('/'):
- return url[1:]
- else:
- return url
-
-
-if get_proxy_longpoll_enabled():
- urlpatterns += patterns('maasserver.views',
- url(
- r'^%s$' % re.escape(
- make_path_relative(django_settings.LONGPOLL_PATH)),
- proxy_to_longpoll, name='proxy-to-longpoll'),
- )
-
# URLs for admin users.
urlpatterns += patterns('maasserver.views',
adminurl(r'^settings/$', settings, name='settings'),
=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py 2012-04-17 09:20:48 +0000
+++ src/maasserver/views.py 2012-04-18 11:55:26 +0000
@@ -29,9 +29,7 @@
]
from logging import getLogger
-import mimetypes
import os
-import urllib2
from convoy.combo import (
combine_files,
@@ -442,21 +440,6 @@
return self.respond(request, profile_form, password_form)
-def proxy_to_longpoll(request):
- url = django_settings.LONGPOLL_SERVER_URL
- assert url is not None, (
- "LONGPOLL_SERVER_URL should point to a Longpoll server.")
-
- if 'QUERY_STRING' in request.META:
- url += '?' + request.META['QUERY_STRING']
- proxied_response = urllib2.urlopen(url)
- status_code = proxied_response.code
- mimetype = (
- proxied_response.headers.typeheader or mimetypes.guess_type(url))
- content = proxied_response.read()
- return HttpResponse(content, status=status_code, mimetype=mimetype)
-
-
def settings(request):
user_list = UserProfile.objects.all_users().order_by('username')
# Process the MAAS & network form.