Skip to content

Commit

Permalink
Convert entry points to use system-wide autotest libs v3
Browse files Browse the repository at this point in the history
If it fails, fallback to the approach used for single
directory layout (just import common).

Changes from v2:
 * Fixed patch to take into account the namespace cleanup
   patches

Changes from v1:
 * dzickus found a typo in client/setup_modules.py and fixed it
 * mkrizek found that in some points we should import
   autotest.common as common, and for safety, converted
   all import calls to look like that.

Signed-off-by: Don Zickus <[email protected]>
Signed-off-by: James Laska <[email protected]>
Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
Signed-off-by: Martin Krizek <[email protected]>
  • Loading branch information
dzickusrh committed Feb 7, 2012
1 parent c9c767c commit b67dfa6
Show file tree
Hide file tree
Showing 189 changed files with 776 additions and 200 deletions.
5 changes: 4 additions & 1 deletion CODING_STYLE
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ from common_lib.error import AutoservError
For example:
import os, pickle, random, re, select, shutil, signal, StringIO, subprocess
import sys, time, urllib, urlparse
import common # Magic autotest_lib module and sys.path setup code.
try:
import autotest.common
except ImportError:
import common # Magic autotest_lib module and sys.path setup code.
import MySQLdb # After common so that we check our site-packages first.
from common_lib import error

Expand Down
5 changes: 4 additions & 1 deletion cli/acl_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, sys

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import topic_common, action_common, acl, cli_mock


Expand Down
5 changes: 4 additions & 1 deletion cli/action_common_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, os, sys, StringIO, copy

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, topic_common, action_common, rpc
from autotest_lib.frontend.afe.json_rpc import proxy

Expand Down
5 changes: 4 additions & 1 deletion cli/atest
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/python -u

import sys
import common
try:
import autotest.common
except ImportError:
import common
from autotest_lib.cli import atest


Expand Down
5 changes: 4 additions & 1 deletion cli/atest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import os, sys, optparse, re, traceback

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import topic_common


Expand Down
5 changes: 4 additions & 1 deletion cli/atest_migrate_host
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/python
# Copyright Google, Martin J. Bligh <[email protected]>, Jan 2009
import os, sys
import common
try:
import autotest.common
except ImportError:
import common
from autotest_lib.server import frontend

try:
Expand Down
5 changes: 4 additions & 1 deletion cli/atest_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, os, sys, StringIO

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock


Expand Down
5 changes: 4 additions & 1 deletion cli/atomicgroup_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import unittest

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, topic_common, atomicgroup


Expand Down
5 changes: 4 additions & 1 deletion cli/autotest-rpc-client
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/python -u

import sys
import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import atest


Expand Down
5 changes: 4 additions & 1 deletion cli/change_protection_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# change_protection_level.py "No protection" machine1 machine2 machine3

import sys, optparse, traceback, pwd, os
import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import rpc, host

usage = 'usage: %prog [options] new_protection_level machine1 machine2 ...'
Expand Down
5 changes: 4 additions & 1 deletion cli/cli_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

import unittest, os, sys, StringIO

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import atest, topic_common, rpc
from autotest_lib.frontend.afe import rpc_client_lib
from autotest_lib.frontend.afe.json_rpc import proxy
Expand Down
5 changes: 4 additions & 1 deletion cli/compose_query
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Selects all rows and columns that satisfy the condition specified
and prints the matrix.
"""
import sys, os, re, optparse
import common
try:
import autotest.common
except ImportError:
import common
from autotest_lib.client.common_lib import kernel_versions
from autotest_lib.tko import display, frontend, db, query_lib

Expand Down
5 changes: 4 additions & 1 deletion cli/contrib/why_isnt_my_job_running.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/python

import sys, optparse, pwd
import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import rpc, host
from autotest_lib.client.common_lib import host_queue_entry_states

Expand Down
5 changes: 4 additions & 1 deletion cli/host_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, os, sys

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, host


Expand Down
5 changes: 4 additions & 1 deletion cli/job_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

import copy, getpass, unittest, sys, os

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, topic_common, job
from autotest_lib.client.common_lib.test_utils import mock

Expand Down
5 changes: 4 additions & 1 deletion cli/label_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, sys, os

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, topic_common


Expand Down
5 changes: 4 additions & 1 deletion cli/query_keyvals
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/python

import sys, optparse
import common
try:
import autotest.common
except ImportError:
import common
from autotest_lib.cli import rpc


Expand Down
5 changes: 4 additions & 1 deletion cli/query_results
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Selects all rows and columns that satisfy the condition specified
and prints the matrix.
"""
import optparse
import common
try:
import autotest.common
except ImportError:
import common
from autotest_lib.cli import rpc
from autotest_lib.database import database_connection

