summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2008-05-16 22:48:09 +0000
committermbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2008-05-16 22:48:09 +0000
commit5e724c3665a6e3d64b9d93b993272fa333248a5b (patch)
treefd1622595f8025e79bcfaf6e17223e30fbcfc970
parent2eba4cfac756622dab9511e353f33c4d2f181fc3 (diff)
Remove all places where we are hardcoding python2.4 on the
scripts Risk: Medium/High Summary: After going trough the autotest tree, removing all places where we have statements like #!/usr/bin/python2.4 As they're unnecessary for those who have python > 2.4. Still, we want to make sure we're running on something > 2.4 for those scripts, so I hooked the scripts to the common lib infrastructure when needed. I tried to be as careful as possible to make sure all scripts worked after my modifications, I could even spot an import problem on server/standalone_profiler.py and fix it. Also, while I was there, I fixed several inconsistencies on the mirror/mirror script. Signed-off-by: Lucas Meneghel Rodrigues <lucasmr@br.ibm.com> git-svn-id: svn://test.kernel.org/autotest/trunk@1527 592f7852-d20e-0410-864c-8624ca9c26a4
-rw-r--r--client/common_lib/global_config_unittest.py8
-rw-r--r--client/common_lib/mail_unittest.py2
-rw-r--r--common.py8
-rw-r--r--frontend/frontend_unittest.py3
-rwxr-xr-xmigrate/migrate.py2
-rw-r--r--mirror/common.py8
-rwxr-xr-xmirror/mirror120
-rw-r--r--server/samples/profilertest.srv3
-rw-r--r--server/standalone_profiler.py3
-rw-r--r--unittest_suite.py4
10 files changed, 80 insertions, 81 deletions
diff --git a/client/common_lib/global_config_unittest.py b/client/common_lib/global_config_unittest.py
index a2400912..e41d7093 100644
--- a/client/common_lib/global_config_unittest.py
+++ b/client/common_lib/global_config_unittest.py
@@ -1,13 +1,9 @@
-#!/usr/bin/python2.4
+#!/usr/bin/python
-import os, sys
-import tempfile
-import unittest
-import types
+import os, sys, tempfile, unittest, types
import global_config
-
global_config_ini_contents = """
[SECTION_A]
value_1: 6.0
diff --git a/client/common_lib/mail_unittest.py b/client/common_lib/mail_unittest.py
index fb13a0ff..95de7827 100644
--- a/client/common_lib/mail_unittest.py
+++ b/client/common_lib/mail_unittest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.4
+#!/usr/bin/python
import unittest
import mail, email.Message
diff --git a/common.py b/common.py
new file mode 100644
index 00000000..7654dabf
--- /dev/null
+++ b/common.py
@@ -0,0 +1,8 @@
+import os, sys
+dirname = os.path.dirname(sys.modules[__name__].__file__)
+autotest_dir = dirname
+client_dir = os.path.join(autotest_dir, "client")
+sys.path.insert(0, client_dir)
+import setup_modules
+sys.path.pop(0)
+setup_modules.setup(base_path=autotest_dir, root_module_name="autotest_lib")
diff --git a/frontend/frontend_unittest.py b/frontend/frontend_unittest.py
index 2b2441cf..51375485 100644
--- a/frontend/frontend_unittest.py
+++ b/frontend/frontend_unittest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.4
+#!/usr/bin/python
"""
This file provides a unittest.TestCase wrapper around the Django unit test
@@ -6,6 +6,7 @@ runner.
"""
import unittest, os
+import common
manage_path = os.path.join(os.path.dirname(__file__), 'manage.py')
diff --git a/migrate/migrate.py b/migrate/migrate.py
index 5382252e..56c086dd 100755
--- a/migrate/migrate.py
+++ b/migrate/migrate.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.4 -u
+#!/usr/bin/python -u
import os, sys, re, subprocess, tempfile
import MySQLdb, MySQLdb.constants.ER
diff --git a/mirror/common.py b/mirror/common.py
new file mode 100644
index 00000000..9941b190
--- /dev/null
+++ b/mirror/common.py
@@ -0,0 +1,8 @@
+import os, sys
+dirname = os.path.dirname(sys.modules[__name__].__file__)
+autotest_dir = os.path.abspath(os.path.join(dirname, ".."))
+client_dir = os.path.join(autotest_dir, "client")
+sys.path.insert(0, client_dir)
+import setup_modules
+sys.path.pop(0)
+setup_modules.setup(base_path=autotest_dir, root_module_name="autotest_lib")
diff --git a/mirror/mirror b/mirror/mirror
index 3c4703ea..31be530f 100755
--- a/mirror/mirror
+++ b/mirror/mirror
@@ -1,16 +1,7 @@
-#!/usr/bin/python2.4
-import sys
-import os, os.path
+#!/usr/bin/python
+import email.Message, optparse, os, os.path, re, shutil, smtplib, sys, tempfile
import time
-import optparse
-import smtplib
-import email.Message
-import tempfile
-import shutil
-import re
-
-import rsync
-import trigger
+import rsync, trigger, common
excludes = ('2.6.0-test*/', 'broken-out/', '*.sign', '*.gz')
@@ -19,8 +10,8 @@ default_clients_path = os.path.expanduser(
default_config_path = os.path.expanduser(
os.path.join ('~', '.autotest_mirror_config'))
options = optparse.Values(defaults={'email': None,
- 'clients': default_clients_path,
- 'config': default_config_path})
+ 'clients': default_clients_path,
+ 'config': default_config_path})
# This counter gets appended and incremented for all jobs created
# this ensures that no two jobs of the same name are created during
@@ -37,12 +28,12 @@ AUTOTEST_WRAPPER = """def step_init():
job.next_step([step_test])
testkernel = job.kernel(kernel)
- if patches:
+ if patches:
testkernel.patch(*patches)
- if config:
- testkernel.config(config)
- else:
- testkernel.config('', None, True)
+ if config:
+ testkernel.config(config)
+ else:
+ testkernel.config('', None, True)
testkernel.build()
testkernel.boot()
@@ -64,38 +55,34 @@ def test_kernel(client, control, kernel, config, patches=None):
since the control file will be created in the host's
queue automatically
"""
- is_autoserv_ctl = control.endswith('.srv')
- # Open a temp file to create the generated control file in
+ is_autoserv_ctl = control.endswith('.srv')
+
+ # Open a temp file to create the generated control file in
tmpfile = tempfile.mktemp()
c = open(tmpfile, 'w')
- print >> c, PREAMBLE % tuple([repr(s) for s in (kernel,
- config,
- patches)])
+ print >> c, PREAMBLE % tuple([repr(s) for s in (kernel, config, patches)])
- if not is_autoserv_ctl:
- print >> c, AUTOTEST_WRAPPER
+ if not is_autoserv_ctl:
+ print >> c, AUTOTEST_WRAPPER
- # Open the basis control file and pull its contents into this one
+ # Open the basis control file and pull its contents into this one
control = open(os.path.expanduser(control), "r")
- # If is an AT file then we need to indent to match wrapper
- # function level indentation, srv files don't need this indentation
- indent = ('\t', '')[is_autoserv_ctl]
+ # If is an AT file then we need to indent to match wrapper
+ # function level indentation, srv files don't need this indentation
+ indent = ('\t', '')[is_autoserv_ctl]
for line in control:
print >> c, "%s%s" % (indent, line.rstrip())
c.close()
# Create a name for the queued file
- # if we came from an .srv file create an .srv file
- extension = ('', '.srv')[is_autoserv_ctl]
+ # if we came from an .srv file create an .srv file
+ extension = ('', '.srv')[is_autoserv_ctl]
global counter
- output = os.path.join(options.queuedir, client,
- "%s-%d%.3d%s" % (kernel,
- int(time.time()),
- counter,
- extension))
+ output = os.path.join(options.queuedir, client, "%s-%d%.3d%s" % (kernel, \
+ int(time.time()), counter, extension))
counter = (counter + 1) % 1000
shutil.move(tmpfile, output)
return output
@@ -111,8 +98,8 @@ def load_conf(conf_path):
Lines beginning with # are stripped from the conf file
"""
machine_controls = {}
- if not os.path.exists(conf_path):
- return machine_controls
+ if not os.path.exists(conf_path):
+ return machine_controls
conf_file = open(conf_path)
for line in conf_file.readlines():
if line.startswith('#'):
@@ -150,6 +137,7 @@ MAIL = "sendmail"
class SendmailException(Exception):
pass
+
def sendmail(message):
"""Send an email using sendmail"""
# open a pipe to the mail program and
@@ -159,22 +147,22 @@ def sendmail(message):
exitcode = p.close()
if exitcode:
raise SendmailException("Exit code: %s" % exitcode)
-
+
+
def send_kernel_mail(kernel_list):
if not options.email:
return
- if len(kernel_list) < 1:
- return
+ if len(kernel_list) < 1:
+ return
message = "\n".join(kernel_list)
message = "Testing new kernel releases:\n%s" % message
- mail("autotest-server@localhost",
- options.email,
- "autotest new kernel notification",
- message)
-
+ mail("autotest-server@localhost", options.email, \
+ "autotest new kernel notification", message)
encode_sep = re.compile('(\D+)')
+
+
def kver_encode(version):
if 'rc' not in version:
version += '-rc99'
@@ -188,8 +176,8 @@ def kver_encode(version):
def kver_cmp(a, b):
- a, b = kver_encode(a), kver_encode(b)
- return cmp(a, b)
+ a, b = kver_encode(a), kver_encode(b)
+ return cmp(a, b)
def closest_kver_leq(klist, kver):
@@ -213,18 +201,18 @@ def perform_client_tests(kernel_list):
# and the tests that each one is to execute
for machine, controls in machines.items():
config_paths = load_conf(os.path.join(options.config,
- machine))
+ machine))
config = '/boot/config'
if len(config_paths) > 0:
kvers = config_paths.keys()
close = closest_kver_leq(kvers,
- kernel)
+ kernel)
config = config_paths[close][0]
for control in controls:
test_kernel(machine,
- control,
- kernel,
- config)
+ control,
+ kernel,
+ config)
def main():
@@ -254,20 +242,20 @@ if __name__ == '__main__':
usage = "mirror [options] <mirrordir> <queuedir>"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-e", "--email", dest="email",
- help="Email address to alert for new kernels",
- metavar="EMAIL")
+ help="Email address to alert for new kernels",
+ metavar="EMAIL")
parser.add_option("-c", "--clients", dest="clients",
- help="Location of the file that describes which \
- control file to run on which clients; defaults \
- to %s" % default_clients_path,
- metavar="CLIENTS",
- default=default_clients_path)
+ help="Location of the file that describes which \
+ control file to run on which clients; defaults \
+ to %s" % default_clients_path, \
+ metavar="CLIENTS", \
+ default=default_clients_path)
parser.add_option("-f", "--config", dest="config",
- help="Location of the directory that describes which \
- config files to use on which clients; defaults \
- to %s" % default_config_path,
- metavar="CONFIG",
- default=default_config_path)
+ help="Location of the directory that describes which \
+ config files to use on which clients; defaults \
+ to %s" % default_config_path,
+ metavar="CONFIG",
+ default=default_config_path)
(options, args) = parser.parse_args()
if len(args) < 2:
parser.print_help()
diff --git a/server/samples/profilertest.srv b/server/samples/profilertest.srv
index 2c7969ad..2743b760 100644
--- a/server/samples/profilertest.srv
+++ b/server/samples/profilertest.srv
@@ -1,6 +1,3 @@
-#!/usr/bin/python2.4
-# -*- mode: python; -*-
-
import time
ssh_hosts = [hosts.SSHHost(m, initialize=False) for m in machines]
diff --git a/server/standalone_profiler.py b/server/standalone_profiler.py
index 22801fd2..81bf7698 100644
--- a/server/standalone_profiler.py
+++ b/server/standalone_profiler.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.4
+#!/usr/bin/python
#
# Copyright 2007 Google Inc. All Rights Reserved.
@@ -10,6 +10,7 @@ running through autotest.
__author__ = 'cranger@google.com (Colby Ranger)'
+import common
from autotest_lib.client.common_lib import barrier
diff --git a/unittest_suite.py b/unittest_suite.py
index 9d264584..b8794ca5 100644
--- a/unittest_suite.py
+++ b/unittest_suite.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.4
+#!/usr/bin/python
import os, sys
import unittest
@@ -23,4 +23,4 @@ if __name__ == "__main__":
os.path.walk(root, lister, None)
alltests = unittest.TestSuite(suites)
runner = unittest.TextTestRunner(verbosity=2)
- runner.run(alltests)
+ runner.run(alltests)