Example #1
0
	def testResultAttributes( self ):
		failing_command = 'cat /etc/shadow'	# insufficient permissions
		succeeding_command = 'uname -a'
		erroneous_command = 'this-command-does-not-exist -a'

		# A successful command should have the appropriate status
		# attributes set
		result = cuisine.run(succeeding_command)
		self.assertTrue(result.succeeded)
		self.assertFalse(result.failed)
		self.assertEqual(result.return_code, 0)

		# With warn_only set, we should be able to examine the result
		# even if it fails
		with settings(warn_only=True):
			# command should fail with output to stderr
			result = cuisine.run(failing_command, combine_stderr=False)
			self.assertTrue(result.failed)
			self.assertFalse(result.succeeded)
			self.assertEqual(result.return_code, 1)
			self.assertIsNotNone(result.stderr)
			self.assertIn('Permission denied', result.stderr)

		# With warn_only off, failure should cause execution to abort
		with settings(warn_only=False):
			with self.assertRaises(SystemExit):
				cuisine.run(failing_command)

		# An erroneoneous command should fail similarly to fabric
		with settings(warn_only=True):
			result = cuisine.run(erroneous_command)
			self.assertTrue(result.failed)
			self.assertEqual(result.return_code, 127)
def install_nagiosgraph():
    cuisine.run('svn checkout --force http://svn.code.sf.net/p/nagiosgraph/code/trunk /tmp/nagiosgraph-code')
    cuisine.sudo('mkdir -p /opt/nagiosgraph/etc')
    cuisine.sudo('cp /tmp/nagiosgraph-code/nagiosgraph/lib/insert.pl /usr/local/nagios/libexec/insert.pl')
    cuisine.sudo('chown nagios.nagios /usr/local/nagios/libexec/insert.pl')
    cuisine.sudo('cp /tmp/nagiosgraph-code/nagiosgraph/cgi/*.cgi /usr/local/nagios/sbin')
    cuisine.sudo('chown -R nagios.nagios /usr/local/nagios/sbin')
    cuisine.sudo('cp /tmp/nagiosgraph-code/nagiosgraph/share/nagiosgraph.css /usr/local/nagios/share')
    cuisine.sudo('cp /tmp/nagiosgraph-code/nagiosgraph/share/nagiosgraph.js /usr/local/nagios/share')
    cuisine.sudo('chown -R nagios.nagios /usr/local/nagios/share')
    cuisine.sudo('cp /tmp/nagiosgraph-code/nagiosgraph/etc/* /opt/nagiosgraph/etc')
#    cuisine.sudo('mkdir -p /opt/nagiosgraph/etc/map')
#    cuisine.sudo('cp -r /tmp/nagiosgraph-code/nagiosgraph/etc/map/* /opt/nagiosgraph/etc/map')
    cuisine.file_upload('/opt/nagiosgraph/etc/nagiosgraph.conf','nagiosgraph.conf',sudo=True)
    cuisine.file_upload('/usr/local/nagios/etc/nagios.cfg','nagios.cfg',sudo=True)
    cuisine.file_upload('/usr/local/nagios/etc/objects/commands.cfg','commands.cfg',sudo=True)
    cuisine.file_upload('/usr/local/nagios/etc/objects/graphed_service.cfg','graphed_service.cfg',sudo=True)
    cuisine.sudo('mkdir -p /var/nagios')
    cuisine.sudo('chown nagios.nagios /var/nagios')
    cuisine.sudo('chmod 775 /var/nagios')
    cuisine.sudo('mkdir -p /var/nagios/rrd')
    cuisine.sudo('chown nagios.nagios /var/nagios/rrd')
    cuisine.sudo('chmod 775 /var/nagios/rrd')
    cuisine.sudo('touch /var/log/nagiosgraph.log')
    cuisine.sudo('chown nagios.nagios /var/log/nagiosgraph.log')
    cuisine.sudo('chmod 664 /var/log/nagiosgraph.log')
    cuisine.sudo('touch /var/log/nagiosgraph-cgi.log')
    cuisine.sudo('chown nagios.nagios /var/log/nagiosgraph-cgi.log')
    cuisine.sudo('chmod 664 /var/log/nagiosgraph-cgi.log')
    cuisine.sudo('cp /tmp/nagiosgraph-code/nagiosgraph/share/graph.gif /usr/local/nagios/share/images/action.gif')
    cuisine.file_upload('/usr/local/nagios/share/ssi/common-header.ssi', 'common-header.ssi', sudo=True)
    cuisine.file_upload('/usr/local/nagios/share/side.php', 'side.php', sudo=True)
