[PATCH] Make a standalone client to be able to use global_config.ini

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In order to make it possible the autotest client to use the
global_config.ini configuration files:

 * Modified global_config.py to support verifying if the
   configuration file is under autotest's root directory,
   or the client directory
 * Extended the autotest client install methods to copy
   over the configuration files with the client.

While there, fixed a small bug: server/autotest.py was making reference to an
exception class not present under common_lib.error

Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx>
---
 client/common_lib/error.py         |    5 +++++
 client/common_lib/global_config.py |   34 ++++++++++++++++++++++++++++------
 server/autotest.py                 |   33 +++++++++++++++++++++++----------
 utils/packager.py                  |   18 +++++++++++++++---
 4 files changed, 71 insertions(+), 19 deletions(-)

diff --git a/client/common_lib/error.py b/client/common_lib/error.py
index 08401ce..9e0002d 100644
--- a/client/common_lib/error.py
+++ b/client/common_lib/error.py
@@ -185,6 +185,11 @@ class AutoservError(Exception):
     pass
 
 
+class AutoservInstallError(Exception):
+    """Autoserv failed in installing autotest on a client machine"""
+    pass
+
+
 class AutoservSSHTimeout(AutoservError):
     """SSH experienced a connection timeout"""
     pass
diff --git a/client/common_lib/global_config.py b/client/common_lib/global_config.py
index 2bbeca0..f27a14c 100644
--- a/client/common_lib/global_config.py
+++ b/client/common_lib/global_config.py
@@ -8,12 +8,6 @@ __author__ = 'raphtee@xxxxxxxxxx (Travis Miller)'
 import os, sys, ConfigParser
 from autotest_lib.client.common_lib import error
 
-dirname = os.path.dirname(sys.modules[__name__].__file__)
-DEFAULT_CONFIG_FILE = os.path.abspath(os.path.join(dirname,
-                                                "../../global_config.ini"))
-DEFAULT_SHADOW_FILE = os.path.abspath(os.path.join(dirname,
-                                                "../../shadow_config.ini"))
-
 
 class ConfigError(error.AutotestError):
     pass
@@ -23,6 +17,34 @@ class ConfigValueError(ConfigError):
     pass
 
 
+
+common_lib_dir = os.path.dirname(sys.modules[__name__].__file__)
+client_dir = os.path.dirname(common_lib_dir)
+root_dir = os.path.dirname(client_dir)
+
+# Check if the config files are at autotest's root dir
+# This will happen if client is executing inside a full autotest tree, or if
+# other entry points are being executed
+global_config_path_root = os.path.join(root_dir, 'global_config.ini')
+shadow_config_path_root = os.path.join(root_dir, 'shadow_config.ini')
+config_in_root = (os.path.exists(global_config_path_root) and
+                  os.path.exists(shadow_config_path_root))
+
+# Check if the config files are at autotest's client dir
+# This will happen if a client stand alone execution is happening
+global_config_path_client = os.path.join(client_dir, 'global_config.ini')
+shadow_config_path_client = os.path.join(client_dir, 'shadow_config.ini')
+config_in_client = (os.path.exists(global_config_path_client) and
+                    os.path.exists(shadow_config_path_client))
+
+if config_in_root:
+    DEFAULT_CONFIG_FILE = global_config_path_root
+    DEFAULT_SHADOW_FILE = shadow_config_path_root
+elif config_in_client:
+    DEFAULT_CONFIG_FILE = global_config_path_client
+    DEFAULT_SHADOW_FILE = shadow_config_path_client
+
+
 class global_config(object):
     _NO_DEFAULT_SPECIFIED = object()
 
diff --git a/server/autotest.py b/server/autotest.py
index 3d307a9..120ab61 100644
--- a/server/autotest.py
+++ b/server/autotest.py
@@ -151,12 +151,25 @@ class BaseAutotest(installable_object.InstallableObject):
         self.installed = True
 
 
