From: Don Zickus <dzic...@redhat.com>

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)

In order to completely abstract the use of the
job.add_repo to control files, just set fetch_location
in global_config.ini.

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

diff --git a/client/cmdparser.py b/client/cmdparser.py
index 165551f..f69a200 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
 
@@ -15,6 +16,16 @@ GLOBALDIRTEST = GLOBAL_CONFIG.get_config_value('COMMON',
                                                'test_dir',
                                                 default="")
 
+tmpdir = os.path.abspath(os.path.join('.', 'tmp'))
+
+FETCHDIRTEST = GLOBAL_CONFIG.get_config_value('COMMON',
+                                               'test_output_dir',
+                                                default=tmpdir)
+FETCHDIRTEST = os.path.join(FETCHDIRTEST, 'site_tests')
+
+if not os.path.isdir(FETCHDIRTEST):
+    os.makedirs(FETCHDIRTEST)
+
 DEBUG = False
 
 
@@ -23,7 +34,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 +77,45 @@ 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()
+
+        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 +124,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 +158,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 +228,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.10.4

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

Reply via email to