Example #3
0
def crontab_add(schedule, script, cron_name, root=False):
    command = '(crontab -l; echo "%s %s && echo \'%s\'" ) | crontab -' % (
        schedule, script, cron_name)
    if root:
        sudo(command)
    else:
        run(command)
Example #4
0
def system_prep():
    """ pre-req process startup """
    env.user=ROOT_USER
    env.password=ROOT_PASS

    run("/etc/init.d/nginx restart")
    run("supervisorctl reload")
Example #5
0
def gunicorn_ensure(path, template, config, venv_path='.venv'):
    with virtualenv(path, venv_path):
        python_package_ensure('gunicorn')
        run("cp %s %s" % (template, config))
        file_update(config, lambda x: text_template(x,env))
        dir_ensure('%s/logs' % path)
        dir_ensure('%s/run' % path)
Example #6
0
def gunicorn_process_ensure(path, template, config, key_env, venv_path='.venv'):
    with virtualenv(path, venv_path):
        python_package_ensure('gunicorn')
        run("cp %s %s" % (template, config))
        file_update(config, lambda x: text_template(x,key_env))
        dir_ensure('%s/logs' % path)
        dir_ensure('%s/run' % path)
Example #7
0
def system_prep():
    """ pre-req process startup """
    env.user = ROOT_USER
    env.password = ROOT_PASS

    run("/etc/init.d/nginx restart")
    run("supervisorctl reload")
def _run(module,
         logger,
         task,
         completed_tasks,
         from_command_line=False,
         args=None,
         kwargs=None):
    """
    @type module: module
    @type logging: Logger
    @type task: Task
    @type completed_tasts: set Task
    @rtype: set Task
    @return: Updated set of completed tasks after satisfying all dependencies.
    """
    # Satsify dependencies recursively. Maintain set of completed tasks so each
    # task is only performed once.
    input_artifacts = {}
    for dependency in task.dependencies:
        _run(module, logger, dependency, completed_tasks)
        input_artifacts[dependency.name] = artifact_file(
            dependency.name, completed_tasks[dependency.name])

    # Perform current task, if need to.
    if from_command_line or task.name not in completed_tasks:

        if task.ignored:

            logger.info("Ignoring task \"%s\"" % task.name)
            cs = 'IGNORE'
        else:

            logger.info(yellow("Starting task \"%s\"" % task.name))
            try:
                # Run task.
                cs = checksum(module, input_artifacts, task.func,
                              task.watched_sources, args, kwargs)
                if cuisine.dir_exists(artifact_file(task.name, cs)):
                    logger.info("Nothing changed")
                else:
                    cuisine.dir_remove(artifact_dir(task.name))
                    cuisine.dir_ensure(artifact_dir(task.name))
                    cuisine.dir_remove(tmp_file(task.name))
                    cuisine.dir_ensure(tmp_file(task.name))
                    State.input_artifacts = input_artifacts
                    State.output_artifact = task.name
                    logger.info("Going to write an artifact with checksum " +
                                cs)
                    task(*(args or []), **(kwargs or {}))
                    cuisine.run("mv " + tmp_file(task.name) + " " +
                                artifact_file(task.name, cs))
            except:
                logger.critical("Error in task \"%s\"" % task.name)
                logger.critical("Aborting build")
                raise

            logger.info("Completed task " + task.name + " artifact path: " +
                        artifact_file(task.name, cs))

        completed_tasks[task.name] = cs
