From: Cleber Rosa <[email protected]>

On the software manager module itself. So that other tests, if they
chose to, can also use this handy mechanism.

Signed-off-by: Cleber Rosa <[email protected]>
---
 client/shared/software_manager.py | 34 ++++++++++++++++++++++++++++++++++
 client/tests/xfstests/control     | 15 +--------------
 2 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/client/shared/software_manager.py 
b/client/shared/software_manager.py
index 7b154e7..4d72460 100755
--- a/client/shared/software_manager.py
+++ b/client/shared/software_manager.py
@@ -722,6 +722,40 @@ class AptBackend(DpkgBackend):
             return None
 
 
+def install_distro_packages(distro_pkg_map):
+    '''
+    Installs packages for the currently running distribution
+
+    This utility function checks if the currently running distro is a
+    key in the distro_pkg_map dictionary, and if there is a list of packages
+    set as its value.
+
+    If these conditions match, the packages will be installed using the
+    software manager interface, thus the native packaging system if the
+    currenlty running distro.
+
+    @type disto_pkg_map: dict
+    @param distro_pkg_map: mapping of distro name, as returned by
+        utils.get_os_vendor(), to a list of package names
+    @returns: True if any packages were actually installed, False otherwise
+    '''
+    result = False
+    distro = utils.get_os_vendor()
+    if distro_pkg_map.has_key(distro):
+        pkgs = distro_pkg_map.get(distro, None)
+        needed_pkgs = []
+        if pkgs is not None:
+            s = SoftwareManager()
+            for p in pkgs:
+                if not s.check_installed(p):
+                    needed_pkgs.append(p)
+        if needed_pkgs:
+            text = ' '.join(needed_pkgs)
+            logging.info('Installing packages "%s"', text)
+            result = s.install(text)
+    return result
+
+
 if __name__ == '__main__':
     parser = optparse.OptionParser(
     "usage: %prog 
[install|remove|check-installed|list-all|list-files|add-repo|"
diff --git a/client/tests/xfstests/control b/client/tests/xfstests/control
index 1466daf..e25d300 100644
--- a/client/tests/xfstests/control
+++ b/client/tests/xfstests/control
@@ -69,20 +69,7 @@ from autotest.client.shared import software_manager
 from autotest.client import partition
 
 # Install package dependencies if your distro is present in PKG_DEPS
-distro = utils.get_os_vendor()
-if PKG_DEPS.has_key(distro):
-    deps = PKG_DEPS.get(distro, None)
-    real_deps = []
-    if deps is not None:
-        s = software_manager.SoftwareManager()
-        for d in deps:
-            if not s.check_installed(d):
-                real_deps.append(d)
-    if real_deps:
-        real_deps_text = ' '.join(real_deps)
-        logging.info('Installing xfstests dependency "%s"', real_deps_text)
-        s.install(real_deps_text)
-
+software_manager.install_distro_packages(PKG_DEPS)
 
 # Define the partitions you want to use.
 #
-- 
1.7.11.2

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to