I have attached the patch for the packaging system.
The documentation is available at : http://test.kernel.org/autotest/PackagingSystem

Signed-off-by: Ashwin Ganti <aganti@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@1953 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/global_config.py b/client/common_lib/global_config.py
index 8db02e1..6ca0d2a 100644
--- a/client/common_lib/global_config.py
+++ b/client/common_lib/global_config.py
@@ -102,6 +102,8 @@
                 return 0
             elif type == float:
                 return 0.0
+            elif type == list:
+                return []
             else:
                 return None
 
@@ -111,6 +113,10 @@
             else:
                 return True
 
+        if type == list:
+            # Split the string using ',' and return a list
+            return [val.strip() for val in sval.split(',')]
+
         try:
             conv_val = type(sval)
             return conv_val
diff --git a/client/common_lib/test.py b/client/common_lib/test.py
index cc343f5..a527c96 100644
--- a/client/common_lib/test.py
+++ b/client/common_lib/test.py
@@ -18,7 +18,8 @@
 
 import os, sys, re, fcntl, shutil, tarfile, warnings
 
-from autotest_lib.client.common_lib import error, utils
+from autotest_lib.client.common_lib import error, utils, packages
+from autotest_lib.client.bin import autotest_utils
 
 
 class base_test:
@@ -146,11 +147,17 @@
                 p_args, p_dargs = _cherry_pick_args(self.initialize,args,dargs)
                 self.initialize(*p_args, **p_dargs)
 
-                # Setup: (compile and install the test, if needed)
-                p_args, p_dargs = _cherry_pick_args(self.setup,args,dargs)
-                utils.update_version(self.srcdir, self.preserve_srcdir,
-                                     self.version, self.setup,
-                                     *p_args, **p_dargs)
+                lockfile = open(os.path.join(self.job.tmpdir, '.testlock'), 'w')
+                try:
+                    fcntl.flock(lockfile, fcntl.LOCK_EX)
+                    # Setup: (compile and install the test, if needed)
+                    p_args, p_dargs = _cherry_pick_args(self.setup,args,dargs)
+                    utils.update_version(self.srcdir, self.preserve_srcdir,
+                                         self.version, self.setup,
+                                         *p_args, **p_dargs)
+                finally:
+                    fcntl.flock(lockfile, fcntl.LOCK_UN)
+                    lockfile.close()
 
                 # Execute:
                 os.chdir(self.outputdir)
@@ -222,24 +229,8 @@
                     raise error.AutotestError('Unknown parameter: %s' % param)
 
 
-def testname(url):
-    # Extract the testname from the test url.
-    match = re.match('[^:]+://(.*)/([^/]*)$', url)
-    if not match:
-        return ('', url)
-    (group, filename) = match.groups()
-
-    # Generate the group prefix.
-    group = re.sub(r'\W', '_', group)
-
-    # Drop the extension to get the raw test name.
-    testname = re.sub(r'\.tgz', '', filename)
-
-    return (group, testname)
-
-
 def _installtest(job, url):
-    (group, name) = testname(url)
+    (group, name) = job.pkgmgr.get_package_name(url, 'test')
 
     # Bail if the test is already installed
     group_dir = os.path.join(job.testdir, "download", group)
@@ -255,15 +246,19 @@
         f.close()
 
     print name + ": installing test url=" + url
-    utils.get_file(url, os.path.join(group_dir, 'test.tgz'))
-    old_wd = os.getcwd()
-    os.chdir(group_dir)
-    tar = tarfile.open('test.tgz')
-    for member in tar.getmembers():
-        tar.extract(member)
-    tar.close()
-    os.chdir(old_wd)
-    os.remove(os.path.join(group_dir, 'test.tgz'))
+    tarball = os.path.basename(url)
+    tarball_path = os.path.join(group_dir, tarball)
+    test_dir = os.path.join(group_dir, name)
+    job.pkgmgr.fetch_pkg(tarball, tarball_path,
+                         repo_url = os.path.dirname(url))
+
+    # Create the directory for the test
+    if not os.path.exists(test_dir):
+        os.mkdir(os.path.join(group_dir, name))
+
+    job.pkgmgr.untar_pkg(tarball_path, test_dir)
+
+    os.remove(tarball_path)
 
     # For this 'sub-object' to be importable via the name
     # 'group.name' we need to provide an __init__.py,
@@ -282,7 +277,7 @@
 
     # if this is not a plain test name then download and install the
     # specified test
-    if utils.is_url(url):
+    if url.endswith('.tar.bz2'):
         (group, testname) = _installtest(job, url)
         bindir = os.path.join(job.testdir, 'download', group, testname)
         site_bindir = None
@@ -298,6 +293,18 @@
         else:
             site_bindir = None
 
+        # The job object here can be that of a server side job or a client
+        # side job. 'install_pkg' method won't be present for server side
+        # jobs, so do the fetch only if that method is present in the job
+        # obj.
+        if hasattr(job, 'install_pkg'):
+            try:
+                job.install_pkg(testname, 'test', bindir)
+            except packages.PackageInstallError, e:
+                # continue as a fall back mechanism and see if the test code
+                # already exists on the machine
+                pass
+
     outputdir = os.path.join(job.resultdir, testname)
     if tag:
         outputdir += '.' + tag
@@ -308,30 +315,26 @@
         testdir = job.site_testdir
     elif os.path.exists(bindir):
         testdir = job.testdir
-    elif not os.path.exists(bindir):
+    else:
         raise error.TestError(testname + ': test does not exist')
 
+    local_namespace['job'] = job
+    local_namespace['bindir'] = bindir
+    local_namespace['outputdir'] = outputdir
+
     if group:
         sys.path.insert(0, os.path.join(testdir, 'download'))
         group += '.'
     else:
         sys.path.insert(0, os.path.join(testdir, testname))
 
-    local_namespace['job'] = job
-    local_namespace['bindir'] = bindir
-    local_namespace['outputdir'] = outputdir
-
-    lockfile = open(os.path.join(job.tmpdir, '.testlock'), 'w')
     try:
-        fcntl.flock(lockfile, fcntl.LOCK_EX)
         exec ("import %s%s" % (group, testname),
               local_namespace, global_namespace)
         exec ("mytest = %s%s.%s(job, bindir, outputdir)" %
               (group, testname, testname),
               local_namespace, global_namespace)
     finally:
-        fcntl.flock(lockfile, fcntl.LOCK_UN)
-        lockfile.close()
         sys.path.pop(0)
 
     pwd = os.getcwd()
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index c29d7e4..e54e134 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -463,6 +463,20 @@
     return "\n".join(control_new)
 
 
+def get_arch(run_function=run):
+    """
+    Get the hardware architecture of the machine.
+    run_function is used to execute the commands. It defaults to
+    utils.run() but a custom method (if provided) should be of the
+    same schema as utils.run. It should return a CmdResult object and
+    throw a CmdError exception.
+    """
+    arch = run_function('/bin/uname -m').stdout.rstrip()
+    if re.match(r'i\d86$', arch):
+        arch = 'i386'
+    return arch
+
+
 class CmdResult(object):
     """
     Command execution result.