def service_ctl(service='listenerdaemon', command='start', use_sudo=False):
    cuisine.file_ensure(('/etc/init.d/%s' % service))
    cmd = str('/etc/init.d/%s %s' % (service, command))
    if use_sudo:
        cuisine.sudo(cmd, shell=False)
    else:
        cuisine.run(cmd, shell=False)
Example #10
0
def setup_os():
	with cuisine.mode_sudo():
		cuisine.ssh_authorize( "matze" , cuisine.file_local_read("./cuisine_id.pub"))
		for _ in PACKAGE_ENSURE: cuisine.package_ensure(_)
		cuisine.run("a2enmod rewrite")
		# TODO enable   AllowOverride none => all for /var/www
		cuisine.run("service apache2 restart")
def install_nagios_plugins_from_source():
    '''
    Downloads Nagios plugins source code and installs Nagios plugins on VM.
    '''
    if not nagios_plugins_downloaded():
        cuisine.sudo('wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz')
    cuisine.run('tar xzf nagios-plugins-2.0.3.tar.gz')
    cuisine.run('cd ~/nagios-plugins-2.0.3 && ./configure --with-nagios-user=nagios --with-nagios-group=nagios && make && make install', shell=False)
Example #12
0
def phpunit():

    if not cuisine.file_exists('/usr/bin/phpunit'):
        if package_installed('php-pear'):
            cuisine.run('pear config-set auto_discover 1')
            cuisine.run('pear install pear.phpunit.de/PHPUnit')
        else:
            print('PhpUnit install failed : PEAR is missing')
Example #13
0
def django_media_pull(project_path, local_media_path, remote_media_path):
    """ Overwrite local media files with remote ones """
    with cd(project_path), cd(remote_media_path):
        run('tar -czf /tmp/media.tar.gz *')
        get('/tmp/media.tar.gz', '/tmp/media.tar.gz')
    local("mkdir -p %s" % (local_media_path)) 
    local("rm -rf %s/*" % (local_media_path))
    local("tar -xf /tmp/media.tar.gz -C %s" % (local_media_path)) 
Example #14
0
def mongodb_ensure():
    with mode_sudo():
        if not run("cat /etc/apt/sources.list | grep '%s'" % (MONGO_REPO),
                   warn_only=True).succeeded:
            run("apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10"
                )
            run("add-apt-repository '%s'" % (MONGO_REPO))
            package_update()
        package_ensure("mongodb-org")
