Introduce a key on global_config.ini, COMMON/autotest_top_path, that has the top level autotest directory. This way we can get rid of all hard coded references to /usr/local/autotest in autotest code.
Signed-off-by: Lucas Meneghel Rodrigues <[email protected]> --- client/bin/kernel.py | 3 ++- client/common_lib/base_packages.py | 2 +- client/virt/virt_test_utils.py | 6 ++++-- conmux/contrib/console_check.py | 7 ++++++- global_config.ini | 3 +++ server/autotest.py | 8 +++++--- server/self-test/autotest_test.py | 27 ++++++++++++++------------- utils/test_importer.py | 24 +++++++++++++++--------- 8 files changed, 50 insertions(+), 30 deletions(-) diff --git a/client/bin/kernel.py b/client/bin/kernel.py index cb0ef99..8bfb58f 100644 --- a/client/bin/kernel.py +++ b/client/bin/kernel.py @@ -130,7 +130,8 @@ class kernel(BootableKernel): job Backpointer to the job object we're part of autodir - Path to the top level autotest dir (/usr/local/autotest) + Path to the top level autotest dir (see global_config.ini, + session COMMON/autotest_top_path) src_dir <tmp_dir>/src/ build_dir diff --git a/client/common_lib/base_packages.py b/client/common_lib/base_packages.py index 645256d..c3d7fd4 100644 --- a/client/common_lib/base_packages.py +++ b/client/common_lib/base_packages.py @@ -539,7 +539,7 @@ class BasePackageManager(object): ''' try: if upload_path.startswith('ssh://'): - # parse ssh://user@host/usr/local/autotest/packages + # parse ssh://user@host[autotest_top_path]/packages hostline, remote_path = parse_ssh_path(upload_path) try: utils.run('scp %s %s:%s' % (file_path, hostline, diff --git a/client/virt/virt_test_utils.py b/client/virt/virt_test_utils.py index 6b0d7eb..bfdbb71 100644 --- a/client/virt/virt_test_utils.py +++ b/client/virt/virt_test_utils.py @@ -22,11 +22,12 @@ More specifically: """ import time, os, logging, re, signal, imp -from autotest_lib.client.common_lib import error +from autotest_lib.client.common_lib import error, global_config from autotest_lib.client.bin import utils from autotest_lib.client.tools import scan_results import aexpect, virt_utils, virt_vm +GLOBAL_CONFIG = global_config.global_config def get_living_vm(env, vm_name): """ @@ -546,7 +547,8 @@ def run_autotest(vm, session, control_path, timeout, outputdir, params): mig_protocol = params.get("migration_protocol", "tcp") compressed_autotest_path = "/tmp/autotest.tar.bz2" - destination_autotest_path = "/usr/local/autotest" + destination_autotest_path = GLOBAL_CONFIG.get_config_value('COMMON', + 'autotest_top_path') # To avoid problems, let's make the test use the current AUTODIR # (autotest client path) location diff --git a/conmux/contrib/console_check.py b/conmux/contrib/console_check.py index 292a07b..86a8d87 100755 --- a/conmux/contrib/console_check.py +++ b/conmux/contrib/console_check.py @@ -16,6 +16,10 @@ _author_ = 'Scott Zawalski ([email protected])' import sys, pexpect, commands, os from optparse import OptionParser +from autotest_lib.client.common_lib import global_config + + +GLOBAL_CONFIG = global_config.global_config def main(argv): @@ -24,6 +28,7 @@ def main(argv): consoles['bad'] = [] consoles['unknown'] = [] # 0, 1, 2 status + TOP_DIR = GLOBAL_CONFIG.get_config_value('COMMON', 'autotest_top_path') STATUS = [ 'good', 'bad', 'unknown'] parser = OptionParser() parser.add_option('--conmux-server', dest="conmux_server", @@ -36,7 +41,7 @@ def main(argv): default='/usr/local/conmux/bin/console', help="Conmux console binary location") parser.add_option('--autotest-cli-dir', dest="autotest_cli_dir", - default='/usr/local/autotest/cli', + default=os.path.join(TOP_DIR, 'cli'), help="Autotest CLI dir") parser.add_option('--add-hosts', action="store_true", dest="add_hosts", diff --git a/global_config.ini b/global_config.ini index e8954ab..d9a18c2 100644 --- a/global_config.ini +++ b/global_config.ini @@ -44,6 +44,9 @@ template_debug_mode: False # Whether to enable django SQL debug mode sql_debug_mode: False +[COMMON] +autotest_top_path: /usr/local/autotest + [AUTOSERV] # Autotest potential install paths client_autodir_paths: /usr/local/autotest,/home/autotest diff --git a/server/autotest.py b/server/autotest.py index 5ea8b83..b3770d4 100644 --- a/server/autotest.py +++ b/server/autotest.py @@ -43,9 +43,11 @@ class BaseAutotest(installable_object.InstallableObject): install_in_tmpdir = False @classmethod def set_install_in_tmpdir(cls, flag): - """ Sets a flag that controls whether or not Autotest should by - default be installed in a "standard" directory (e.g. - /home/autotest, /usr/local/autotest) or a temporary directory. """ + """ + Sets a flag that controls whether or not Autotest should by + default be installed in a "standard" directory (e.g. /home/autotest) or + a temporary directory. + """ cls.install_in_tmpdir = flag diff --git a/server/self-test/autotest_test.py b/server/self-test/autotest_test.py index 6e9df7b..8a69fdc 100755 --- a/server/self-test/autotest_test.py +++ b/server/self-test/autotest_test.py @@ -16,8 +16,12 @@ import common from autotest_lib.server import utils from autotest_lib.server import autotest from autotest_lib.server import hosts +from autotest_lib.client.common_lib import global_config +_GLOBAL_CONFIG = global_config.global_config +_TOP_PATH = _GLOBAL_CONFIG.get_config_value('COMMON', 'autotest_top_path') + class AutotestTestCase(unittest.TestCase): def setUp(self): self.autotest = autotest.Autotest() @@ -59,7 +63,7 @@ class AutotestTestCase(unittest.TestCase): def run(self, command): if command == "grep autodir= /etc/autotest.conf": result= hosts.CmdResult() - result.stdout = "autodir=/usr/local/autotest\n" + result.stdout = "autodir=%s\n" % _TOP_PATH return result else: self.commands.append(command) @@ -72,11 +76,10 @@ class AutotestTestCase(unittest.TestCase): tmpdir = utils.get_tmp_dir() self.autotest.get(tmpdir) self.autotest.install(host) - self.assertEqual(host.commands[0], - 'mkdir -p /usr/local/autotest') + self.assertEqual(host.commands[0], 'mkdir -p %s' % _TOP_PATH) self.assertTrue(host.commands[1].startswith('send_file: /tmp/')) self.assertTrue(host.commands[1].endswith( - '/ /usr/local/autotest')) + '/ %s' % GLOBAL_CONFIG.get_config_value('COMMON', 'autotest_top_path'))) @@ -89,7 +92,7 @@ class AutotestTestCase(unittest.TestCase): def run(self, command): if command == "grep autodir= /etc/autotest.conf": result= hosts.CmdResult() - result.stdout = "autodir=/usr/local/autotest\n" + result.stdout = ("autodir=%s\n" % _TOP_PATH) return result else: self.commands.append(command) @@ -98,8 +101,7 @@ class AutotestTestCase(unittest.TestCase): self.autotest.install(host) self.assertEqual(host.commands, ['svn checkout ' - + autotest.AUTOTEST_SVN + ' ' - + "/usr/local/autotest"]) + + autotest.AUTOTEST_SVN + ' ' + _TOP_PATH]) def testFirstInstallFromSVNFails(self): @@ -110,13 +112,12 @@ class AutotestTestCase(unittest.TestCase): def run(self, command): if command == "grep autodir= /etc/autotest.conf": result= hosts.CmdResult() - result.stdout = "autodir=/usr/local/autotest\n" + result.stdout = "autodir=%s\n" % _TOP_PATH return result else: self.commands.append(command) - first = ('svn checkout ' + - autotest.AUTOTEST_SVN + ' ' + - "/usr/local/autotest") + first = ('svn checkout ' + autotest.AUTOTEST_SVN + ' ' + + _TOP_PATH) if (command == first): raise autotest.AutoservRunError( "svn not found") @@ -125,9 +126,9 @@ class AutotestTestCase(unittest.TestCase): self.autotest.install(host) self.assertEqual(host.commands, ['svn checkout ' + autotest.AUTOTEST_SVN + - ' ' + "/usr/local/autotest", + ' ' + _TOP_PATH, 'svn checkout ' + autotest.AUTOTEST_HTTP + - ' ' + "/usr/local/autotest"]) + ' ' + _TOP_PATH]) def suite(): diff --git a/utils/test_importer.py b/utils/test_importer.py index a7be755..2faf053 100755 --- a/utils/test_importer.py +++ b/utils/test_importer.py @@ -6,17 +6,17 @@ This utility allows for easy updating, removing and importing of tests into the autotest_web afe_autotests table. Example of updating client side tests: -./test_importer.py -t /usr/local/autotest/client/tests +./test_importer.py -t TOP_DIR/client/tests If, for example, not all of your control files adhere to the standard outlined at http://autotest.kernel.org/wiki/ControlRequirements, you can force options: -./test_importer.py --test-type server -t /usr/local/autotest/server/tests +./test_importer.py --test-type server -t TOP_DIR/server/tests You would need to pass --add-noncompliant to include such control files, however. An easy way to check for compliance is to run in dry mode: -./test_importer.py --dry-run -t /usr/local/autotest/server/tests/mytest +./test_importer.py --dry-run -t TOP_DIR/server/tests/mytest Or to check a single control file, you can use check_control_file_vars.py. @@ -58,7 +58,8 @@ def update_all(autotest_dir, add_noncompliant, add_experimental): from the db. The base test directories are hard-coded to client/tests, client/site_tests, server/tests and server/site_tests. - @param autotest_dir: prepended to path strings (/usr/local/autotest). + @param autotest_dir: prepended to path strings + (see global_config.ini, COMMON, autotest_top_path). @param add_noncompliant: attempt adding test with invalid control files. @param add_experimental: add tests with experimental attribute set. """ @@ -101,7 +102,8 @@ def update_samples(autotest_dir, add_noncompliant, add_experimental): Only adds tests to the database - does not delete any. Samples tests are formatted slightly differently than other tests. - @param autotest_dir: prepended to path strings (/usr/local/autotest). + @param autotest_dir: prepended to path strings + (see global_config.ini, COMMON, autotest_top_path). @param add_noncompliant: attempt adding test with invalid control files. @param add_experimental: add tests with experimental attribute set. """ @@ -124,7 +126,8 @@ def db_clean_broken(autotest_dir): found in the filesystem. Also removes profilers which are just a special case of tests. - @param autotest_dir: prepended to path strings (/usr/local/autotest). + @param autotest_dir: prepended to path strings + (see global_config.ini, COMMON, autotest_top_path). """ for test in models.Test.objects.all(): full_path = os.path.join(autotest_dir, test.path) @@ -148,7 +151,8 @@ def db_clean_all(autotest_dir): This function invoked when -C supplied on the command line. Removes ALL tests from the database. - @param autotest_dir: prepended to path strings (/usr/local/autotest). + @param autotest_dir: prepended to path strings + (see global_config.ini, COMMON, autotest_top_path). """ for test in models.Test.objects.all(): full_path = os.path.join(autotest_dir, test.path) @@ -206,7 +210,8 @@ def update_tests_in_db(tests, dry_run=False, add_experimental=False, @param dry_run: not used at this time. @param add_experimental: add tests with experimental attribute set. @param add_noncompliant: attempt adding test with invalid control files. - @param autotest_dir: prepended to path strings (/usr/local/autotest). + @param autotest_dir: prepended to path strings + (see global_config.ini, COMMON, autotest_top_path). """ site_set_attributes_module = utils.import_site_module( __file__, 'autotest_lib.utils.site_test_importer_attributes') @@ -439,7 +444,8 @@ def update_from_whitelist(whitelist_set, add_experimental, add_noncompliant, @param whitelist_set: set of tests in full-path form from a whitelist. @param add_experimental: add tests with experimental attribute set. @param add_noncompliant: attempt adding test with invalid control files. - @param autotest_dir: prepended to path strings (/usr/local/autotest). + @param autotest_dir: prepended to path strings + (see global_config.ini, COMMON, autotest_top_path). """ tests = {} profilers = {} -- 1.7.7.5 _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