-    def _install_using_send_file(self, host, autodir):
-        dirs_to_exclude = set(["tests", "site_tests", "deps", "profilers"])
-        light_files = [os.path.join(self.source_material, f)
-                       for f in os.listdir(self.source_material)
-                       if f not in dirs_to_exclude]
-        host.send_file(light_files, autodir, delete_dest=True)
+    def _install_using_send_file(self, host, autodir, full):
+        if full:
+            dirs_to_exclude = set([])
+        else:
+            dirs_to_exclude = set(["tests", "site_tests", "deps", "profilers"])
+
+        files = []
+        for f in os.listdir(self.source_material):
+            if f not in dirs_to_exclude:
+                files.append(os.path.join(self.source_material, f))
+
+        # We will also add the global configuration files to the bundle
+        root_dir = os.path.dirname(self.serverdir)
+        global_config = os.path.join(root_dir, 'global_config.ini')
+        shadow_config = os.path.join(root_dir, 'shadow_config.ini')
+        files.append(global_config)
+        files.append(shadow_config)
+        # Copy the files to the host
+        host.send_file(files, autodir, delete_dest=True)
 
         # create empty dirs for all the stuff we excluded
         commands = []
@@ -165,7 +178,8 @@ class BaseAutotest(installable_object.InstallableObject):
             abs_path = utils.sh_escape(abs_path)
             commands.append("mkdir -p '%s'" % abs_path)
             commands.append("touch '%s'/__init__.py" % abs_path)
-        host.run(';'.join(commands))
+        if commands:
+            host.run(';'.join(commands))
 
 
     def _install(self, host=None, autodir=None, use_autoserv=True,
@@ -223,10 +237,9 @@ class BaseAutotest(installable_object.InstallableObject):
                     "PACKAGES", "serve_packages_from_autoserv", type=bool)
                 # Copy autotest recursively
                 if supports_autoserv_packaging and use_autoserv:
-                    self._install_using_send_file(host, autodir)
+                    self._install_using_send_file(host, autodir, full=False)
                 else:
-                    host.send_file(self.source_material, autodir,
-                                   delete_dest=True)
+                    self._install_using_send_file(host, autodir, full=True)
             else:
                 # Copy autotest via tarball
                 e_msg = 'Installation method not yet implemented!'
diff --git a/utils/packager.py b/utils/packager.py
index e8e4a45..0a7fdac 100755
--- a/utils/packager.py
+++ b/utils/packager.py
@@ -77,9 +77,19 @@ def process_packages(pkgmgr, pkg_type, pkg_names, src_dir, repo_url,
     names = [p.strip() for p in pkg_names.split(',')]
     for name in names:
         print "Processing %s ... " % name
+        copy_config = False
         if pkg_type=='client':
             pkg_dir = src_dir
             exclude_string  = get_exclude_string(pkg_dir)
+            copy_config = True
+            global_config_src = os.path.join(os.path.dirname(src_dir),
+                                             'global_config.ini')
+            shadow_config_src = os.path.join(os.path.dirname(src_dir),
+                                             'shadow_config.ini')
+            global_config_dst = os.path.join(src_dir, 'global_config.ini')
+            shadow_config_dst = os.path.join(src_dir, 'shadow_config.ini')
+            shutil.copy(global_config_src, global_config_dst)
+            shutil.copy(shadow_config_src, shadow_config_dst)
         elif pkg_type=='test':
             # if the package is a test then look whether it is in client/tests
             # or client/site_tests
@@ -103,6 +113,9 @@ def process_packages(pkgmgr, pkg_type, pkg_names, src_dir, repo_url,
                                                   temp_dir, exclude_string)
                 pkgmgr.upload_pkg(tarball_path, repo_url, update_checksum=True)
             finally:
+                if copy_config:
+                    os.unlink(global_config_dst)
+                    os.unlink(shadow_config_dst)
                 # remove the temporary directory
                 shutil.rmtree(temp_dir)
         else:
@@ -129,9 +142,8 @@ def tar_packages(pkgmgr, pkg_type, pkg_names, src_dir, temp_dir):
             pkg_dir = os.path.join(src_dir, name)
 
         pkg_name = pkgmgr.get_tarball_name(name, pkg_type)
-        tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir,
-                                              temp_dir, exclude_string)
-
+        tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir, temp_dir,
+                                          exclude_string)
         tarballs.append(tarball_path)
 
     return tarballs
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux