Commits

Mikhail Korobov committed 8a77b23

test_project2 is converted to use SUDO_USER. Fix #21. The test reveals permissions problems with setup_pip_conf during create_sudo_linux_account. It looks like fabric bug (temporary file storage is too deterministic) but in order to make things work pip.conf setup is removed from create_sudo_linux_account now.

Comments (0)

Files changed (5)

 - requirement for root ssh access is removed: django-fab-deploy is now using
   sudo internally (thanks Vladimir Mihailenco);
 - hgrc is no more required;
-- utils.detect_os is now failing loudly if detection fails;
+- ``utils.detect_os`` is now failing loudly if detection fails;
 - test running improvements.
 
 In order to upgrade from previous verions of django-fab-deploy,

fab_deploy/system.py

         sudo('aptitude update')
 
 @utils.run_as_sudo
-def create_linux_account(pub_key_file):
+def create_linux_account(pub_key_file, username=None):
     """ Creates linux account, setups ssh access and pip.conf file. """
     with open(os.path.normpath(pub_key_file), 'rt') as f:
         ssh_key = f.read()
 
-    username = env.conf.USER
+    username = username or env.conf.USER
 
     @utils.run_as(username)
     def setup_pip_conf():
 
 @utils.run_as('root')
 def create_sudo_linux_account(pub_key_file, username=None):
-    if username is None:
-        username = env.conf.SUDO_USER
+    username = username or env.conf.SUDO_USER
+    if username == 'root':
+        return
+
     home_dir = '/home/%s' % username
 
     with open(os.path.normpath(pub_key_file), 'rt') as f:
         ssh_key = f.read()
 
-    @utils.run_as(username)
-    def setup_pip_conf():
-        from fab_deploy import virtualenv
-        virtualenv.pip_setup_conf()
-
     with (settings(warn_only=True)):
         run('adduser %s --disabled-password --gecos ""' % username)
         with cd(home_dir):
             run('mkdir -p .ssh')
             files.append('.ssh/authorized_keys', ssh_key)
             run('chown -R %s:%s .ssh' % (username, username))
-        setup_pip_conf()
 
     line = '%s ALL=(ALL) NOPASSWD: ALL' % username
     files.append('/etc/sudoers', line)

fab_deploy_tests/test_project2/fabfile.py

 )
 
 def foo_site():
-    env.hosts = ['foo@127.0.0.1:2222']
+    env.hosts = ['foo2@127.0.0.1:2222']
     env.conf = dict(
         DB_PASSWORD = '123',
         VCS = 'git',
         SERVER_NAME = 'foo.example.com',
+        SUDO_USER = 'sudouser',
     )
     env.conf.update(LAYOUT_OPTIONS)
     update_env()

fab_deploy_tests/tests/deploy.py

 from fab_deploy.apache import (apache_make_config, apache_make_wsgi,
                                apache_restart, apache_install)
 from .base import FabDeployTest
+from ..utils import setup_ssh, setup_sudo
 from ..test_project.fabfile import foo_site, bar_site
 from ..test_project2.fabfile import foo_site as foo_site2
 
 class CustomLayoutDeployTest(FabDeployProjectTest):
     project = 'test_project2'
 
+    def setUp(self):
+        super(CustomLayoutDeployTest, self).setUp()
+
     def test_deploy(self):
         url = 'http://foo.example.com/instance/'
         fab(foo_site2)
+
+        setup_sudo()
+        setup_ssh()
+
         fab(deploy_project)
-        self.assertResponse(url, 'foo')
+        self.assertResponse(url, 'foo2')
 
         # just check that blank push doesn't break anything
         # TODO: proper push tests
         fab(push, 'pip_update', 'syncdb')
-        self.assertResponse(url, 'foo')
+        self.assertResponse(url, 'foo2')
 
         # check that updeploy disables the site
         # TODO: more undeploy tests
 
         # deploying project again should be possible
         fab(deploy_project)
-        self.assertResponse(url, 'foo')
+        self.assertResponse(url, 'foo2')
 
     def test_push_callback(self):
-        url = 'http://foo.example.com/instance/'
 
         def before_restart():
             before_restart.called = True
             return push(*args, before_restart=before_restart)
 
         fab(foo_site2)
+
+        setup_sudo()
+        setup_ssh()
+
         fab(deploy_project)
         fab(my_push)
         self.assertTrue(before_restart.called)

fab_deploy_tests/utils.py

 from fabric.api import run
 from fabtest import fab
 from fab_deploy.utils import run_as
-from fab_deploy.system import create_linux_account, install_sudo
+from fab_deploy.system import create_linux_account, install_sudo, create_sudo_linux_account
 
 def public_key_path():
     return os.path.join(os.path.dirname(__file__), 'keys', 'id_rsa.pub')
 
 def setup_sudo():
     fab(install_sudo)
+    fab(create_sudo_linux_account, public_key_path())