Example #15
0
def bower():
    """ Run bower install from bower.json"""

    puts(red('###############################'))
    puts(red('### Bower install'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        cuisine.run('bower install')
Example #16
0
def install_requirements():
    with cd('/vagrant'):
        if not exists('./requirements.txt'):
            return
        res = run('workon python27', quiet=True)
        if res.failed:
            run('mkvirtualenv python27 --python=/opt/python27/bin/python2.7')
        with prefix('workon python27'):
            run('pip install -r ./requirements.txt')
Example #17
0
def run_python_program(program=None, sudo=False):
    """
    Fabric task to run a Python program on a VM.
    """
    cuisine.file_ensure('/usr/bin/python')
    if sudo:
        cuisine.sudo(('/usr/bin/python %s' % program))
    else:
        cuisine.run(('/usr/bin/python %s' % program))
Example #18
0
	def testPath( self ):
		# Make sure the path is applied properly by setting it empty 
		# and making sure that stops a simple command from running
		self.assertTrue(cuisine.run('ls').succeeded)

		with fabric.api.path(' ', behavior='replace'), settings(warn_only=True):
			result = cuisine.run('ls', combine_stderr=False)
			self.assertTrue(result.failed)
			self.assertIn("command not found", result.stderr)
def run_python_program(program=None, sudo=False):
    """
    Fabric task to run a Python program on a VM.
    """
    cuisine.file_ensure('/usr/bin/python')
    if sudo:
        cuisine.sudo(('/usr/bin/python %s' % program))
    else:
        cuisine.run(('/usr/bin/python %s' % program))
Example #20
0
def runserver():
    """ Run python manage.py runserver 0.0.0.0:8000  """

    puts(red('###############################'))
    puts(red('### Runserver'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        cuisine.run('python manage.py runserver 0.0.0.0:8000')
Example #21
0
def ubuntu_setup():
    with cs.mode_sudo():
        if not cs.package_ensure_apt('zsh',update=True) :
            cs.run('chsh -s /bin/zsh')
        if not cs.package_ensure_apt('git',update=True) :
            pass
        cs.package_ensure_apt('vim-enhansed',update=True)
        cs.package_ensure_apt('gcc',update=True)
        cs.package_ensure_apt('make',update=True)
Example #22
0
def createsuperuser():
    """ Run python manage.py makemigrations"""

    puts(red('###############################'))
    puts(red('### Createsuperuser'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        cuisine.run('python manage.py createsuperuser')
Example #23
0
def compilemessages():
    """ Run python manage.py compilemessages """

    puts(red('###############################'))
    puts(red('### Compilemessages'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        cuisine.run('python manage.py compilemessages')
Example #24
0
def pip():
    """ Run pip install --user -r """

    puts(red('###############################'))
    puts(red('### Pip'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        cuisine.run('pip install --user -r requirements.txt')
Example #25
0
def debugsqlshell():
    """ Run python manage.py debugsqlshell """

    puts(red('###############################'))
    puts(red('### Debugsqlshell'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        cuisine.run('python manage.py debugsqlshell')
Example #26
0
def dotdeb():
    
    if not cuisine.file_exists('/etc/apt/sources.list.d/dotdeb.list'):
        sources = 'deb http://packages.dotdeb.org wheezy all\n \
        deb-src http://packages.dotdeb.org wheezy all'
        cuisine.file_write('/etc/apt/sources.list.d/dotdeb.list', sources, 644, 'root', 'root')
        with cd('/tmp'):
            cuisine.run('wget http://www.dotdeb.org/dotdeb.gpg')
            fabtools.deb.add_apt_key('dotdeb.gpg')
Example #27
0
def setup_package(package, virtualenv, options=''):
    #--index-url=http://c.pypi.python.org/simple
    pip_cmd_template = """
        source {virtualenv}/bin/activate;
        sh -c "pip install --upgrade pip";
        sh -c "export TEMP=/var/tmp; pip install --cache-dir=/var/cache/pip --verbose {options} {package}"
        """
    #sh -c "pip install --download-cache=/var/cache/pip --allow-all-external --allow-unverified=which --verbose {options} {package}"
    run(pip_cmd_template.format(**locals()))
Example #28
0
def bootstrap_virtualenv():
    """ install required packages """
    env.user=RTD_USER
    env.password=RTD_PASS

    run("source /opt/rtd/apps/readthedocs/current/bin/activate && pip install -r /opt/rtd/apps/readthedocs/current/readthedocs.org/pip_requirements.txt")
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py syncdb --noinput --settings=settings.prod")
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py migrate --noinput --settings=settings.prod")
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py collectstatic --noinput --settings=settings.prod")
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py create_api_user --settings=settings.prod")
Example #29
0
def django_cache_ensure(project_path,
                        project_name,
                        schedule,
                        venv_path='.venv'):
    script = "%s/bin/python %s/manage.py rebuild_index --noinput" % (
        os.path.join(project_path, venv_path), project_path)
    cron_name = "%s-cache" % project_name
    crontab_ensure(schedule, script, cron_name, root=True)
    with virtualenv(project_path, venv_path):
        run('python manage.py clear_cache')
def install_nrpe_plugin_from_source():
    '''
    Downloads NRPE plugin source code and installs NRPE plugin on VM.
    '''
    cuisine.package_ensure_apt('libssl-dev')
    cuisine.dir_ensure('/usr/local/src')
    cuisine.sudo('cd /usr/local/src')
    if not nrpe_plugins_downloaded():
        cuisine.sudo('wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz')
    cuisine.sudo('tar xzf nrpe-2.15.tar.gz')
    cuisine.run('cd ~/nrpe-2.15 && ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu && make all && make install-plugin')
Example #31
0
def deploy_plugin():
    files = []
    with cd('~/blogging/my_blog/addon-plugins'):
        pwd = run('pwd')
        for f in run("find . * -name *.rb | grep -v '^\.'").split():
            files.append(os.path.join(pwd, f))

    with cd('~/blogging/octopress/plugins'):
        with settings(warn_only=True):
            for f in files:
                sudo('ln -s %s .' % f)
def checksum(module, input_artifacts, func, watched_sources, args, kwargs):
    checksums = []
    checksums.append(str(input_artifacts))
    checksums.append(str(args if args else None))
    checksums.append(str(kwargs if kwargs else None))
    checksums.append(str(bytecode(module, func, {})))
    for watched_source in watched_sources:
        cuisine.run("git add -A " + watched_source)
        checksums.append(cuisine.run("git ls-files -s " + watched_source))
    cs = ",".join(checksums)
    return hashlib.sha256(cs).hexdigest()
Example #33
0
def deploy_plugin():
    files = []
    with cd('~/blogging/my_blog/addon-plugins'):
        pwd = run('pwd')
        for f in run("find . * -name *.rb | grep -v '^\.'").split():
            files.append(os.path.join(pwd, f))

    with cd('~/blogging/octopress/plugins'):
        with settings(warn_only=True):
            for f in files:
                sudo('ln -s %s .' % f)
Example #34
0
def startapp(app_name):
    """ Run python manage.py startapp name """

    puts(red('###############################'))
    puts(red('### Startapp'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        path = 'applications/%s' % app_name
        cuisine.run('mkdir %s' % path)
        cuisine.run('python manage.py startapp %s %s' % (app_name, path))
def checksum(module, input_artifacts, func, watched_sources, args, kwargs):
    checksums = []
    checksums.append(str(input_artifacts))
    checksums.append(str(args if args else None))
    checksums.append(str(kwargs if kwargs else None))
    checksums.append(str(bytecode(module, func, {})))  
    for watched_source in watched_sources:
        cuisine.run("git add -A " + watched_source)
        checksums.append(cuisine.run("git ls-files -s " + watched_source))
    cs = ",".join(checksums)
    return hashlib.sha256(cs).hexdigest()
Example #36
0
def makemigrations(app=None):
    """ Run python manage.py makemigrations"""

    puts(red('###############################'))
    puts(red('### Makemigrations'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        if app is not None:
            cuisine.run('python manage.py makemigrations %s' % app)
        else:
            cuisine.run('python manage.py makemigrations')
Example #37
0
def migrate(app=None):
    """ Run python manage.py migrate """

    puts(red('###############################'))
    puts(red('### Migrate'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        if app is not None:
            cuisine.run('python manage.py migrate %s' % app)
        else:
            cuisine.run('python manage.py migrate')
Example #38
0
def makemessages(lang=None):
    """ Run python manage.py makemessages """

    puts(red('###############################'))
    puts(red('### Makemessages'))
    puts(red('###############################'))

    with cuisine.cd(env.project_path):
        if lang is not None:
            cuisine.run('python manage.py makemessages -l %s' % lang)
        else:
            cuisine.run('python manage.py makemessages -a')
Example #39
0
def install(version, target):

    if not target:
        abort('Task argument "target" is required.')

    current_dir = os.path.dirname(__file__)
    project_path = current_dir
    pkg_version = setuptools_get_version(project_path)
    pkg_name = setuptools_get_name(project_path)

    if not version:
        version = pkg_version

    print('Installing package {0}, version {1} to target {2}.'.format(
        *list(map(yellow, [pkg_name, version, target]))))
    if env.confirm:
        response = ask('Proceed (y/n)? ', ('y', 'n'))
    else:
        response = 'y'

    if response == 'y':

        # From filesystem
        #source_package = '~/install/PatZilla/PatZilla-{version}.tar.gz'.format(version=version)

        # From PyPI
        source_package = 'patzilla=={version}'.format(version=version)
        source_config = './patzilla/config/production.ini.tpl'

        target_path = os.path.join(INSTALLATION_PATH, 'sites', target)
        dir_ensure(target_path, recursive=True)

        venv_path = target_path + '/.venv2'

        #if not file_is_file(source_package):
        #    abort('Source package does not exist: ' + source_package)

        if not file_is_dir(target_path):
            abort('Target path does not exist: ' + target_path)

        if not file_is_dir(venv_path):
            run('virtualenv --no-site-packages "{0}"'.format(venv_path))
            #setup_package('which', venv_path)
            # TODO: put these packages to a more convenient location

        setup_package(source_package, venv_path)

        upload_config(source_config, target_path)

        restart_service(target)

    else:
        print(yellow('Skipped package install due to user request.'))
Example #40
0
    def ssh_config(self, vm=None, host=None):
        with self.execution_context():
            # load info about the box to use as its context var
            with settings(warn_only=True):
                output = run('vagrant ssh-config %s' % (vm or '',))
                if output.failed:
                    modes = run('ls -la /usr/local/jenkins/jobs/build-vagrant-boxes/workspace/credentials/fabric_rsa')
                    abort(modes + self.read_vagrantfile() + output.stdout + output.stderr)

            ssh_info = output.splitlines()[1:]
            ssh_info = dict([l.strip().split(' ', 1)
                             for l in ssh_info if l.strip()])
            return {k.lower(): v for k, v in ssh_info.items()}
Example #41
0
def restart_service(target):
    uwsgi_names = {
        'develop': 'patentsearch-develop',
        'staging': 'patentsearch-staging',
        'prod': 'patentsearch-prod',
        'patoffice': 'patentsearch.patoffice',
        'vdpm': 'patentsearch.vdpm',
    }
    uwsgi_name = uwsgi_names.get(target, target)
    if uwsgi_name:
        run('service uwsgi reload %s' % uwsgi_name)
    else:
        print((red('WARNING: Could not restart service "%s"' % target)))
Example #42
0
def django_database_push(project_path, db_name, db_username, db_password,
                         config_template_path, config_path):
    """ Recreate and load local database to remote host"""
    local("python manage.py dumpdata > /tmp/db.json")
    with cd(project_path):
        put('/tmp/db.json', '/tmp/db.json')
    if postgresql_database_check(db_name):
        postgresql_database_drop(db_name)
    django_config_ensure(project_path, config_template_path, config_path)
    postgresql_ensure(db_name, db_username, project_path, db_password)
    django_database_ensure(project_path)
    with virtualenv(project_path):
        run("python manage.py loaddata /tmp/db.json")
Example #43
0
def dotfiles():
    dotfiles = [
        [".pryrc",              "~/.pryrc"],
        [".tigrc",              "~/.tigrc"],
        [".zshrc",              "~/.zshrc"],
        [".vimrc",              "~/.vimrc"],
        [".vimrc.yaml",         "~/.vimrc.yaml"],
        [".rbenv/default-gems", "~/.rbenv/default-gems"],
    ]
    git_clone("https://github.com/kazufusa/dotfiles", "~/dotfiles")
    with cuisine.cd("~"):
        for target, sym in dotfiles:
            cuisine.run("ln -sf ~/dotfiles/{} {}".format(target, sym))
Example #44
0
def django_database_push(project_path, db_name, db_username, db_password, config_template_path, config_path):
    """ Recreate and load local database to remote host"""
    local("python manage.py dumpdata > /tmp/db.json")
    with cd(project_path):
        put('/tmp/db.json', '/tmp/db.json')
    if postgresql_database_check(db_name):
        postgresql_database_drop(db_name)
    django_config_ensure(project_path,
        config_template_path,
        config_path)
    postgresql_ensure(db_name, db_username, project_path, db_password )
    django_database_ensure(project_path )    
    with virtualenv(project_path):
        run("python manage.py loaddata /tmp/db.json")
def _run(module, logger, task, completed_tasks, from_command_line = False, args = None, kwargs = None):
    """
    @type module: module
    @type logging: Logger
    @type task: Task
    @type completed_tasts: set Task
    @rtype: set Task
    @return: Updated set of completed tasks after satisfying all dependencies.
    """
    # Satsify dependencies recursively. Maintain set of completed tasks so each
    # task is only performed once.
    input_artifacts={}
    for dependency in task.dependencies:
        _run(module,logger,dependency, completed_tasks)
        input_artifacts[dependency.name] = artifact_file(dependency.name, completed_tasks[dependency.name])


    # Perform current task, if need to.
    if from_command_line or task.name not in completed_tasks:

        if task.ignored:
        
            logger.info("Ignoring task \"%s\"" % task.name)
            cs = 'IGNORE'
        else:

            logger.info(yellow("Starting task \"%s\"" % task.name))
            try:
                # Run task.
                cs = checksum(module, input_artifacts, task.func, task.watched_sources, args, kwargs)
                if cuisine.dir_exists(artifact_file(task.name, cs)):
                    logger.info("Nothing changed")
                else:
                    cuisine.dir_remove(artifact_dir(task.name))
                    cuisine.dir_ensure(artifact_dir(task.name))
                    cuisine.dir_remove(tmp_file(task.name))
                    cuisine.dir_ensure(tmp_file(task.name))
                    State.input_artifacts = input_artifacts
                    State.output_artifact = task.name
                    logger.info("Going to write an artifact with checksum " + cs)
                    task(*(args or []), **(kwargs or {}))
                    cuisine.run("mv " + tmp_file(task.name) + " " + artifact_file(task.name, cs))
            except:
                logger.critical("Error in task \"%s\"" % task.name)
                logger.critical("Aborting build")
                raise
            
            logger.info("Completed task " + task.name + " artifact path: " + artifact_file(task.name, cs))
        
        completed_tasks[task.name] = cs
Example #46
0
def configure_database(use_db_backend=True):
    """ creates the database """
    env.user = RTD_USER
    env.password = RTD_PASS

    if use_db_backend:
        run("mysql -u root -p'changeme123' -e \"%s\"" %
            (CREATE_DB_SQL % {
                'db_name': 'readthedocs'
            }))
        try:
            run("mysql -u root -p'changeme123' readthedocs -e \"%s\"" %
                (DELETE_USER_SQL % {
                    'db_user': '******'
                }))
        except:
            pass  # may fail the first time through
        run("mysql -u root -p'changeme123' readthedocs -e \"%s\"" %
            (CREATE_USER_SQL % {
                'db_user': '******',
                'db_password': '******'
            }))
        run("mysql -u root -p'changeme123' -e \"%s\"" %
            (GRANT_PERMISSIONS_SQL % {
                'db_user': '******',
                'db_name': 'readthedocs'
            }))
Example #47
0
def bootstrap_virtualenv():
    """ install required packages """
    env.user = RTD_USER
    env.password = RTD_PASS

    run("source /opt/rtd/apps/readthedocs/current/bin/activate && pip install -r /opt/rtd/apps/readthedocs/current/readthedocs.org/pip_requirements.txt"
        )
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py syncdb --noinput --settings=settings.prod"
        )
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py migrate --noinput --settings=settings.prod"
        )
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py collectstatic --noinput --settings=settings.prod"
        )
    run("source /opt/rtd/apps/readthedocs/current/bin/activate && /opt/rtd/apps/readthedocs/current/readthedocs.org/readthedocs/manage.py create_api_user --settings=settings.prod"
        )
def install_nagiosbpi():
    cuisine.sudo('rm -rf /tmp/nagios-nagiosbpi')
    cuisine.run('git clone git://git.code.sf.net/p/nagios/nagiosbpi /tmp/nagios-nagiosbpi')
    cuisine.run('cp -R /tmp/nagios-nagiosbpi/nagiosbpi /usr/local/nagios/share')
    cuisine.sudo('mkdir -p /usr/local/nagios/share/nagiosbpi/tmp')
    chmod_file('o+rx', '/usr/local/nagios/share/nagiosbpi/config_functions')
    chmod_file('o+rx', '/usr/local/nagios/share/nagiosbpi/functions')
    chmod_file('o+rx', '/usr/local/nagios/share/nagiosbpi/images')
    chmod_file('o+rx', '/usr/local/nagios/share/nagiosbpi/tmp')
    chmod_file('o+rxw', '/usr/local/nagios/share/nagiosbpi/tmp')
    cuisine.file_upload('/usr/local/nagios/share/nagiosbpi/constants.conf', 'constants.conf', sudo=True)
    chmod_file('+x', '/usr/local/nagios/share/nagiosbpi/set_bpi_perms.sh')
    chmod_file('777', '/usr/local/nagios/share/nagiosbpi/bpi.conf')
    chmod_file('-R 777', '/usr/local/nagios/share/nagiosbpi/tmp')
    chmod_file('+x', '/usr/local/nagios/share/nagiosbpi/check_bpi.php')
Example #49
0
 def create_virtualenv(self):
     with mode_sudo():
         dir_ensure(self.virtualenv_dir,
             owner=self.user_name,
             group=self.group_name,
             recursive=True,
             )
         with cd(self.virtualenv_dir):
             run('[[ -f bin/activate ]] || virtualenv .',
                 user=self.user_name)
             python_package_ensure_pip(r=os.sep.join((
                 self.repo_dir,
                 self.repo_django_root,
                 self.django_requirements_txt
             )))
Example #50
0
def make_virtualenv():
    """ builds project in virtual environment """
    env.user=RTD_USER
    env.password=RTD_PASS

    # build the virtualenv
    with cd("/opt/rtd/apps/readthedocs"):
        if not dir_exists("/opt/rtd/apps/readthedocs/%s" % RTD_INITIAL_VERSION):
            run("virtualenv %s" % RTD_INITIAL_VERSION)
        if not dir_exists("/opt/rtd/apps/readthedocs/current"):
            file_link("/opt/rtd/apps/readthedocs/%s" % RTD_INITIAL_VERSION, "/opt/rtd/apps/readthedocs/current")

    # clone the repo
    with cd("/opt/rtd/apps/readthedocs/%s" % RTD_INITIAL_VERSION):
        if not dir_exists("/opt/rtd/apps/readthedocs/%s/%s" % (RTD_INITIAL_VERSION, RTD_CLONE_NAME)):
            run("git clone %s %s" % ( RTD_CLONE, RTD_CLONE_NAME) )
def run(*args, **kwargs):
    print("Running command: " + blue(str(args[0])))
    start = time.clock()
    print(green(cuisine.run(args, kwargs)))
    end = time.clock()
    print("Elapsed time: " + str(end - start))
    print
Example #52
0
def set_symlinks():
    print white('--- set symlinks ---', bold=True)
    with cd('~/'):
        dotfiles = '''
            zshrc zshenv tmux.conf vimrc vim gitignore gitconfig gitattributes
        '''.split()
        map(lambda _: run('ln -sf dotfiles/_{0} .{0}'.format(_)), dotfiles)
Example #53
0
def installed_boxes():

    # Match lines like 'box-name (virtualbox)' with the parenthetical box type
    # being optional (added in vagrant 1.1 dev version)
    line_pattern = re.compile('^(?P<name>[^\s]+)(?:\s+\((?P<type>.*)\))?$')
    return [re.match(line_pattern, line).group('name')
            for line in run('vagrant box list').splitlines()]
Example #54
0
 def unregister(self, vm=None, delete=False):
     cmd = 'VBoxManage unregistervm %s' % self.uuid(vm=vm)
     if delete:
         cmd += ' --delete'
     with self.execution_context():
         result = run(cmd)
         return result
Example #55
0
def dir_attribs_recursive(location, mode=None, dir_mode=None, file_mode=None,
                          owner=None, group=None):
    '''Updates the mode/owner/group for the remote dir at the given
    location.'''
    if mode:
        cuisine.run('chmod -R {} "{}"'.format(mode, location))
    if dir_mode:
        cuisine.run('find "{}" -type d '
                    '-exec chmod {} {{}} \;'.format(location, dir_mode))
    if file_mode:
        cuisine.run('find "{}" -type f '
                    '-exec chmod {} {{}} \;'.format(location, file_mode))
    if owner:
        cuisine.run('chown -R {} "{}"'.format(owner, location))
    if group:
        cuisine.run('chgrp -R {} "{}"'.format(group, location))