[libvirt] [jenkins-ci PATCH v4 4/5] mappings: extend mapping to allow per-arch entries

Daniel P. Berrangé berrange at redhat.com
Thu Feb 21 16:33:53 UTC 2019


For example to prevent Xen being installed on any s390x

  xen:
    default-s390x:
    deb: libxen-dev
    Fedora: xen-devel

Or the inverse to only install Xen on x86_64 on Debian, but allow
it on all archs on Fedora

  xen:
    deb-x86_64: libxen-dev
    Fedora: xen-devel

Note that the architecture specific matches are considered after
all the non-architcture matches.

The mappings are updated to blacklist libnuma on arm6/7 for Debian
since it is not built for those archs. xen is whitelisted to only
be used on x86_64, arm7 and aarch64 for Debian, since the majority
of other architectures don't support it.

The dockerfile generator is updated to apply arch filtering based
on the host arch.

The ansible playbook is not actually implementing support for
non-x86_64 architectures in this commit. It is just hardcoding
x86_64, which is enough to ensure the changes in the mappings.yml
file are a no-op initially.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 guests/lcitool                             | 17 ++++++++-
 guests/playbooks/update/tasks/packages.yml | 32 +++++++++++++++++
 guests/vars/mappings.yml                   | 42 +++++++++++++++++++---
 3 files changed, 86 insertions(+), 5 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 2af6878..ae7e4ee 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -21,6 +21,7 @@ import crypt
 import fnmatch
 import json
 import os
+import platform
 import random
 import string
 import subprocess
@@ -303,6 +304,8 @@ class Application:
         self._inventory = Inventory()
         self._projects = Projects()
 
+        self._native_arch = self._libvirt_host_arch()
+
         self._parser = argparse.ArgumentParser(
             conflict_handler="resolve",
             formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -433,6 +436,15 @@ class Application:
             raise Error(
                 "Failed to run {} on '{}': {}".format(playbook, hosts, ex))
 
+    def _libvirt_host_arch(self):
+        # Same canonicalization as libvirt virArchFromHost
+        arch = platform.machine()
+        if arch in ["i386", "i486", "i586"]:
+            arch = "i686"
+        if arch == "amd64":
+            arch = "x86_64"
+        return arch
+
     def _action_hosts(self, args):
         for host in self._inventory.expand_pattern("all"):
             print(host)
@@ -549,7 +561,8 @@ class Application:
                 )
 
         pkgs = {}
-        keys = ["default", package_format, os_name, os_full]
+        base_keys = ["default", package_format, os_name, os_full]
+        keys = base_keys + [k + "-" + self._native_arch for k in base_keys]
         # We need to add the base project manually here: the standard
         # machinery hides it because it's an implementation detail
         for project in projects + ["base"]:
@@ -558,6 +571,8 @@ class Application:
                     if key in mappings[package]:
                         pkgs[package] = mappings[package][key]
 
+                if package not in pkgs:
+                    continue
                 if pkgs[package] is None:
                     del pkgs[package]
 
diff --git a/guests/playbooks/update/tasks/packages.yml b/guests/playbooks/update/tasks/packages.yml
index 7fdfc45..b3b8a27 100644
--- a/guests/playbooks/update/tasks/packages.yml
+++ b/guests/playbooks/update/tasks/packages.yml
@@ -52,6 +52,38 @@
   when:
     - mappings[item][os_name + os_version] is defined
 
+- name: '{{ project }}: Look up mappings (default with arch)'
+  set_fact:
+    temp: '{{ temp|combine({ item: mappings[item]["default" + "-" + "x86_64"] }) }}'
+  with_items:
+    '{{ packages }}'
+  when:
+    - mappings[item]["default" + "-" + "x86_64"] is defined
+
+- name: '{{ project }}: Look up mappings (package format with arch)'
+  set_fact:
+    temp: '{{ temp|combine({ item: mappings[item][package_format + "-" + "x86_64"] }) }}'
+  with_items:
+    '{{ packages }}'
+  when:
+    - mappings[item][package_format + "-" + "x86_64"] is defined
+
+- name: '{{ project }}: Look up mappings (OS name with arch)'
+  set_fact:
+    temp: '{{ temp|combine({ item: mappings[item][os_name + "-" + "x86_64"] }) }}'
+  with_items:
+    '{{ packages }}'
+  when:
+    - mappings[item][os_name + "-" + "x86_64"] is defined
+
+- name: '{{ project }}: Look up mappings (OS version with arch)'
+  set_fact:
+    temp: '{{ temp|combine({ item: mappings[item][os_name + os_version + "-" + "x86_64"] }) }}'
+  with_items:
+    '{{ packages }}'
+  when:
+    - mappings[item][os_name + os_version + "-" + "x86_64"] is defined
+
 - set_fact:
     flattened: []
 
diff --git a/guests/vars/mappings.yml b/guests/vars/mappings.yml
index f31b460..4ca8fae 100644
--- a/guests/vars/mappings.yml
+++ b/guests/vars/mappings.yml
@@ -7,9 +7,25 @@
 # priority:
 #
 #   - default
-#   - package format (deb, pkg, rpm)
-#   - OS name (CentOS, Debian, Fedora, FreeBSD, Ubuntu)
-#   - OS version (CentOS7, Debian9, FedoraRawhide, Ubuntu18 and so on)
+#   - package format
+#   - OS name
+#   - OS version
+#   - default with arch
+#   - package format with arch
+#   - OS name with arch
+#   - OS version with arch
+#
+# Valid package formats are
+#   - deb, pkg, rpm
+#
+# Valid OS names are:
+#   - CentOS, Debian, Fedora, FreeBSD, Ubuntu
+#
+# Valid OS versions are:
+#   - CentOS7, Debian9, FedoraRawhide, Ubuntu18 and so on
+#
+# The 'with arch' levels take a suffix "-$ARCH" where  $ARCH
+# is a libvirt arch name.
 #
 # So something like
 #
@@ -27,6 +43,20 @@
 #
 # will result in the 'ccache' package being installed everywhere except
 # for CentOS, where nothing will be installed.
+#
+# For example to prevent Xen being installed on any s390x
+#
+#  xen:
+#    default-s390x:
+#    deb: libxen-dev
+#    Fedora: xen-devel
+#
+# Or the inverse to only install Xen on x86_64
+#
+#  xen:
+#    deb-x86_64: libxen-dev
+#    Fedora-x86_64: xen-devel
+#
 
 mappings:
 
@@ -278,6 +308,8 @@ mappings:
 
   libnuma:
     deb: libnuma-dev
+    deb-armv6l:
+    deb-armv7l:
     rpm: numactl-devel
 
   libparted:
@@ -817,7 +849,9 @@ mappings:
     Debian8:
 
   xen:
-    deb: libxen-dev
+    deb-x86_64: libxen-dev
+    deb-armv7l: libxen-dev
+    deb-aarch64: libxen-dev
     Fedora: xen-devel
 
   xfsprogs:
-- 
2.20.1




More information about the libvir-list mailing list