Commits

theoden committed 40fb850

+ UwsgiSetupTest was added to "misc" test-set, and the former is green.
+ uWSGI config uwsgi.ini was added

Comments (0)

Files changed (5)

fab_deploy/webserver/uwsgi.py

 # coding: utf-8
 from __future__ import with_statement, absolute_import
 
-from fabric.api import cd, sudo, prefix #env, run, settings, hide, abort
+from fabric.api import env, cd, sudo, prefix #run, settings, hide, abort
 #from fabric.contrib import files, console
 
 from taskset import task_method
 __all__ = ['Uwsgi']
 
 class Uwsgi(WsgiBackend):
-    """ Only lucid and squeeze are supported. """
+    """ Only squeeze is supported. """ # need someone to port on lucid
 
-    def __init__(self, config='uwsgi.config', wsgi='wsgi.py'):
+    def __init__(self, config='uwsgi.ini', wsgi='wsgi.py'):
         super(Uwsgi, self).__init__(wsgi)
         self.config = config
 
             extra_context={'CURRENT_BACKEND': self}, use_sudo=True
         )
         with cd('/etc/uwsgi/apps-enabled'):
-            sudo('ln -s ../apps-available/%s .' % name)
+            sudo('if [ ! -f %s ]; then ln -s ../apps-available/%s .; fi' % (name, name))
 
     @task_method
     @utils.run_as_sudo

fab_deploy_tests/runtests.py

 
     suites = {
         'misc': TestSuite(load(initial + [
-                    FastPrepareServerTest, ApacheSetupTest,
+                    FastPrepareServerTest, ApacheSetupTest, UwsgiSetupTest,
                     PipSetupTest, NoPipSetupTest, CrontabTest,
                     MysqlNonRootTest, PostgresSetupTest,
                 ])),

fab_deploy_tests/test_project/config_templates/uwsgi.ini

+# django < 1.4 options
+[uwsgi]
+plugins = python27
+virtualenv = {{ ENV_DIR }}
+chdir = {{ PROJECT_DIR }}
+module = {{ CURRENT_BACKEND.get_wsgi_full_file_name() }}
+touch-reload = {{ CURRENT_BACKEND.get_wsgi_full_file_name() }}

fab_deploy_tests/test_project/fabfile.py

 
 from fab_deploy.utils import define_host, update_env
 from fab_deploy.project import WebProject
+from fab_deploy.django import Django
+from fab_deploy.webserver.uwsgi import Uwsgi
+from fab_deploy.webserver.nginx import Nginx
 
 project = WebProject().expose_as_module('project')
+project_u = WebProject({
+    'django': Django(Nginx(), Uwsgi(wsgi='django_wsgi.py'))
+}).expose_as_module('project_u')
 
 @define_host('foo@127.0.0.1:2222')
 def foo_site():

fab_deploy_tests/tests/deploy.py

 from fab_deploy.webserver.apache import Apache
 from .base import FabDeployTest
 from ..utils import setup_ssh, setup_sudo
-from ..test_project.fabfile import foo_site, bar_site, invalid_site, project
+from ..test_project.fabfile import foo_site, bar_site, invalid_site, project, project_u
 from ..test_project2.fabfile import foo_site as foo_site2, project as project2
 from ..test_project3.fabfile import postgis_site, postgres_site, project as project3
 
         self.assertFileExists(env.conf.ENV_DIR+'/var/wsgi/foo.py')
 
 
+class UwsgiSetupTest(FabDeployProjectTest):
+    snapshot = 'fabtest-prepared-uwsgi'
+    project = project_u
+
+    def test_uwsgi_config(self):
+        """
+        This test is somewhat singular to uWSGI. Server cannot be started
+        (and hence restarted) because of virtualenv and chdir options, that
+        point to non-existing (at this test) directories.
+        """
+
+        # first site
+        fab(foo_site)
+        fab(self.project.apps.django.backend.upload_config)
+        self.assertFileExists('/etc/uwsgi/apps-enabled/foo_uwsgi.ini')
+
+        # second site
+        fab(bar_site)
+        fab(self.project.apps.django.backend.upload_config)
+
+        fab(self.project.apps.django.backend.restart)
+
+        # re-configuring doesn't lead to errors
+        fab(self.project.apps.django.backend.upload_config)
+
+    def test_uwsgi_make_wsgi(self):
+        self.assertNoFile(env.conf.ENV_DIR+'/var/wsgi/foo/django_wsgi.py')
+        fab(self.project.apps.django.backend.upload_wsgi)
+        self.assertFileExists(env.conf.ENV_DIR+'/var/wsgi/foo.py')
+
+
 class DeployTest(FabDeployProjectTest):
 
     def test_deploy(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.