Beispiel #1
0
 def test_set_user_password(self):
     "Create user then set their password."
     with patch('argyle.postgres.change_db_user_password') as change_password:
         postgres.create_db_user('foo', password='******')
         self.assertSudoCommand('createuser -D -A -R foo')
         self.assertTrue(change_password.called)
         args, kwargs = change_password.call_args
         self.assertEqual(list(args), ['foo', 'bar'])
Beispiel #2
0
def setup_server(*roles):
    """Install packages and add configurations for server given roles."""
    require('environment')
    # Set server locale
    sudo('/usr/sbin/update-locale LANG=en_US.UTF-8')
    roles = list(roles)
    if roles == ['all', ]:
        roles = SERVER_ROLES
    if 'base' not in roles:
        roles.insert(0, 'base')
    install_packages(*roles)
    if 'db' in roles:
        if console.confirm(u"Do you want to reset the Postgres cluster?.", default=False):
            # Ensure the cluster is using UTF-8
            pg_version = postgres.detect_version()
            sudo('pg_dropcluster --stop %s main' % pg_version, user='******')
            sudo('pg_createcluster --start -e UTF-8 --locale en_US.UTF-8 %s main' % pg_version,
                 user='******')
        postgres.create_db_user(username=env.project_user)
        postgres.create_db(name=env.db, owner=env.project_user)
    if 'app' in roles:
        # Create project directories and install Python requirements
        project_run('mkdir -p %(root)s' % env)
        project_run('mkdir -p %(log_dir)s' % env)
        # FIXME: update to SSH as normal user and use sudo
        # we ssh as the project_user here to maintain ssh agent
        # forwarding, because it doesn't work with sudo. read:
        # http://serverfault.com/questions/107187/sudo-su-username-while-keeping-ssh-key-forwarding
        with settings(user=env.project_user):
            # TODO: Add known hosts prior to clone.
            # i.e. ssh -o StrictHostKeyChecking=no [email protected]
            run('git clone %(repo)s %(code_root)s' % env)
            with cd(env.code_root):
                run('git checkout %(branch)s' % env)
        # Install and create virtualenv
        with settings(hide('everything'), warn_only=True):
            test_for_pip = run('which pip')
        if not test_for_pip:
            sudo("easy_install -U pip")
        with settings(hide('everything'), warn_only=True):
            test_for_virtualenv = run('which virtualenv')
        if not test_for_virtualenv:
            sudo("pip install -U virtualenv")
        project_run('virtualenv -p python2.7 --clear --distribute %s' % env.virtualenv_root)
        path_file = os.path.join(env.virtualenv_root, 'lib', 'python2.7', 'site-packages', 'project.pth')
        files.append(path_file, env.code_root, use_sudo=True)
        sudo('chown %s:%s %s' % (env.project_user, env.project_user, path_file))
        sudo('npm install [email protected] -g')
        update_requirements()
        upload_supervisor_app_conf(app_name=u'gunicorn')
        upload_supervisor_app_conf(app_name=u'group')
        # Restart services to pickup changes
        supervisor_command('reload')
        supervisor_command('restart %(environment)s:*' % env)
    if 'lb' in roles:
        nginx.remove_default_site()
        nginx.upload_nginx_site_conf(site_name=u'%(project)s-%(environment)s.conf' % env)
Beispiel #3
0
 def test_set_user_password(self):
     "Create user then set their password."
     with patch(
             'argyle.postgres.change_db_user_password') as change_password:
         postgres.create_db_user('foo', password='******')
         self.assertSudoCommand('createuser -D -A -R foo')
         self.assertTrue(change_password.called)
         args, kwargs = change_password.call_args
         self.assertEqual(list(args), ['foo', 'bar'])
Beispiel #4
0
 def test_user_defaults(self):
     "Default flags for use creation."
     postgres.create_db_user('foo')
     self.assertSudoCommand('createuser -D -A -R foo')
     # Command should use the postgres user
     sudo = self.mocks['sudo']
     args, kwargs = sudo.call_args
     user = kwargs.get('user', None)
     self.assertEqual(user, 'postgres')
Beispiel #5
0
 def test_user_defaults(self):
     "Default flags for use creation."
     postgres.create_db_user('foo')
     self.assertSudoCommand('createuser -D -A -R foo')
     # Command should use the postgres user
     sudo = self.mocks['sudo']
     args, kwargs = sudo.call_args
     user = kwargs.get('user', None)
     self.assertEqual(user, 'postgres')
Beispiel #6
0
def setup_server(*roles):
    """Install packages and add configurations for server given roles."""
    require("environment")
    # Set server locale
    sudo("/usr/sbin/update-locale LANG=en_US.UTF-8")
    install_packages(*roles)
    if "db" in roles:
        if console.confirm(u"Do you want to reset the Postgres cluster?.", default=False):
            # Ensure the cluster is using UTF-8
            sudo("pg_dropcluster --stop 9.1 main", user="******")
            sudo("pg_createcluster --start -e UTF-8 9.1 main", user="******")
        postgres.create_db_user(username=env.project_user)
        postgres.create_db(name=env.db, owner=env.project_user)
    if "app" in roles:
        # Create project directories and install Python requirements
        project_run("mkdir -p %(root)s" % env)
        project_run("mkdir -p %(log_dir)s" % env)
        with settings(user=env.project_user):
            # TODO: Add known hosts prior to clone.
            # i.e. ssh -o StrictHostKeyChecking=no [email protected]
            sshagent_run("git clone %(repo)s %(code_root)s" % env)
        project_run("git checkout %(branch)s" % env)
        # Install and create virtualenv
        with settings(hide("everything"), warn_only=True):
            test_for_pip = run("which pip")
        if not test_for_pip:
            sudo("easy_install -U pip")
        with settings(hide("everything"), warn_only=True):
            test_for_virtualenv = run("which virtualenv")
        if not test_for_virtualenv:
            sudo("pip install -U virtualenv")
        project_run("virtualenv -p python2.6 --clear --distribute %s" % env.virtualenv_root)
        path_file = os.path.join(env.virtualenv_root, "lib", "python2.6", "site-packages", "project.pth")
        files.append(path_file, env.code_root, use_sudo=True)
        sudo("chown %s:%s %s" % (env.project_user, env.project_user, path_file))
        sudo("npm install less -g")
        update_requirements()
        upload_supervisor_app_conf(app_name=u"gunicorn")
        upload_supervisor_app_conf(app_name=u"group")
        # Restart services to pickup changes
        supervisor_command("reload")
        supervisor_command("restart %(environment)s:*" % env)
    if "lb" in roles:
        nginx.remove_default_site()
        nginx.upload_nginx_site_conf(site_name=u"%(project)s-%(environment)s.conf" % env)
Beispiel #7
0
 def test_change_user_flags(self):
     "Create user with different flags."
     postgres.create_db_user('foo', flags='-s')
     self.assertSudoCommand('createuser -s foo')
Beispiel #8
0
 def test_change_user_flags(self):
     "Create user with different flags."
     postgres.create_db_user('foo', flags='-s')
     self.assertSudoCommand('createuser -s foo')
Beispiel #9
0
def create_db_user():
    """Create the Postgres user."""

    require("environment", provided_by=env.environments)
    _load_passwords(["database_password"], generate=True)
    postgres.create_db_user(env.database_user, password=env.database_password)