← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/frontend-bug-984728 into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/frontend-bug-984728 into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #984728 in MAAS: "Longpoll is not enabled on a dev instance."
  https://bugs.launchpad.net/maas/+bug/984728

For more details, see:
https://code.launchpad.net/~rvb/maas/frontend-bug-984728/+merge/102494

This branch fixes the dev environment to make it able to use longpoll without breaking the debugging/auto-reload feature of Django's dev server.

Until now, Django was used as a proxy to txlongpoll (apache does that in production) and because the python dev server does not deal well with concurrent requests, the longpoll feature was disabled by default on a dev instance.  This branch fixes that by introducing a lightweight server (nginx) that acts as a frontend to both txlongpoll and Django's dev server.  This way, a longpoll request does not touch Django.  This mimics what happens in production.

Why not use apache instead of nginx you might ask?  Many reasons: nginx is much more lightweight, nginx is much more easy to configure as a simple process run by a user.  But the main reason is that it would only have made sense to use apache if we could have reused the production's setup somehow (contrib/maas-http.conf).  But this is not the case: the production uses wsgi and we want our dev frontend to be a simple proxy to Django's dev server (to be able to debug the server).

The only downside (apart from the additional [dev] dependency) is that when you run "make run" you get:
"""
0 errors found
Django version 1.3.1, using settings 'maas.demo'
Development server is running at http://0.0.0.0:5244/
Quit the server with CONTROL-C.
"""
And it you want to be able to use longpoll you have to go to http://0.0.0.0:5240/ (where the frontend server listens).

Also, once the follow-up branch (https://code.launchpad.net/~rvb/maas/longpoll-cleanup/+merge/102493) has landed, if you go directly to Django's dev server address (http://0.0.0.0:5244/) everything will "just work" but all the longpoll requests will result in a 404 and this will cause the longpoll js code to stop polling after ~5 failed attempts.
-- 
https://code.launchpad.net/~rvb/maas/frontend-bug-984728/+merge/102494
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/frontend-bug-984728 into lp:maas.
=== modified file 'HACKING.txt'
--- HACKING.txt	2012-04-11 12:50:17 +0000
+++ HACKING.txt	2012-04-18 11:55:30 +0000
@@ -30,7 +30,7 @@
 avahi-daemon and make::
 
     $ sudo apt-get install postgresql-9.1 rabbitmq-server python-dev \
-        avahi-daemon make
+        avahi-daemon make nginx-light
 
 Also, you might want to install Bazaar (bzr) to grab the source code directly
 from Launchpad::

=== modified file 'Makefile'
--- Makefile	2012-03-29 22:39:44 +0000
+++ Makefile	2012-04-18 11:55:30 +0000
@@ -102,8 +102,18 @@
 txlongpoll-stop:
 	{ test -e $(pidfile) && cat $(pidfile); } | xargs --no-run-if-empty kill
 
-run: bin/maas dev-db run/pserv.pid run/txlongpoll.pid
-	bin/maas runserver 0.0.0.0:5240 --settings=maas.demo
+run/nginx.pid: | etc/nginx.conf
+	nginx -c etc/nginx.conf -p `pwd`/
+
+nginx-start: run/nginx.pid
+
+nginx-stop: pidfile=run/nginx.pid
+nginx-stop:
+	{ test -e $(pidfile) && cat $(pidfile); } | xargs --no-run-if-empty kill
+
+
+run: bin/maas dev-db run/pserv.pid run/txlongpoll.pid run/nginx.pid
+	bin/maas runserver 0.0.0.0:5244 --settings=maas.demo
 
 harness: bin/maas dev-db
 	bin/maas shell --settings=maas.demo

=== added file 'etc/nginx.conf'
--- etc/nginx.conf	1970-01-01 00:00:00 +0000
+++ etc/nginx.conf	2012-04-18 11:55:30 +0000
@@ -0,0 +1,52 @@
+worker_processes 4;
+pid run/nginx.pid;
+
+error_log logs/nginx.error.log;
+
+events {
+    worker_connections 768;
+    # multi_accept on;
+}
+
+http {
+
+    ##
+    # Basic Settings
+    ##
+
+    sendfile on;
+    tcp_nopush on;
+    tcp_nodelay on;
+    keepalive_timeout 65;
+    types_hash_max_size 2048;
+    # server_tokens off;
+    # server_names_hash_bucket_size 64;
+    # server_name_in_redirect off;
+
+    include /etc/nginx/mime.types;
+    default_type application/octet-stream;
+
+    ##
+    # Logging Settings
+    ##
+
+    access_log logs/nginx.access.log;
+
+    ##
+    # Server Settings
+    ##
+
+    server {
+        listen 0.0.0.0:5240;
+
+        location /longpoll/ {
+            proxy_pass http://localhost:5242;
+            proxy_buffering off;
+        }
+
+        location / {
+            proxy_pass http://localhost:5244;
+            proxy_buffering off;
+        }
+    }
+}

=== modified file 'src/maas/demo.py'
--- src/maas/demo.py	2012-04-16 10:00:51 +0000
+++ src/maas/demo.py	2012-04-18 11:55:30 +0000
@@ -36,9 +36,8 @@
 # In dev mode: Django should act as a proxy to txlongpoll.
 LONGPOLL_SERVER_URL = "http://localhost:5242/";
 
-# Disable longpoll by default for now. Set it back to '/longpoll/' to
-# enable it.
-LONGPOLL_PATH = None
+# Enable longpoll. Set LONGPOLL_PATH to None to disable it.
+LONGPOLL_PATH = '/longpoll/'
 
 # For demo purposes, use a real provisioning server.
 USE_REAL_PSERV = True


Follow ups