Expand Down
5 changes: 4 additions & 1 deletion cli/rpc_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"""Test for the rpc proxy class."""

import unittest, os
import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import rpc
from autotest_lib.client.common_lib import global_config
from autotest_lib.frontend.afe import rpc_client_lib
Expand Down
5 changes: 4 additions & 1 deletion cli/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, sys, os

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, topic_common, test


Expand Down
5 changes: 4 additions & 1 deletion cli/threads_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import threading, Queue

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, threads


Expand Down
5 changes: 4 additions & 1 deletion cli/topic_common_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, os, sys, StringIO, urllib2

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, topic_common, rpc
from autotest_lib.frontend.afe.json_rpc import proxy

Expand Down
5 changes: 4 additions & 1 deletion cli/user_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import unittest, os, sys

import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.cli import cli_mock, user


Expand Down
7 changes: 6 additions & 1 deletion client/bin/autotest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
#
# autotest <control file> - run the autotest control file specified.
#
import autotest_local
try:
import autotest.common as common
except ImportError:
import common

from autotest_lib.client.bin import autotest_local

if __name__ == '__main__':
autotest_local.main()
7 changes: 6 additions & 1 deletion client/bin/autotest-local
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
#
# autotest <control file> - run the autotest control file specified.
#
import autotest_local
try:
import autotest.common as common
except ImportError:
import common

from autotest_lib.client.bin import autotest_local

if __name__ == '__main__':
autotest_local.main()
5 changes: 4 additions & 1 deletion client/bin/autotest_client
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/python
import common
try:
import autotest.common
except ImportError:
import common

import sys, os, time, subprocess

Expand Down
21 changes: 12 additions & 9 deletions client/bin/autotest_local.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import os, sys
import common
from optparse import OptionParser
try:
import autotest.common as common
rootdir = os.path.abspath(os.path.dirname(common.__file__))
autodir = os.path.join(rootdir, 'client')
autodirbin = os.path.join(rootdir, 'client', 'bin')
except ImportError:
import common
autodirbin = os.path.dirname(os.path.realpath(sys.argv[0]))
autodir = os.path.dirname(autodirbin)
sys.path.insert(0, autodirbin)

from autotest_lib.client.bin import job
from autotest_lib.client.common_lib import global_config
from autotest_lib.client.bin import cmdparser

# Use the name of the binary to find the real installation directory
# aka $AUTODIR. Update our path to include the $AUTODIR/bin/tests
# directory and ensure we have $AUTODIR in our environment.
autodirbin = os.path.dirname(os.path.realpath(sys.argv[0]))
autodir = os.path.dirname(autodirbin)
autodirtest = os.path.join(autodir, "tests")

sys.path.insert(0, autodirbin)

os.environ['AUTODIR'] = autodir
os.environ['AUTODIRBIN'] = autodirbin
os.environ['AUTODIRTEST'] = autodirtest
os.environ['PYTHONPATH'] = autodirbin

cmd_parser = cmdparser.CommandParser() # Allow access to instance in parser

commandinfo = "[command] (optional)\tOne of: "+str(cmd_parser.cmdlist)
commandinfo = "[command] (optional)\tOne of: " + str(cmd_parser.cmdlist)
if sys.version_info[0:2] < (2,6):
parser = OptionParser(usage='Usage: %prog [options] [command] <control-file>',
description=commandinfo)
Expand Down
5 changes: 4 additions & 1 deletion client/bin/autotestd
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/python

import common
try:
import autotest.common
except ImportError:
import common
import sys, os, subprocess, fcntl


Expand Down
5 changes: 4 additions & 1 deletion client/bin/autotestd_monitor
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/python

import common
try:
import autotest.common
except ImportError:
import common
import sys, os, signal, time, subprocess, fcntl

logdir = sys.argv[1]
Expand Down
5 changes: 4 additions & 1 deletion client/bin/client_logging_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import common
try:
import autotest.common as common
except ImportError:
import common
import logging, os
from autotest_lib.client.common_lib import logging_config, global_config

Expand Down
5 changes: 4 additions & 1 deletion client/bin/fsdev_disks_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
__author__ = '[email protected] (Gregory Smith)'

import unittest
import common
try:
import autotest.common as common
except ImportError:
import common
from autotest_lib.client.bin import fsdev_disks

class fsdev_disks_test(unittest.TestCase):
Expand Down
Loading

0 comments on commit b67dfa6

Please sign in to comment.