1. theoden
  2. django-fab-deploy


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.

  • Participants
  • Parent commits 5d29ed2
  • Branches default

Comments (0)

Files changed (5)

File docs/CHANGES.rst

View file
 - 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,

File fab_deploy/system.py

View file
         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 = f.read()
-    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 = 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)

File fab_deploy_tests/test_project2/fabfile.py

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

File fab_deploy_tests/tests/deploy.py

View file
 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/'
+        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 = 'http://foo.example.com/instance/'
         def before_restart():
             before_restart.called = True
             return push(*args, before_restart=before_restart)
+        setup_sudo()
+        setup_ssh()

File fab_deploy_tests/utils.py

View file
 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(create_sudo_linux_account, public_key_path())