package-installs: add list to arch and "not-arch" list
Icf8a075224833fcfbbe2128e8802ff41c39f3c09 looked rather ugly, and it's
easy for us to expand the processing done in the arch list.
Change "arch" to a comma-separated list of architectures that should
match for install.
Add a "not-arch" list which will exclude the package from installation
on those architectures.  (An aside -- I considered making it just he
one list with foo,!bar,moo but ! has special meaning in YAML, so it's
easier to have two lists).
$ ARCH=ppc64 package-installs-squash --elements ironic-agent --path=./elements/ /dev/stdout | grep dmidecode
$ ARCH=ppc64 package-installs-squash --elements ironic-agent --path=./elements/ /dev/stdout | grep lshw
    "lshw",
$ ARCH=amd64 package-installs-squash --elements ironic-agent --path=./elements/ /dev/stdout | grep lshw
$ ARCH=amd64 package-installs-squash --elements ironic-agent --path=./elements/ /dev/stdout | grep dmidecode
    "dmidecode",
Change-Id: Ic69dd02a09e6f3ba9078a2377d8df29871a20db2
			
			
This commit is contained in:
		 Ian Wienand
					Ian Wienand
				
			
				
					committed by
					
						 Andreas Florath
						Andreas Florath
					
				
			
			
				
	
			
			
			 Andreas Florath
						Andreas Florath
					
				
			
						parent
						
							76bf793a39
						
					
				
				
					commit
					8a1c8370a1
				
			| @@ -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: | ||||
|   | ||||
| @@ -9,7 +9,9 @@ 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`` | ||||
|  | ||||
| .. code-block:: YAML | ||||
|  | ||||
|   libxml2: | ||||
|   grub2: | ||||
| @@ -20,8 +22,14 @@ example package-installs.yaml:: | ||||
|     installtype: source | ||||
|   linux-image-amd64: | ||||
|     arch: amd64 | ||||
|   dmidecode: | ||||
|     not-arch: ppc64, ppc64le | ||||
|   lshw: | ||||
|     arch: ppc64, ppc64le | ||||
|  | ||||
| example package-installs.json:: | ||||
| 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-<element-name> will cause | ||||
|   | ||||
| @@ -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 | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -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. | ||||
		Reference in New Issue
	
	Block a user