Exemplo n.º 1
0
def test_git_require_sudo_user(gituser):
    """
    Test working_copy() with sudo as a user
    """

    from fabtools.require.git import working_copy

    username, groupname = gituser

    with cd('/tmp'):
        try:
            working_copy(REMOTE_URL,
                         path='wc_nobody',
                         use_sudo=True,
                         user=username)

            assert is_dir('wc_nobody')
            assert is_dir('wc_nobody/.git')

            with cd('wc_nobody'):
                remotes = sudo('git remote -v', user=username)
                assert remotes == \
                    'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                    'origin\thttps://github.com/disko/fabtools.git (push)'

                assert _current_branch() == 'master'

            assert owner('wc_nobody') == username
            assert group('wc_nobody') == groupname

        finally:
            run_as_root('rm -rf wc_nobody')
Exemplo n.º 2
0
def test_git_require_sudo_user(gituser):
    """
    Test working_copy() with sudo as a user
    """

    from fabtools.require.git import working_copy

    username, groupname = gituser

    with cd('/tmp'):
        try:
            working_copy(REMOTE_URL, path='wc_nobody', use_sudo=True, user=username)

            assert is_dir('wc_nobody')
            assert is_dir('wc_nobody/.git')

            with cd('wc_nobody'):
                remotes = sudo('git remote -v', user=username)
                assert remotes == \
                    'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                    'origin\thttps://github.com/disko/fabtools.git (push)'

                assert _current_branch() == 'master'

            assert owner('wc_nobody') == username
            assert group('wc_nobody') == groupname

        finally:
            run_as_root('rm -rf wc_nobody')
