Adds a -G to autoserv to be able to set host_group_name in the group keyvals
file that it writes. Useful only if someone has asked autoserv to run the
parser itself.
The scheduler does not need this as it will write that keyvals entry itself.
Adds a unittest for autoserv_parser and fixes a minor bug in --args support.
Signed-off-by: Gregory Smith <[email protected]>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3137 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/autoserv b/server/autoserv
index b8c69e5..bd32cf8 100755
--- a/server/autoserv
+++ b/server/autoserv
@@ -41,6 +41,7 @@
machines = []
machines_file = parser.options.machines_file
label = parser.options.label
+ group_name = parser.options.group_name
user = parser.options.user
client = parser.options.client
server = parser.options.server
@@ -91,9 +92,15 @@
machines = list(set(machines))
machines.sort()
+ if group_name and len(machines) < 2:
+ print ("-G %r may only be supplied with more than one machine."
+ % group_name)
+ sys.exit(1)
+
job = server_job.server_job(control, parser.args[1:], results, label,
user, machines, client, parse_job,
- ssh_user, ssh_port, ssh_pass)
+ ssh_user, ssh_port, ssh_pass,
+ group_name=group_name)
if results:
debug_dir = os.path.join(results, 'debug')
stdout = os.path.join(debug_dir, 'autoserv.stdout')
diff --git a/server/autoserv_parser.py b/server/autoserv_parser.py
index b402e6c..aaf0676 100644
--- a/server/autoserv_parser.py
+++ b/server/autoserv_parser.py
@@ -42,6 +42,9 @@
self.parser.add_option("-l", action="store", type="string",
dest="label", default='',
help="label for the job")
+ self.parser.add_option("-G", action="store", type="string",
+ dest="group_name", default='',
+ help="The host_group_name to store in keyvals")
self.parser.add_option("-u", action="store", type="string",
dest="user",
default=os.environ.get('USER'),
@@ -110,7 +113,7 @@
def parse_args(self):
self.options, self.args = self.parser.parse_args()
if self.options.args:
- self.args += self.options.args.split(' ')
+ self.args += self.options.args.split()
site_autoserv_parser = utils.import_site_class(
diff --git a/server/autoserv_parser_unittest.py b/server/autoserv_parser_unittest.py
new file mode 100644
index 0000000..87e1824
--- /dev/null
+++ b/server/autoserv_parser_unittest.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+"""Tests for autoserv_parser."""
+
+import sys
+import unittest
+
+import common
+from autotest_lib.server import autoserv_parser
+
+
+class autoserv_parser_test(unittest.TestCase):
+ def setUp(self):
+ self.orig_sys_argv = sys.argv
+
+ def tearDown(self):
+ sys.argv = self.orig_sys_argv
+
+ def _get_parser(self):
+ # We resort to this vile hack because autoserv_parser is bad
+ # enough to instantiate itself and replace its own class definition
+ # with its instance at module import time. Disgusting.
+ return autoserv_parser.autoserv_parser.__class__()
+
+ def test_control_file_args(self):
+ sys.argv = [None, '--args', '-y -z foo --hello', 'controlfile']
+ parser = self._get_parser()
+ parser.parse_args()
+ self.assertEqual(['controlfile', '-y', '-z', 'foo', '--hello'],
+ parser.args)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/server/server_job.py b/server/server_job.py
index 946ed34..b898b49 100755
--- a/server/server_job.py
+++ b/server/server_job.py
@@ -74,17 +74,23 @@
def __init__(self, control, args, resultdir, label, user, machines,
client=False, parse_job='',
- ssh_user='root', ssh_port=22, ssh_pass=''):
+ ssh_user='root', ssh_port=22, ssh_pass='',
+ group_name=''):
"""
- Server side job object.
+ Create a server side job object.
- Parameters:
- control: The control file (pathname of)
- args: args to pass to the control file
- resultdir: where to throw the results
- label: label for the job
- user: Username for the job (email address)
- client: True if a client-side control file
+ @param control The pathname of the control file.
+ @param args Passed to the control file.
+ @param resultdir Where to throw the results.
+ @param label Description of the job.
+ @param user Username for the job (email address).
+ @param client True if this is a client-side control file.
+ @param parse_job bool, should the results be through the TKO parser.
+ @param ssh_user The SSH username. [root]
+ @param ssh_port The SSH port number. [22]
+ @param ssh_pass The SSH passphrase, if needed.
+ @param group_name If supplied, this will be written out as
+ host_group_name in the keyvals file for the parser.
"""
path = os.path.dirname(__file__)
self.autodir = os.path.abspath(os.path.join(path, '..'))
@@ -102,7 +108,8 @@
self.resultdir = resultdir
self.uncollected_log_file = None
if resultdir:
- self.uncollected_log_file = os.path.join(resultdir, "uncollected_logs")
+ self.uncollected_log_file = os.path.join(resultdir,
+ 'uncollected_logs')
self.debugdir = os.path.join(resultdir, 'debug')
if not os.path.exists(resultdir):
@@ -155,6 +162,8 @@
'hostname' : ','.join(machines),
'status_version' : str(self.STATUS_VERSION),
'job_started' : str(int(time.time()))}
+ if group_name:
+ job_data['host_group_name'] = group_name
if self.resultdir:
# only write these keyvals out on the first job in a resultdir
if 'job_started' not in utils.read_keyval(self.resultdir):