Commits

Vladimir Mihailenco  committed 8d0ae0f Merge

Merge with kmike

  • Participants
  • Parent commits 609a75b, 2db5d84

Comments (0)

Files changed (9)

File docs/conf.py

 
 # The theme to use for HTML and HTML Help pages.  See the documentation for
 # a list of builtin themes.
-html_theme = 'sphinxdoc'
+# html_theme = 'sphinxdoc'
 
 # Theme options are theme-specific and customize the look and feel of a theme
 # further.  For a list of options available for each theme, see the

File fab_deploy/config_templates/nginx.config

 server {
     listen 80;
     server_name {{ SERVER_NAME }} www.{{ SERVER_NAME }};
-    access_log /var/log/nginx/{{ SERVER_NAME }}.access.log;
+    access_log /var/log/nginx/{{ INSTANCE_NAME }}.access.log;
     charset utf-8;
     client_max_body_size 8m;
 

File fab_deploy/django_commands.py

 def command_is_available(command):
     with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True):
         output = run('python manage.py help ' + command)
-    if output.failed:
-        with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True):
-            test_output = run('python manage.py')
-        if test_output.failed:
-            return True
-    return output.succeeded
+
+    if output.succeeded:
+        return True
+
+    # that's ugly
+    unknown_command_msg = "Unknown command: '%s'" % command
+    if unknown_command_msg in output:
+        return False
+
+    # re-raise the original exception
+    run('python manage.py help ' + command)
 
 @utils.inside_project
 def manage(command):
 
         fab manage:createsuperuser
     """
-    if not command_is_available(command):
-        warn('Management command "%s" is not available' % command)
+    command_name = command.split()[0]
+    if not command_is_available(command_name):
+        warn('Management command "%s" is not available' % command_name)
     else:
         run('python manage.py ' + command)
 

File fab_deploy/mysql.py

     os = utils.detect_os()
     system.aptitude_install('debconf-utils')
 
-    mysql_versions = {'lenny': '5.0', 'squeeze': '5.1', 'maverick': '5.1'}
+    mysql_versions = {
+        'lenny': '5.0',
+        'squeeze': '5.1',
+        'lucid': '5.1',
+        'maverick': '5.1',
+    }
     version = mysql_versions[os]
 
     debconf_defaults = [

File fab_deploy/system.py

     # git and mercurial are outdated in stable Debian Lenny and
     # don't work with some source repositories on github and bitbucket
     vcs_options = {'lenny': '-t lenny-backports'}
-    aptitude_install('mercurial git', vcs_options.get(os, ""))
+    aptitude_install('mercurial git git-core', vcs_options.get(os, ""))
     aptitude_install('bzr', '--without-recommends')
 
     sudo('easy_install -U pip')

File fab_deploy/utils.py

 from functools import wraps
 from fabric.api import *
 from fabric.contrib import files
+from fabric.utils import puts
 from fabric import state
 from fabric import network
 from fabric import operations

File fab_deploy_tests/test_project/config.server.py

     }
 }
 INSTANCE_NAME = '{{ INSTANCE_NAME }}'
+{{ EXTRA }}

File fab_deploy_tests/test_project/fabfile.py

         INSTANCE_NAME = 'bar',
     )
     update_env()
+
+def invalid_site():
+    env.hosts = ['foo@127.0.0.1:2222']
+    env.conf = dict(
+        DB_PASSWORD = '123',
+        VCS = 'none',
+        SERVER_NAME = 'invalid.example.com',
+        INSTANCE_NAME = 'invalid',
+        EXTRA = 'raise Exception()'
+    )
+    update_env()

File fab_deploy_tests/tests/deploy.py

 from __future__ import absolute_import
 import os
+from fabric.api import *
+from fabtest import fab, vbox_urlopen, FabricAbortException
 from fab_deploy.utils import run_as
-from fabric.api import *
-from fabtest import fab, vbox_urlopen
 from fab_deploy.deploy import deploy_project, push, undeploy
 from fab_deploy.mysql import mysql_create_db
 from fab_deploy.apache import (apache_make_config, apache_make_wsgi,
                                apache_restart, apache_install)
+from fab_deploy.django_commands import command_is_available
 from .base import FabDeployTest
 from ..utils import setup_ssh, setup_sudo
-from ..test_project.fabfile import foo_site, bar_site
+from ..test_project.fabfile import foo_site, bar_site, invalid_site
 from ..test_project2.fabfile import foo_site as foo_site2
 
 def get_file_content(remote_file):
     def assertResponse(self, url, data):
         self.assertEqual(vbox_urlopen(url).read(), data)
 
+    def assertHttpError(self, url):
+        # FIXME: this should only catch BadStatusLine and urllib2.HttpError
+        self.assertRaises(Exception, vbox_urlopen, url)
+
     def assertNoFile(self, path):
         with(settings(warn_only=True)):
             res = get_file_content(path)
         with(settings(warn_only=True)):
             self.assertTrue(get_file_content(path))
 
+    def assertCommandAvailable(self, command):
+        result = fab(command_is_available, command)
+        self.assertTrue(result[0])
+
+    def assertCommandNotAvailable(self, command):
+        result = fab(command_is_available, command)
+        self.assertFalse(result[0])
+
+    def assertCommandFails(self, command):
+        self.assertRaises(FabricAbortException, fab,
+                          command_is_available, command)
+
     def setup_conf(self):
         self.cwd = os.getcwd()
         os.chdir(self.project)
 
 class DeployTest(FabDeployProjectTest):
 
+    def assertInstanceWorks(self, instance):
+        url = 'http://%s.example.com/instance/' % instance
+        self.assertResponse(url, instance)
+
+    def assertInstanceDoesntWork(self, instance):
+        url = 'http://%s.example.com/instance/' % instance
+        self.assertHttpError(url)
+
     def test_deploy(self):
+        self.assertCommandFails('syncdb')
+
         # deploy first site
         fab(foo_site)
         fab(deploy_project)
 
-        # first site works
-        self.assertResponse('http://foo.example.com/instance/', 'foo')
+        self.assertCommandAvailable('syncdb')
+        self.assertCommandNotAvailable('syncddb')
+
+        self.assertInstanceWorks('foo')
 
         # deploy second site
         fab(bar_site)
         fab(deploy_project)
 
-        # second site works
-        self.assertResponse('http://bar.example.com/instance/', 'bar')
-        # first site is still available
-        self.assertResponse('http://foo.example.com/instance/', 'foo')
+        self.assertInstanceWorks('bar')
+        self.assertInstanceWorks('foo')
+
+        # deploy improperly configured site
+        fab(invalid_site)
+
+        # config errors should not be silenced
+        self.assertRaises(FabricAbortException, fab, deploy_project)
+
+        # old sites still work
+        self.assertInstanceWorks('bar')
+        self.assertInstanceWorks('foo')
+        self.assertInstanceDoesntWork('invalid')
 
 
 class CustomLayoutDeployTest(FabDeployProjectTest):
         # check that updeploy disables the site
         # TODO: more undeploy tests
         fab(undeploy, confirm=False)
-        self.assertRaises(Exception, vbox_urlopen, url)
+        self.assertHttpError(url)
 
         # deploying project again should be possible
         fab(deploy_project)