Permalink
Browse files

Bug 825140 - Utilize per_device actions in fabric for foopies and add…

… a what_master action. r=armenzg r=coop

--HG--
extra : rebase_source : bfd9eaebd3b87f4423bc60e7195d576ab2039a39
  • Loading branch information...
1 parent a44415d commit 71027bdd0eaeec2821490a1d35bf4872d0dab810 @Callek Callek committed Dec 19, 2012
Showing with 84 additions and 34 deletions.
  1. +68 −33 buildfarm/maintenance/foopy_fabric.py
  2. +16 −1 buildfarm/maintenance/manage_foopies.py
@@ -1,33 +1,68 @@
-from fabric.api import run
-from fabric.context_managers import cd, hide, show
-from fabric.colors import green
-
-OK = green('[OK]')
-
-def show_revision(foopy):
- with hide('stdout', 'stderr', 'running'):
- tools_rev = run('hg -R /builds/tools ident -i')
-
- print "%-14s %12s" % (foopy, tools_rev)
-
-def update(foopy):
- with show('running'):
- with cd('/builds/tools'):
- run('hg pull && hg update -C')
- with hide('stdout', 'stderr', 'running'):
- tools_rev = run('hg ident -i')
-
- print OK, "updated %s tools to %12s" % (foopy, tools_rev)
-
-def stop_cp(foopy):
- with show('running'):
- with cd('/builds'):
- run('./stop_cp.sh')
-
- print OK, "Stopped all cp on %s" % foopy
-
-actions = [
- 'show_revision',
- 'update',
- 'stop_cp',
- ]
+from fabric.api import run
+from fabric.context_managers import cd, hide, show
+from fabric.context_managers import settings
+from fabric.colors import green, yellow, red
+
+OK = green('[OK] ')
+FAIL = red('[FAIL]')
+INFO = yellow('[INFO]')
+
+def per_host(fn):
+ fn.per_host = True
+ return fn
+
+def per_device(fn):
+ fn.per_device = True
+ return fn
+
+@per_host
+def show_revision(foopy):
+ with hide('stdout', 'stderr', 'running'):
+ tools_rev = run('hg -R /builds/tools ident -i')
+
+ print "%-14s %12s" % (foopy, tools_rev)
+
+@per_host
+def update(foopy):
+ with show('running'):
+ with cd('/builds/tools'):
+ run('hg pull && hg update -C')
+ with hide('stdout', 'stderr', 'running'):
+ tools_rev = run('hg ident -i')
+
+ print OK, "updated %s tools to %12s" % (foopy, tools_rev)
+
+@per_device
+def stop_cp(device):
+ with show('running'):
+ with cd('/builds'):
+ run('./stop_cp.sh %s' % device)
+ print OK, "Stopped clientproxy for %s" % (device)
+
+@per_device
+def what_master(device):
+ import re
+ with hide('stdout', 'stderr', 'running'):
+ with cd('/builds'):
+ tac_path = './%s/buildbot.tac' % device
+ tac_exists = False
+ with settings(hide('everything'), warn_only=True):
+ tac_exists = not run('test -e "$(echo %s)"' % tac_path).failed
+ if tac_exists:
+ output = run('cat %s | grep "^buildmaster_host"' % tac_path)
+ m = re.search('^buildmaster_host\s*=\s*([\'"])(.*)[\'"]', output, re.M)
+ if not m:
+ print FAIL, "Failed to parse buildbot.tac:", repr(output)
+ master = "No Master"
+ else:
+ master = m.group(2)
+ else:
+ master = "No Master"
+ print OK, "%s uses %s" % (device, master)
+
+actions = [
+ 'what_master',
+ 'show_revision',
+ 'update',
+ 'stop_cp',
+ ]
@@ -69,7 +69,22 @@ def run_action_on_foopy(action, foopy):
return False
def run_action_on_devices(action, foopy_dict):
- print FAIL, "Per-Device Actions not yet supported"
+ atfork()
+ action_func = getattr(foopy_fabric, action)
+ try:
+ with settings(host_string="%s.build.mozilla.org" % foopy_dict['host']):
+ for device in foopy_dict['devices']:
+ action_func(device)
+ return True
+ return False
+ except AttributeError:
+ print FAIL, "[%s] %s action is not defined." % (foopy_dict['host'], action)
+ return False
+ except:
+ import traceback
+ print "Failed to run", action, "on", foopy_dict['host']
+ print traceback.format_exc()
+ return False
if __name__ == '__main__':
from optparse import OptionParser

0 comments on commit 71027bd

Please sign in to comment.