Skip to content

Instantly share code, notes, and snippets.

@alq666
Created August 10, 2012 21:36
Show Gist options
  • Save alq666/3318245 to your computer and use it in GitHub Desktop.
Save alq666/3318245 to your computer and use it in GitHub Desktop.
Testing the fabric integration
easy_install fabric
python -c "import fabric; print fabric"
# <module 'fabric' from '.../python2.7/site-packages/Fabric-1.4.3-py2.7.egg/fabric/__init__.pyc'>
cd dogapi
fab -f examples/fabfile.py sweet_task:"yay!"
# My sweet task always runs properly.
#
# Done.
fab -f examples/fabfile.py boring_task:"oh noes"
fab -f examples/fabfile.py boring_task:"oh noes"
# My boring task is designed to fail.
# Traceback (most recent call last):
# ...
# File "build/bdist.macosx-10.8-intel/egg/dogapi/fab.py", line 72, in wrapper
# Exception: failure!!!
@alq666
Copy link
Author

alq666 commented Aug 10, 2012

And here's the result in Datadog (with annotations)

fabric

@jravetch
Copy link

Here's a snippet of my fabfile:

import os, sys
from fabric.api import *
from fabric.colors import *
from dogapi.fab import setup, notify

setup(api_key = "YOUR API KEY HERE")

sys.path.insert( 0, os.path.abspath( os.path.join( os.path.realpath( os.path.curdir ), '../' ) ) )
from lib.server_ip_map import ServerIpMap, ServerIpMapException
from lib.modenv_parser import ModEnvParser

sim = ServerIpMap('/srv/sys_restore/etc/server_ip_mappings.txt')
env.user = 'deployer'
env.roledefs = {'staging': sim.get_group('www-staging', 'external_ip'),
'qa': sim.get_group('www-qa', 'external_ip'),
'sandbox': sim.get_group('www-sandbox', 'external_ip'),
'assets-staging': sim.get_group('assets-staging', 'external_ip'),
'assets-qa': sim.get_group('assets-qa', 'external_ip'),
'assets-live': sim.get_group('assets-live', 'external_ip'),
'assets': sim.get_group('assets', 'external_ip'),
'live': sim.get_group('www-live', 'external_ip')}

env.roledefs['staging'].extend(env.roledefs['assets-staging'])
env.roledefs['qa'].extend(env.roledefs['assets-qa'])
env.roledefs['live'].extend(env.roledefs['assets-live'])

env.roledefs['staging'].reverse()
env.roledefs['qa'].reverse()
env.roledefs['live'].reverse()

env.parallel = 'True'
env.forward_agent = 'True'

def get_env():

if env.host_string in env.roledefs['staging'] and 'staging' in env.roles:
    return 'staging'
if env.host_string in env.roledefs['qa'] and 'qa' in env.roles:
    return 'qa'
elif env.host_string in env.roledefs['sandbox'] and 'sandbox' in env.roles:
    return 'sandbox'
elif env.host_string in env.roledefs['live'] and 'live' in env.roles:
    return 'live'
else:
    return false

def clean_modules(mods):
""" converts and cleans modules list based on which instance we're on. """

modules = [int(i) for i in mods.split(';')]
modenv = ModEnvParser(get_env())

if 0 in modules:
    # do all modules
    modules = modenv.get_all_modids()
    modules = modules.keys()

if env.host_string in env.roledefs['assets']:
    # we handle assets (id 5) uniquely
    modules = [x for x in modules if x == 5]
elif env.host_string not in env.roledefs['assets']:
    modules = [x for x in modules if x != 5]

return modules

@notify
@task
def update_sys_restore():
run('cd /srv/sys_restore && git pull')
print "\n"

@task
def host_type():
run('uname -a')
print "\n"

@alq666
Copy link
Author

alq666 commented Aug 13, 2012

Indeed the first @task gets discarded. I'm tracing it in the debugger.

@alq666
Copy link
Author

alq666 commented Aug 13, 2012

@task sorry this was not intended to notify you, it's a fabric construct...

@alq666
Copy link
Author

alq666 commented Aug 13, 2012

Fixed in 1.0.11 (being tested right now).

@alq666
Copy link
Author

alq666 commented Aug 13, 2012

Commit details: DataDog/dogapi@484850b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment