diff --git a/elements/ironic-agent/package-installs.yaml b/elements/ironic-agent/package-installs.yaml index 71994e333..0e4ea7c99 100644 --- a/elements/ironic-agent/package-installs.yaml +++ b/elements/ironic-agent/package-installs.yaml @@ -1,12 +1,10 @@ tgt: curl: -# dmidecode does not exist for ppc* arches so add includes for non ppc +# dmidecode does not exist for ppc* arches so we use lshw dmidecode: - arch: x86_64 -dmidecode: - arch: i386 -dmidecode: - arch: amd64 + not-arch: ppc64,ppc64el +lshw: + arch: ppc64, ppc64el ipmitool: qemu-utils: gcc: @@ -17,6 +15,5 @@ util-linux: genisoimage: gdisk: kmod: -lshw: psmisc: dosfstools: diff --git a/elements/package-installs/README.rst b/elements/package-installs/README.rst index 33fd15c53..8d1027362 100644 --- a/elements/package-installs/README.rst +++ b/elements/package-installs/README.rst @@ -9,19 +9,27 @@ package-installs.yaml or package-installs.json file in the element directory. In order to work on Gentoo hosts you will need to manually install `dev-python/pyyaml`. -example package-installs.yaml:: +example ``package-installs.yaml`` - libxml2: - grub2: - phase: pre-install.d - networkmanager: - uninstall: True - os-collect-config: - installtype: source - linux-image-amd64: - arch: amd64 +.. code-block:: YAML -example package-installs.json:: + libxml2: + grub2: + phase: pre-install.d + networkmanager: + uninstall: True + os-collect-config: + installtype: source + linux-image-amd64: + arch: amd64 + dmidecode: + not-arch: ppc64, ppc64le + lshw: + arch: ppc64, ppc64le + +example package-installs.json + +.. code-block:: json { "libxml2": null, @@ -43,9 +51,11 @@ Setting the installtype property causes the package only to be installed if the specified installtype would be used for the element. See the diskimage-builder docs for more information on installtypes. -Setting the arch property causes the package only to be installed for the -specified target architecture. See documentation about the ARCH variable -for more information. +The ``arch`` property is a comma-separated list of architectures to +install for. The ``not-arch`` is a comma-separated list of +architectures the package should be excluded from. Either ``arch`` or +``not-arch`` can be given for one package - not both. See +documentation about the ARCH variable for more information. DEPRECATED: Adding a file under your elements pre-install.d, install.d, or post-install.d directories called package-installs- will cause diff --git a/elements/package-installs/bin/package-installs-squash b/elements/package-installs/bin/package-installs-squash index ff0cd62a7..49cc76484 100755 --- a/elements/package-installs/bin/package-installs-squash +++ b/elements/package-installs/bin/package-installs-squash @@ -19,7 +19,7 @@ import collections import functools import json import os - +import sys import yaml @@ -30,6 +30,31 @@ def get_element_installtype(element_name): default) +def _is_arch_in_list(strlist): + """Checks if os.environ['ARCH'] is in comma separated strlist""" + strlist = strlist.split(',') + map(str.strip, strlist) + return os.environ['ARCH'] in strlist + + +def _valid_for_arch(pkg_name, arch, not_arch): + """Filter out incorrect ARCH versions""" + if arch is None and not_arch is None: + # nothing specified; always OK + return True + if arch and not_arch: + print("package-installs configuration error: arch and not_arch " + "given for package [%s]" % pkg_name) + sys.exit(1) + # if we have an arch list, our current arch must be in it + # to install. + if arch: + return _is_arch_in_list(arch) + # if we don't have an explicit arch list, we should + # install unless we are in the not-arch list. + return not _is_arch_in_list(not_arch) + + def collect_data(data, filename, element_name): try: objs = json.load(open(filename)) @@ -48,13 +73,12 @@ def collect_data(data, filename, element_name): elem_installtype = get_element_installtype(element_name) valid_installtype = (installtype is None or installtype == elem_installtype) - - # Filter out incorrect ARCH versions - arch = params.get('arch', None) - valid_arch = arch is None or arch == os.environ['ARCH'] + valid_arch = _valid_for_arch(pkg_name, params.get('arch', None), + params.get('not-arch', None)) if valid_installtype and valid_arch: data[phase][install].append((pkg_name, element_name)) + return data diff --git a/releasenotes/notes/package-install-arch-38bb5a6e61794fa5.yaml b/releasenotes/notes/package-install-arch-38bb5a6e61794fa5.yaml new file mode 100644 index 000000000..ccbebae46 --- /dev/null +++ b/releasenotes/notes/package-install-arch-38bb5a6e61794fa5.yaml @@ -0,0 +1,6 @@ +--- +features: + - The ``package-installs`` element now supports a list of + architectures to install the package for in the ``arch`` field and + negative matching with a ``not-arch`` field. This allows greater + flexibility when installing packages for only some architectures. \ No newline at end of file