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,


         sudo('aptitude update')
-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 =
-    username = env.conf.USER
+    username = username or env.conf.USER
     def setup_pip_conf():
 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 =
-    @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)


 def foo_site():
-    env.hosts = ['foo@']
+    env.hosts = ['foo2@']
     env.conf = dict(
         DB_PASSWORD = '123',
         VCS = 'git',
         SERVER_NAME = '',
+        SUDO_USER = 'sudouser',


 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 = ''
+        setup_sudo()
+        setup_ssh()
-        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
-        self.assertResponse(url, 'foo')
+        self.assertResponse(url, 'foo2')
     def test_push_callback(self):
-        url = ''
         def before_restart():
             before_restart.called = True
             return push(*args, before_restart=before_restart)
+        setup_sudo()
+        setup_ssh()


 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', '')
 def setup_sudo():
+    fab(create_sudo_linux_account, public_key_path())