Exemplo n.º 3
0
def test_git_require_sudo():
    """
    Test working_copy() with sudo
    """

    from fabtools.require.git import working_copy

    try:
        working_copy(REMOTE_URL, path='wc_root', use_sudo=True)

        assert is_dir('wc_root')
        assert is_dir('wc_root/.git')

        with cd('wc_root'):
            remotes = run('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'

            assert _current_branch() == 'master'

        assert owner('wc_root') == 'root'
        assert group('wc_root') == 'root'

    finally:
        run_as_root('rm -rf wc_root')
Exemplo n.º 4
0
def test_git_require_sudo():
    """
    Test working_copy() with sudo
    """

    from fabtools.require.git import working_copy

    try:
        working_copy(REMOTE_URL, path='wc_root', use_sudo=True)

        assert is_dir('wc_root')
        assert is_dir('wc_root/.git')

        with cd('wc_root'):
            remotes = run('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'

            assert _current_branch() == 'master'

        assert owner('wc_root') == 'root'
        assert group('wc_root') == 'root'

    finally:
        run_as_root('rm -rf wc_root')
Exemplo n.º 5
0
def setup_dotfiles():
    if files.is_dir('$HOME/dotfiles') and not files.is_dir('$HOME/.dotfiles'):
        install_dotfiles()
        run('mv $HOME/dotfiles/ $HOME/.dotfiles')
        with cd('$HOME/.dotfiles'):
            run('bash bash_setup.sh')
        with cd('$HOME/.dotfiles/.vim/bundle'):
            run('rm -rf neobundle.vim')
            git.working_copy('https://github.com/Shougo/neobundle.vim.git')
Exemplo n.º 6
0
 def repository_pull_clone_and_checkout(self, update=True):
     _logger.info("Updateing/getting repository %s with update=%s" % (
         self.repository_id.name, update))
     if self.repository_id.error_message:
         raise ValidationError(self.repository_id.error_message)
     if self.actual_commit and not update:
         return True
     self.instance_id.environment_id.server_id.get_env()
     path = self.path
     if self.sources_from_id:
         # check if repository exists
         source_repository = self.search([
             ('repository_id', '=', self.repository_id.id),
             ('instance_id', '=', self.sources_from_id.id),
         ], limit=1)
         if not source_repository:
             raise ValidationError(_(
                 'Source repository not found for %s on instance %s') % (
                 self.repository_id.name, self.sources_from_id.name))
         if source_repository.branch_id != self.branch_id:
             raise ValidationError(_(
                 'Source repository branch and target branch must be the '
                 'same\n'
                 '* Source repository branch: %s\n'
                 '* Target repository branch: %s\n') % (
                 source_repository.branch_id.name, self.branch_id.name))
         actual_commit = "%s / %s" % (
             source_repository.actual_commit,
             fields.Datetime.to_string(
                 fields.Datetime.context_timestamp(self, datetime.now())))
         remote_url = os.path.join(
             self.sources_from_id.sources_path,
             self.repository_id.directory
         )
     else:
         remote_url = self.repository_id.url
         actual_commit = fields.Datetime.to_string(
             fields.Datetime.context_timestamp(self, datetime.now()))
     try:
         # TODO mejorar aca y usar la api de github para pasar depth = 1 y
         # manejar errores
         working_copy(
             remote_url,
             path=path,
             branch=self.branch_id.name,
             update=update,
         )
         self._cr.commit()
     except Exception, e:
         raise ValidationError(_(
             'Error pulling git repository. This is what we get:\n'
             '%s' % e))
Exemplo n.º 7
0
def install_dev():
    """To install"""
    with cd("~%s" % USER):
        working_copy(REPO_URI, use_sudo=True, user=USER)
    with cd(PATH):
        sudo('make install_integration', user=USER)
        with virtualenv('.'):
            sudo('make assets', user=USER)
        sudo('ln -s %s/etc/nginx.conf /etc/nginx/sites-enabled/%s' %
             (PATH, CONF_NAME))
        sudo('ln -s %s/etc/monit.conf /etc/monit/conf.d/%s' %
             (PATH, CONF_NAME))
        sudo('service nginx reload')
        sudo('monit reload')
 def repository_pull_clone_and_checkout(self, update=True):
     _logger.info("Updateing/getting repository %s with update=%s" % (
         self.repository_id.name, update))
     if self.actual_commit and not update:
         return True
     self.instance_id.environment_id.server_id.get_env()
     path = self.path
     if self.sources_from_id:
         # check if repository exists
         source_repository = self.search([
             ('repository_id', '=', self.repository_id.id),
             ('instance_id', '=', self.sources_from_id.id),
             ], limit=1)
         if not source_repository:
             raise Warning(_(
                 'Source repository not found for %s on instance %s') % (
                 self.repository_id.name, self.sources_from_id.name))
         if source_repository.branch_id != self.branch_id:
             raise Warning(_(
                 'Source repository branch and target branch must be the '
                 'same\n'
                 '* Source repository branch: %s\n'
                 '* Target repository branch: %s\n') % (
                 source_repository.branch_id.name, self.branch_id.name))
         actual_commit = "%s / %s" % (
             source_repository.actual_commit,
             fields.Datetime.to_string(
                 fields.Datetime.context_timestamp(self, datetime.now())))
         remote_url = os.path.join(
             self.sources_from_id.sources_path,
             self.repository_id.directory
             )
     else:
         remote_url = self.repository_id.url
         actual_commit = fields.Datetime.to_string(
             fields.Datetime.context_timestamp(self, datetime.now()))
     try:
         # TODO mejorar aca y usar la api de github para pasar depth = 1 y
         # manejar errores
         working_copy(
             remote_url,
             path=path,
             branch=self.branch_id.name,
             update=update,
             )
     except Exception, e:
         raise Warning(_('Error pulling git repository. This is what we get:\
             \n%s' % e))
Exemplo n.º 9
0
def deploy(lookup_param='prod', pip='install'):
    with cd(env.home_dir):
        files.directory(env.project_root, mode='750')
        files.directory(env.shared, mode='750')
        with cd(env.shared):
            files.directory('.pip.cache', mode='750')
            files.directory('db', mode='750')
            files.directory('log', mode='750')
            files.directory('pids', mode='750')
            files.directory('system', mode='750')
            files.directory('media', mode='750')
    with cd(env.project_root):
        git.working_copy(env.repository, env.root, branch=env.config['www']['branch'])
        with cd(env.root):
            if not exists('db'):
                run('ln -s {0}/{1} {2}/'.format(env.shared, 'db', env.root))
            if not exists('log'):
                run('ln -s {0}/{1} {2}/'.format(env.shared, 'log', env.root))
            if not exists('public/media'):
                run('ln -s {0}/{1} {2}/public/'.format(env.shared, 'media', env.root))
            execute(libs, lookup_param=lookup_param, pip=pip)
Exemplo n.º 10
0
def test_git_require_no_update():
    """
    Test working_copy() with update=False
    """

    from fabtools.require.git import working_copy

    try:
        working_copy(REMOTE_URL, path='wc')

        run('tar -c -f wc_old.tar --exclude .git wc')
        old_md5 = md5sum('wc_old.tar')

        working_copy(REMOTE_URL, path='wc', update=False)

        # Test that the working tree was not updated
        run('tar -c -f wc_new.tar --exclude .git wc')
        new_md5 = md5sum('wc_new.tar')
        assert old_md5 == new_md5

    finally:
        run('rm -rf wc')
Exemplo n.º 11
0
def test_git_require_no_update():
    """
    Test working_copy() with update=False
    """

    from fabtools.require.git import working_copy

    try:
        working_copy(REMOTE_URL, path='wc')

        run('tar -c -f wc_old.tar --exclude .git wc')
        old_md5 = md5sum('wc_old.tar')

        working_copy(REMOTE_URL, path='wc', update=False)

        # Test that the working tree was not updated
        run('tar -c -f wc_new.tar --exclude .git wc')
        new_md5 = md5sum('wc_new.tar')
        assert old_md5 == new_md5

    finally:
        run('rm -rf wc')
Exemplo n.º 12
0
def test_git_require_remote_url():
    """
    Test with remote URL only
    """

    from fabtools.require.git import working_copy

    try:
        working_copy(REMOTE_URL)

        assert is_dir('fabtools')
        assert is_dir('fabtools/.git')

        with cd('fabtools'):
            remotes = run('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'

            assert _current_branch() == 'master'

    finally:
        run('rm -rf fabtools')
Exemplo n.º 13
0
def test_git_require_remote_url_and_path():
    """
    Test working_copy() with remote URL and path
    """

    from fabtools.require.git import working_copy

    try:
        working_copy(REMOTE_URL, path='wc')

        assert is_dir('wc')
        assert is_dir('wc/.git')

        with cd('wc'):
            remotes = run('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'

            assert _current_branch() == 'master'

    finally:
        run('rm -rf wc')
Exemplo n.º 14
0
def test_git_require_branch():
    """
    Test checkout of a branch
    """

    from fabtools.require.git import working_copy

    try:
        working_copy(REMOTE_URL, path='wc', branch='test_git')

        assert is_dir('wc')
        assert is_dir('wc/.git')

        with cd('wc'):
            remotes = run('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'

            assert _current_branch() == 'test_git'

    finally:
        run('rm -rf wc')
Exemplo n.º 15
0
def git_require():
    """ Test high level git tools.  These tests should also cover the low level
        tools as all of them are called indirectly. """

    require.deb.package('git')

    from fabtools.require.git import working_copy

    with cd('/tmp'):
        # clean up...
        sudo('rm -rf *')

        # working_copy(remote_url, path=None, branch="master", update=True,
        #              use_sudo=False, user=None)

        # Test with remote_url only
        working_copy(remote_url)
        assert is_dir('fabtools')
        assert is_dir('fabtools/.git')
        with cd('fabtools'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'

        # Test with remote_url and path
        working_copy(remote_url, path='wc')
        assert is_dir('wc')
        assert is_dir('wc/.git')
        with cd('wc'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'

        # Test that nothing is upated
        sudo('tar cf wc_old.tar wc')
        old_md5 = sudo('md5sum wc_old.tar').split(' ')[0]
        working_copy(remote_url, path='wc', update=False)
        sudo('tar cf wc_new.tar wc')
        new_md5 = sudo('md5sum wc_new.tar').split(' ')[0]
        assert old_md5 == new_md5

        # Test checkout of a branch
        working_copy(remote_url, path='wc', branch="test_git")
        assert is_dir('wc')
        assert is_dir('wc/.git')
        with cd('wc'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == 'master\r\n* test_git'

        # Test use_sudo without user
        working_copy(remote_url, path='wc_root', use_sudo=True)
        assert is_dir('wc_root')
        assert is_dir('wc_root/.git')
        with cd('wc_root'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'
        assert owner('wc_root') == 'root'
        assert group('wc_root') == 'root'

        # Test use_sudo with user nobody
        working_copy(remote_url, path='wc_nobody', use_sudo=True,
                     user='******')
        assert is_dir('wc_nobody')
        assert is_dir('wc_nobody/.git')
        with cd('wc_nobody'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'
        assert owner('wc_nobody') == 'nobody'
        assert group('wc_nobody') == 'nogroup'
Exemplo n.º 16
0
def git_require():
    """ Test high level git tools.  These tests should also cover the low level
        tools as all of them are called indirectly. """

    from fabric.api import cd, sudo

    from fabtools import require
    from fabtools.files import group, is_dir, owner
    from fabtools.system import distrib_family

    from fabtools.require.git import working_copy

    family = distrib_family()
    if family == 'debian':
        require.deb.package('git-core')
    elif family == 'redhat':
        require.rpm.package('git')

    with cd('/tmp'):
        # clean up...
        sudo('rm -rf *')

        # working_copy(remote_url, path=None, branch="master", update=True,
        #              use_sudo=False, user=None)

        # Test with remote_url only
        working_copy(remote_url)
        assert is_dir('fabtools')
        assert is_dir('fabtools/.git')
        with cd('fabtools'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'

        # Test with remote_url and path
        working_copy(remote_url, path='wc')
        assert is_dir('wc')
        assert is_dir('wc/.git')
        with cd('wc'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'

        # Test that nothing is upated
        sudo('tar cf wc_old.tar wc')
        old_md5 = sudo('md5sum wc_old.tar').split(' ')[0]
        working_copy(remote_url, path='wc', update=False)
        sudo('tar cf wc_new.tar wc')
        new_md5 = sudo('md5sum wc_new.tar').split(' ')[0]
        assert old_md5 == new_md5

        # Test checkout of a branch
        working_copy(remote_url, path='wc', branch="test_git")
        assert is_dir('wc')
        assert is_dir('wc/.git')
        with cd('wc'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == 'master\r\n* test_git'

        # Test use_sudo without user
        working_copy(remote_url, path='wc_root', use_sudo=True)
        assert is_dir('wc_root')
        assert is_dir('wc_root/.git')
        with cd('wc_root'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'
        assert owner('wc_root') == 'root'
        assert group('wc_root') == 'root'

        # Test use_sudo with user nobody
        working_copy(remote_url,
                     path='wc_nobody',
                     use_sudo=True,
                     user='******')
        assert is_dir('wc_nobody')
        assert is_dir('wc_nobody/.git')
        with cd('wc_nobody'):
            remotes = sudo('git remote -v')
            assert remotes == \
                'origin\thttps://github.com/disko/fabtools.git (fetch)\r\n' \
                'origin\thttps://github.com/disko/fabtools.git (push)'
            branch = sudo('git branch')
            assert branch == '* master'
        assert owner('wc_nobody') == 'nobody'
        if family == 'debian':
            assert group('wc_nobody') == 'nogroup'
        elif family == 'redhat':
            assert group('wc_nobody') == 'nobody'
Exemplo n.º 17
0
def install_dotfiles():
    git.working_copy('https://github.com/takuan-osho/dotfiles.git',
                     path='$HOME/dotfiles')