From patchwork Mon Nov 16 05:16:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 60214 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAG5Gvrl020665 for ; Mon, 16 Nov 2009 05:16:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751360AbZKPFQt (ORCPT ); Mon, 16 Nov 2009 00:16:49 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751339AbZKPFQs (ORCPT ); Mon, 16 Nov 2009 00:16:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52021 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750770AbZKPFQs (ORCPT ); Mon, 16 Nov 2009 00:16:48 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAG5GmP7012934 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Nov 2009 00:16:48 -0500 Received: from localhost.localdomain (vpn-11-32.rdu.redhat.com [10.11.11.32]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAG5GjS4016173; Mon, 16 Nov 2009 00:16:46 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, jadmanski@google.com, Lucas Meneghel Rodrigues Subject: [PATCH] Make a standalone client to be able to use global_config.ini Date: Mon, 16 Nov 2009 03:16:45 -0200 Message-Id: <1258348605-10897-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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@google.com (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