When playing with my changes for the Git Fetcher, I thought it would be
nice if we could just 'fetch' the control file remotely.

This would make it easier for folks to create random tests and host them,
while letting others just grab them with a url pointer (either git: or
http:).

It creates a new area to store the fetched tests (based on the 'test_out_dir'
variable) and hooks this area into the 'list' and 'run' commands.

Tested by running:

autotest-local fetch git://<internal-git-site> testsuite/control.simple

and then run it with

autotest-local run testsuite/control.simple

(the control file adds the remote repo to fetch the tests from)

The downside is the remote repo and branch info is hardcoded in the control
file.  I would like to develop a more generic mechanism to abstract it out
to give some flexibility, but my brain is worn out dealing with all the
packaging fallout from my current patches. :-(

Signed-off-by: Don Zickus <dzic...@redhat.com>
---
 client/cmdparser.py |   61 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/client/cmdparser.py b/client/cmdparser.py
index 165551f..51566e2 100644
--- a/client/cmdparser.py
+++ b/client/cmdparser.py
@@ -7,6 +7,7 @@ Autotest command parser
 import os, re, sys
 from autotest.client import os_dep
 from autotest.client.shared import global_config
+from autotest.client.shared import base_packages, packages
 
 GLOBAL_CONFIG = global_config.global_config
 
@@ -14,6 +15,10 @@ LOCALDIRTEST = "tests"
 GLOBALDIRTEST = GLOBAL_CONFIG.get_config_value('COMMON',
                                                'test_dir',
                                                 default="")
+FETCHDIRTEST = GLOBAL_CONFIG.get_config_value('COMMON',
+                                               'test_output_dir',
+                                                default="")
+FETCHDIRTEST = os.path.join(FETCHDIRTEST, 'site_tests')
 
 DEBUG = False
 
@@ -23,7 +28,7 @@ class CommandParser(object):
     A client-side command wrapper for the autotest client.
     """
 
-    COMMAND_LIST = ['help', 'list', 'run']
+    COMMAND_LIST = ['help', 'list', 'run', 'fetch']
 
     @classmethod
     def _print_control_list(cls, pipe, path):
@@ -66,6 +71,46 @@ class CommandParser(object):
                     pipe.write(' %-50s %s\n' % (text, desc))
 
 
+    def is_url(self, url):
+        """Return true if path looks like a URL"""
+        return url.startswith('http://') or url.startswith('git://')
+
+    def fetch(self, args):
+        """
+        fetch a remote control file or packages
+
+        """
+        if not len(args):
+            self.help()
+
+        url = args.pop(0)
+        if not self.is_url(url):
+            print "Not a remote url, nothing to fetch (%s)" % url
+            self.help()
+
+        print "hey you2"
+        if len(args):
+            name = args.pop(0)
+        else:
+            name = ""
+
+        print "fetching file %s:%s" % (url, name)
+        autodir = os.path.abspath(os.environ['AUTODIR'])
+        tmpdir = os.path.join(autodir, 'tmp')
+        tests_out_dir = GLOBAL_CONFIG.get_config_value('COMMON',
+                                                       'test_output_dir',
+                                                       default=tmpdir)
+        pkg_dir = os.path.join(tests_out_dir, 'packages')
+        install_dir = os.path.join(FETCHDIRTEST, name)
+
+        pkgmgr = packages.PackageManager(tests_out_dir,
+            run_function_dargs={'timeout':3600})
+        pkgmgr.install_pkg(name, 'test', pkg_dir, install_dir,
+            repo_url=url)
+
+        raise SystemExit(0)
+
+
     @classmethod
     def help(cls):
         """
@@ -74,6 +119,9 @@ class CommandParser(object):
         @param args is not used here.
         """
         print "Commands:"
+        print "fetch <url> [<file>]\tFetch a remote file/package and install 
it"
+        print "\tgit://...:[<branch>] [<file/directory>]"
+        print "\thttp://... [<file>]"
         print "help\t\t\tOutput a list of supported commands"
         print "list\t\t\tOutput a list of available tests"
         print "run <test> [<args>]\tFind given <test> in path and run with 
args"
@@ -105,6 +153,13 @@ class CommandParser(object):
             cls._print_control_list(pipe, dirtest)
             pipe.write("\n")
 
+        # Walk fetchdirtest directory
+        if FETCHDIRTEST and os.path.isdir(FETCHDIRTEST):
+            dirtest = FETCHDIRTEST
+            pipe.write("Remotely fetched tests (%s)\n" % dirtest)
+            cls._print_control_list(pipe, dirtest)
+            pipe.write("\n")
+
         # Walk globaldirtests directory
         if GLOBALDIRTEST and os.path.isdir(GLOBALDIRTEST):
             dirtest = GLOBALDIRTEST
@@ -168,13 +223,13 @@ class CommandParser(object):
             test = test + "/control"
 
         localdir = os.path.join(os.path.abspath(os.path.curdir), LOCALDIRTEST)
+        fetchdir = FETCHDIRTEST
         globaldir = GLOBALDIRTEST
         autodir = os.environ['AUTODIRTEST']
 
-        for dirtest in [localdir, globaldir, autodir]:
+        for dirtest in [localdir, fetchdir, globaldir, autodir]:
             d = os.path.join(dirtest, test)
             if os.path.isfile(d):
-                print d
                 args.insert(0, d)
                 return args
 
-- 
1.7.1

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to