launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #09156
[Merge] lp:~rvb/maas/fix-avahi into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/fix-avahi into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/fix-avahi/+merge/111814
This branch changes where we set up zeroconf. Instead of doing that in urls.py, we only set up zeroconfg when running the full server (in calling 'runserver' [dev mode] and in wsgi.py [production mode]). This way, nothing will be published over avahi when running commands.
Note that this is sort of a follow-up branch on the rejected branch https://code.launchpad.net/~rvb/maas/enlist-kernel-cmd-line/+merge/111632.
The main change is copied from https://code.launchpad.net/~allenap/maas/enlist-kernel-cmd-line/+merge/111674.
= Notes =
I couldn't help but salvage the change I made to absolute_reverse; that change will definitely come in handy.
I made two changes to contrib/maas-http.conf. These are simple improvements:
- adding "display-name=%{GROUP}" to the WSGIDaemonProcess statement make the wsgi process look nicer when running "ps".
- WSGIImportScript preloads the wsgi script (which is otherwise lazily loaded, meaning that nothing will actually get done before the first request comes in). This has two benefits:
- there is no penalty for the first request (which currently has to load up the whole application).
- initialization code (currently only, the avahi publishing) happens the server starts and not when the first request comes in).
--
https://code.launchpad.net/~rvb/maas/fix-avahi/+merge/111814
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/fix-avahi into lp:maas.
=== modified file 'contrib/maas-http.conf'
--- contrib/maas-http.conf 2012-04-12 19:31:38 +0000
+++ contrib/maas-http.conf 2012-06-25 10:41:37 +0000
@@ -1,5 +1,8 @@
-WSGIDaemonProcess maas user=maas group=maas processes=2 threads=1
+WSGIDaemonProcess maas user=maas group=maas processes=2 threads=1 display-name=%{GROUP}
WSGIScriptAlias /MAAS /usr/share/maas/wsgi.py
+# Preload application when process starts. This will allow publishing
+# the MAAS server existence over Avahi.
+WSGIImportScript /usr/share/maas/wsgi.py process-group=maas
WSGIPassAuthorization On
<Directory /usr/share/maas/>
=== modified file 'contrib/wsgi.py'
--- contrib/wsgi.py 2012-04-16 10:00:51 +0000
+++ contrib/wsgi.py 2012-06-25 10:41:37 +0000
@@ -16,6 +16,7 @@
import sys
import django.core.handlers.wsgi
+from maasserver.maasavahi import setup_maas_avahi_service
current_path = os.path.dirname(os.path.abspath(__file__))
@@ -23,3 +24,5 @@
os.environ['DJANGO_SETTINGS_MODULE'] = 'maas.settings'
application = django.core.handlers.wsgi.WSGIHandler()
+
+setup_maas_avahi_service()
=== modified file 'src/maasserver/management/commands/runserver.py'
--- src/maasserver/management/commands/runserver.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/management/commands/runserver.py 2012-06-25 10:41:37 +0000
@@ -19,6 +19,7 @@
from django.core.management.commands.runserver import BaseRunserverCommand
from django.core.servers import basehttp
from django.core.servers.basehttp import WSGIServer
+from maasserver.maasavahi import setup_maas_avahi_service
import oops
from oops_datedir_repo import DateDirRepo
from oops_wsgi import (
@@ -67,6 +68,7 @@
# Monkey patch basehttp.WSGIServer.
setattr(basehttp, 'WSGIServer', ThreadedWSGIServer)
+ setup_maas_avahi_service()
return super(Command, self).run(*args, **options)
def get_handler(self, *args, **kwargs):
=== modified file 'src/maasserver/tests/test_utils.py'
--- src/maasserver/tests/test_utils.py 2012-06-20 18:32:54 +0000
+++ src/maasserver/tests/test_utils.py 2012-06-25 10:41:37 +0000
@@ -12,6 +12,8 @@
__metaclass__ = type
__all__ = []
+from urllib import urlencode
+
from django.conf import settings
from django.core.urlresolvers import reverse
from maasserver.enum import NODE_STATUS_CHOICES
@@ -69,6 +71,13 @@
expected_url = settings.DEFAULT_MAAS_URL + reverse('settings')
self.assertEqual(expected_url, absolute_url)
+ def test_absolute_reverse_uses_query_string(self):
+ self.patch(settings, 'DEFAULT_MAAS_URL', '')
+ parameters = {factory.getRandomString(): factory.getRandomString()}
+ absolute_url = absolute_reverse('settings', query_dict=parameters)
+ expected_url = '%s?%s' % (reverse('settings'), urlencode(parameters))
+ self.assertEqual(expected_url, absolute_url)
+
def test_absolute_reverse_uses_kwargs(self):
node = factory.make_node()
self.patch(settings, 'DEFAULT_MAAS_URL', '')
=== modified file 'src/maasserver/urls.py'
--- src/maasserver/urls.py 2012-06-22 07:50:12 +0000
+++ src/maasserver/urls.py 2012-06-25 10:41:37 +0000
@@ -25,7 +25,6 @@
direct_to_template,
redirect_to,
)
-from maasserver.maasavahi import setup_maas_avahi_service
from maasserver.models import Node
from maasserver.views.account import (
login,
@@ -148,10 +147,3 @@
urlpatterns += patterns('',
(r'^api/1\.0/', include('maasserver.urls_api'))
)
-
-# Code to run once when the server is initialized, as suggested in
-# http://stackoverflow.com/
-# questions/
-# 6791911/
-# execute-code-when-django-starts-once-only
-setup_maas_avahi_service()
=== modified file 'src/maasserver/utils.py'
--- src/maasserver/utils.py 2012-06-20 15:59:47 +0000
+++ src/maasserver/utils.py 2012-06-25 10:41:37 +0000
@@ -17,6 +17,7 @@
'map_enum',
]
+from urllib import urlencode
from urlparse import urljoin
from django.conf import settings
@@ -61,7 +62,7 @@
}
-def absolute_reverse(view_name, *args, **kwargs):
+def absolute_reverse(view_name, query_dict=None, *args, **kwargs):
"""Return the absolute URL (i.e. including the URL scheme specifier and
the network location of the MAAS server). Internally this method simply
calls Django's 'reverse' method and prefixes the result of that call with
@@ -69,8 +70,13 @@
:param view_name: Django's view function name/reference or URL pattern
name for which to compute the absolute URL.
+ :param query_dict: Optional dictionary containing parameters for the
+ query string.
:param args: Positional arguments for Django's 'reverse' method.
:param kwargs: Named arguments for Django's 'reverse' method.
"""
- return urljoin(
+ url = urljoin(
settings.DEFAULT_MAAS_URL, reverse(view_name, *args, **kwargs))
+ if query_dict is not None:
+ url += '?%s' % urlencode(query_dict)
+ return url