diff options
author | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2010-04-01 17:15:53 +0000 |
---|---|---|
committer | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2010-04-01 17:15:53 +0000 |
commit | 34faa896095c28349973224bb1486ba3dc5c57d8 (patch) | |
tree | e4c0255aabb4b79e79dda9e817c26bf066fe7937 /server | |
parent | aaa227a0bb9852911e8c1b226c9adea45aa360b0 (diff) |
enable server side test prebuild from autoserv
From: ericli@google.com
git-svn-id: svn://test.kernel.org/autotest/trunk@4371 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'server')
-rw-r--r-- | server/autotest.py | 18 | ||||
-rw-r--r-- | server/prebuild.py | 64 |
2 files changed, 79 insertions, 3 deletions
diff --git a/server/autotest.py b/server/autotest.py index f19e350b..1e92bf92 100644 --- a/server/autotest.py +++ b/server/autotest.py @@ -2,7 +2,7 @@ import re, os, sys, traceback, subprocess, time, pickle, glob, tempfile import logging, getpass -from autotest_lib.server import installable_object, utils +from autotest_lib.server import installable_object, prebuild, utils from autotest_lib.client.common_lib import log, error, autotemp from autotest_lib.client.common_lib import global_config, packages from autotest_lib.client.common_lib import utils as client_utils @@ -16,6 +16,11 @@ BOOT_TIME = 1800 CRASH_RECOVERY_TIME = 9000 +get_value = global_config.global_config.get_config_value +autoserv_prebuild = get_value('AUTOSERV', 'enable_server_prebuild', + type=bool, default=False) + + class AutodirNotFoundError(Exception): """No Autotest installation could be found.""" @@ -974,10 +979,17 @@ class client_logger(object): name, pkg_type = self.job.pkgmgr.parse_tarball_name(pkg_name) src_dirs = [] if pkg_type == 'test': - src_dirs += [os.path.join(self.job.clientdir, 'site_tests', name), - os.path.join(self.job.clientdir, 'tests', name)] + for test_dir in ['site_tests', 'tests']: + src_dir = os.path.join(self.job.clientdir, test_dir, name) + if os.path.exists(src_dir): + src_dirs += [src_dir] + if autoserv_prebuild: + prebuild.setup(self.job.clientdir, src_dir) + break elif pkg_type == 'profiler': src_dirs += [os.path.join(self.job.clientdir, 'profilers', name)] + if autoserv_prebuild: + prebuild.setup(self.job.clientdir, src_dir) elif pkg_type == 'dep': src_dirs += [os.path.join(self.job.clientdir, 'deps', name)] elif pkg_type == 'client': diff --git a/server/prebuild.py b/server/prebuild.py new file mode 100644 index 00000000..4d786050 --- /dev/null +++ b/server/prebuild.py @@ -0,0 +1,64 @@ +# Copyright 2010 Google Inc. Released under the GPL v2 +# +# Eric Li <ericli@google.com> + +import logging, os, pickle, re, sys +import common +from autotest_lib.client.bin import setup_job as client_setup_job + + +def touch_init(parent_dir, child_dir): + """ + Touch __init__.py file all alone through from dir_patent to child_dir. + + So client tests could be loaded as Python modules. Assume child_dir is a + subdirectory of parent_dir. + """ + + if not child_dir.startswith(parent_dir): + logging.error('%s is not a subdirectory of %s' % (child_dir, + parent_dir)) + return + sub_parent_dirs = parent_dir.split(os.path.sep) + sub_child_dirs = child_dir.split(os.path.sep) + for sub_dir in sub_child_dirs[len(sub_parent_dirs):]: + sub_parent_dirs.append(sub_dir) + path = os.path.sep.join(sub_parent_dirs) + init_py = os.path.join(path, '__init__.py') + open(init_py, 'a').close() + + +def init_test(testdir): + """ + Instantiate a client test object from a given test directory. + + @param testdir The test directory. + @returns A test object or None if failed to instantiate. + """ + + class options: + tag = '' + verbose = None + cont = False + harness = 'autoserv' + hostname = None + user = None + log = True + return client_setup_job.init_test(options, testdir) + + +def setup(autotest_client_dir, client_test_dir): + """ + Setup prebuild of a client test. + + @param autotest_client_dir: The autotest/client base directory. + @param client_test_dir: The actual test directory under client. + """ + + os.environ['AUTODIR'] = autotest_client_dir + touch_init(autotest_client_dir, client_test_dir) + + # instantiate a client_test instance. + client_test = init_test(client_test_dir) + client_setup_job.setup_test(client_test) + |