blob: 36b6e0599404122b9084cf37681a80f4c1b566b2 [file] [log] [blame]
#!/usr/bin/python -u
#
# Copyright 2007 Google Inc. Released under the GPL v2
"""
Run an autoserv control file
-m machine[,machine,machine] : specify machines to run on
-c : assume control file is a client control file
"""
__author__ = """
mbligh@google.com (Martin J. Bligh),
poirier@google.com (Benjamin Poirier),
stutsman@google.com (Ryan Stutsman)
"""
import sys, os
preamble = """\
import os, sys
import errors, hosts, autotest, kvm
import source_kernel, rpm_kernel, deb_kernel
from subcommand import *
from utils import run, get_tmp_dir, sh_escape
"""
client_wrapper = """
at = autotest.Autotest()
def run_client(machine):
host = hosts.SSHHost(machine)
at.run(control, host=host)
if len(machines) > 1:
parallel_simple(run_client, machines)
else:
run_client(machines[0])
"""
# Later, autotest.py will want to figure out what the top level autodir is.
# They won't be able to use abspath later, if we change directory - as it works
# relative to whatever your current path is. Hence we make argv[0] absolute now.
sys.argv[0] = os.path.abspath(sys.argv[0])
args = sys.argv[1:]
def run(control_file, machines, args, client):
namespace = dict({ 'machines' : machines, 'args' : args })
control = open(control_file, 'r').read()
if client:
namespace['control'] = control
exec(preamble + client_wrapper, namespace, namespace)
else:
exec(preamble + control, namespace, namespace)
def usage():
print "usage: autoserv [-c] <control file> [-m machine,[machine,...]] [args ...]"
sys.exit(1)
# We can't use the general getopt methods here, as there will be unknown
# extra arguments that we pass down into the control file instead.
# Thus we process the arguments by hand, for which we are duly repentant.
if args.count('-m'):
idx = args.index('-m')
machines = args[idx+1].split(',')
args[idx:idx+2] = [] # delete '-m machines'
else:
machines = None
if args.count('-c'):
client = True
idx = args.index('-c')
args[idx:idx+1] = [] # delete '-c'
else:
client = False
if len(args) < 1:
usage()
run(args[0], machines, args[1:], client)