aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Nasiadka <mnasiadka@gmail.com>2026-11-15 10:40:59 -0600
committerMichal Nasiadka <mnasiadka@gmail.com>2026-11-16 00:07:51 +0000
commita705ddbf5e2418345a1bc971c7878472df9790b5 (patch)
tree66bb0c7c9ba8304982d5fe75d99effd96644b723
parent9eaff51d990bb33884c1a1d801f0ed8e56a4a114 (diff)
downloadkolla-a705ddbf5e2418345a1bc971c7878472df9790b5.tar.gz
kolla-a705ddbf5e2418345a1bc971c7878472df9790b5.zip
CI: Rework process_build_logs to AnsibleHEADmaster
Currently the existing script is having problems parsing extremely long bifrost build logs (that include Ansible output) - let's use the occassion to rework that script to an Ansible module and send output using zuul_return Change-Id: Ib4fc0129b415ffc8ee295a47b48f8df1ff06325e Signed-off-by: Michal Nasiadka <mnasiadka@gmail.com>
-rw-r--r--.ansible-lint2
-rw-r--r--roles/kolla-build-tests/defaults/main.yml21
-rw-r--r--roles/kolla-build-tests/files/list-image-packages.sh57
-rw-r--r--roles/kolla-build-tests/library/kolla_package_report.py253
-rw-r--r--roles/kolla-build-tests/tasks/main.yml50
-rwxr-xr-xtests/files/process_build_logs.py80
-rw-r--r--tests/playbooks/post.yml11
-rw-r--r--tests/test_kolla_package_report.py174
-rw-r--r--zuul.d/base.yaml3
9 files changed, 567 insertions, 84 deletions
diff --git a/.ansible-lint b/.ansible-lint
index 6b5f1f15c..8454088cc 100644
--- a/.ansible-lint
+++ b/.ansible-lint
@@ -3,6 +3,8 @@ exclude_paths:
- .cache/ # implicit unless exclude_paths is defined in config
- zuul.d/
- kolla/template/repos.yaml
+mock_modules:
+ - zuul_return
offline: true
profile: basic
skip_list:
diff --git a/roles/kolla-build-tests/defaults/main.yml b/roles/kolla-build-tests/defaults/main.yml
new file mode 100644
index 000000000..72cacd909
--- /dev/null
+++ b/roles/kolla-build-tests/defaults/main.yml
@@ -0,0 +1,21 @@
+---
+# Path to the kolla-build log files, used to find each image's parent.
+kolla_build_tests_logs_dir: "{{ zuul_output_dir }}/logs/kolla/build"
+
+# Directory to write packages-info.txt and packages-info.json to.
+kolla_build_tests_report_dir: "{{ zuul_output_dir }}/logs/kolla"
+
+# Directory to write the per-image package lists to.
+kolla_build_tests_pkg_dir: "{{ kolla_build_tests_report_dir }}/packages"
+
+# Container engine the images were built with.
+kolla_build_tests_container_engine: "{{ container_engine }}"
+
+# The kolla base_distro the images were built for.
+kolla_build_tests_base_distro: "{{ base_distro }}"
+
+# Report packages installed separately in more than this many images.
+kolla_build_tests_threshold: 10
+
+# Whether to report package suggestions to the change via zuul_return.
+kolla_build_tests_report_to_zuul: false
diff --git a/roles/kolla-build-tests/files/list-image-packages.sh b/roles/kolla-build-tests/files/list-image-packages.sh
new file mode 100644
index 000000000..0c5358c5c
--- /dev/null
+++ b/roles/kolla-build-tests/files/list-image-packages.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# List the packages installed in each kolla image, one <image>.txt file per
+# image with one package name per line.
+#
+# Usage: list-image-packages.sh <container engine> <base distro> <output dir>
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+engine=$1
+base_distro=$2
+outdir=$3
+
+case "${base_distro}" in
+ rocky)
+ query=(rpm -qa --qf '%{NAME}\n')
+ ;;
+ debian|ubuntu)
+ query=(dpkg-query -W -f '${Package}\n')
+ ;;
+ *)
+ echo "Unsupported base distro: ${base_distro}" >&2
+ exit 1
+ ;;
+esac
+
+list_image() {
+ local id=$1
+ local name
+ name=$(sudo "${engine}" image inspect \
+ --format '{{ index .Config.Labels "name" }}' "${id}")
+ if ! sudo "${engine}" run --rm --network none \
+ --entrypoint "${query[0]}" "${id}" "${query[@]:1}" \
+ > "${outdir}/${name}.txt"; then
+ echo "Failed to list packages in ${name}" >&2
+ rm -f "${outdir}/${name}.txt"
+ fi
+}
+
+mkdir -p "${outdir}"
+
+# Only kolla images carry the kolla_version label.
+images=$(sudo "${engine}" images --filter label=kolla_version \
+ --format '{{ .ID }}' | sort -u)
+
+running=0
+for id in ${images}; do
+ list_image "${id}" &
+ running=$((running + 1))
+ if [[ ${running} -ge 8 ]]; then
+ wait -n || true
+ running=$((running - 1))
+ fi
+done
+wait
diff --git a/roles/kolla-build-tests/library/kolla_package_report.py b/roles/kolla-build-tests/library/kolla_package_report.py
new file mode 100644
index 000000000..40f73317e
--- /dev/null
+++ b/roles/kolla-build-tests/library/kolla_package_report.py
@@ -0,0 +1,253 @@
+#!/usr/bin/python
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import collections
+import glob
+import os
+import re
+
+DOCUMENTATION = '''
+---
+module: kolla_package_report
+short_description: Report packages installed separately in many kolla images
+description:
+ - Compares the packages installed in each kolla image with its parent
+ image, using one file per image listing installed package names.
+ - Reports packages installed separately in more than I(threshold) images,
+ with the closest common parent image they could be moved to, and
+ packages an image removes compared with its parent.
+options:
+ logdir:
+ description: Path to the kolla-build log files, used to find each
+ image's parent.
+ required: true
+ type: path
+ pkgdir:
+ description: Path to the package lists, one C(<image>.txt) per image
+ with one package name per line.
+ required: true
+ type: path
+ threshold:
+ description: Report packages installed separately in more than this many
+ images.
+ type: int
+ default: 10
+'''
+
+EXAMPLES = '''
+- name: Report packages installed in kolla images
+ kolla_package_report:
+ logdir: /home/zuul/zuul-output/logs/kolla/build
+ pkgdir: /home/zuul/zuul-output/logs/kolla/packages
+ register: result
+'''
+
+RETURN = '''
+candidates:
+ description: Packages to consider moving to a parent image.
+ returned: always
+ type: list
+removals:
+ description: Packages each image removes compared with its parent.
+ returned: always
+ type: list
+skipped:
+ description: Images skipped because their parent has no package list.
+ returned: always
+ type: list
+package_warnings:
+ description: One line per candidate and per image removing packages.
+ returned: always
+ type: list
+report:
+ description: Human readable report.
+ returned: always
+ type: str
+'''
+
+# Lines longer than this are JSON-escaped output (e.g. bifrost's ansible
+# run) and are expensive to match.
+MAX_LINE = 8192
+
+# docker (BuildKit): INFO:kolla.common.utils.<image>:#<step> [<secs>] <payload>
+# podman: INFO:kolla.common.utils.<image>:<payload>
+PREFIX = re.compile(
+ r'^[A-Z]+:kolla\.common\.utils\.[^:]+:'
+ r'(?:#(\d+) (?:\d+(?:\.\d+)? ?)?)?(.*)$')
+FROM = re.compile(r'^(?:\[\s*1/\d+\]|STEP 1/\d+:) FROM \S*?/([^/:\s]+):')
+
+# rpm's pseudo-package for imported GPG keys, not an installed package.
+IGNORED_PACKAGES = {'gpg-pubkey'}
+
+
+def payloads(lines):
+ for line in lines:
+ if len(line) > MAX_LINE:
+ continue
+ m = PREFIX.match(line.rstrip('\n'))
+ if m:
+ yield m.group(1), m.group(2)
+
+
+def parse_parent(lines):
+ """Return the image named in the first FROM line of a build log."""
+ for _, p in payloads(lines):
+ m = FROM.match(p)
+ if m:
+ return m.group(1)
+ return None
+
+
+def read_packages(path):
+ with open(path) as f:
+ return {line.strip() for line in f
+ if line.strip() and line.strip() not in IGNORED_PACKAGES}
+
+
+def ancestors(image, parents):
+ """Return the parent chain of an image, root first."""
+ chain, seen = [], {image}
+ cur = parents.get(image)
+ while cur and cur not in seen:
+ chain.append(cur)
+ seen.add(cur)
+ cur = parents.get(cur)
+ return chain[::-1]
+
+
+def common_parent(images, parents):
+ common = None
+ for level in zip(*[ancestors(i, parents) for i in images]):
+ if len(set(level)) != 1:
+ break
+ common = level[0]
+ return common
+
+
+def analyse(logdir, pkgdir, threshold):
+ parents = {}
+ for filename in sorted(glob.glob(os.path.join(logdir, '*.log'))):
+ image = os.path.splitext(os.path.basename(filename))[0]
+ with open(filename, errors='replace') as f:
+ parents[image] = parse_parent(f)
+ # Only images built in this run count as parents.
+ parents = {i: p if p in parents else None for i, p in parents.items()}
+
+ pkgs = {}
+ for filename in sorted(glob.glob(os.path.join(pkgdir, '*.txt'))):
+ image = os.path.splitext(os.path.basename(filename))[0]
+ pkgs[image] = read_packages(filename)
+
+ added, removals, skipped = {}, [], []
+ for image in sorted(pkgs):
+ parent = parents.get(image)
+ if parent is None:
+ added[image] = pkgs[image]
+ elif parent in pkgs:
+ added[image] = pkgs[image] - pkgs[parent]
+ removed = pkgs[parent] - pkgs[image]
+ if removed:
+ removals.append({'image': image,
+ 'parent': parent,
+ 'packages': sorted(removed)})
+ else:
+ skipped.append(image)
+
+ where = collections.defaultdict(set)
+ for image, image_pkgs in added.items():
+ for pkg in image_pkgs:
+ where[pkg].add(image)
+
+ candidates = [{'package': pkg,
+ 'images': sorted(images),
+ 'suggested_parent': common_parent(images, parents)}
+ for pkg, images in where.items() if len(images) > threshold]
+ candidates.sort(key=lambda c: (-len(c['images']), c['package']))
+
+ warnings = []
+ for c in candidates:
+ if c['suggested_parent']:
+ warnings.append(
+ '%s is installed by %d images separately; consider '
+ 'installing it once in %s instead' %
+ (c['package'], len(c['images']), c['suggested_parent']))
+ else:
+ warnings.append(
+ '%s is installed by %d images separately, but they have no '
+ 'common parent image' % (c['package'], len(c['images'])))
+ for r in removals:
+ warnings.append('%s removes %s, which its parent %s has installed' %
+ (r['image'], ', '.join(r['packages']), r['parent']))
+ return {'candidates': candidates,
+ 'removals': removals,
+ 'skipped': skipped,
+ 'warnings': warnings}
+
+
+def format_report(report):
+ lines = []
+ if report['candidates']:
+ lines.append(
+ "Consider moving the following packages to a parent image:")
+ for c in report['candidates']:
+ lines.append("%s -> %s (%s)" %
+ (c['package'],
+ c['suggested_parent'] or '(no common parent)',
+ ', '.join(c['images'])))
+ lines.append('')
+
+ if report['removals']:
+ lines.append("Packages removed compared with the parent image:")
+ for r in report['removals']:
+ lines.append("%s (parent %s): %s" %
+ (r['image'], r['parent'], ', '.join(r['packages'])))
+ lines.append('')
+
+ if report['skipped']:
+ lines.append("Skipped (parent has no package list): %s" %
+ ', '.join(report['skipped']))
+ lines.append('')
+ return '\n'.join(lines)
+
+
+def main():
+ # Imported here so the parsing functions can be unit tested on Python
+ # versions without ansible-core (see test-requirements.txt).
+ from ansible.module_utils.basic import AnsibleModule
+
+ module = AnsibleModule(
+ argument_spec=dict(
+ logdir=dict(type='path', required=True),
+ pkgdir=dict(type='path', required=True),
+ threshold=dict(type='int', default=10),
+ ),
+ supports_check_mode=True,
+ )
+ p = module.params
+ for opt in ('logdir', 'pkgdir'):
+ if not os.path.isdir(p[opt]):
+ module.fail_json(msg='%s is not a directory' % p[opt])
+
+ report = analyse(p['logdir'], p['pkgdir'], p['threshold'])
+ # 'warnings' is reserved for Ansible's own warnings.
+ module.exit_json(changed=False,
+ candidates=report['candidates'],
+ removals=report['removals'],
+ skipped=report['skipped'],
+ package_warnings=report['warnings'],
+ report=format_report(report))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/roles/kolla-build-tests/tasks/main.yml b/roles/kolla-build-tests/tasks/main.yml
new file mode 100644
index 000000000..2688ebeaf
--- /dev/null
+++ b/roles/kolla-build-tests/tasks/main.yml
@@ -0,0 +1,50 @@
+---
+- name: Report packages installed in kolla images
+ block:
+ - name: List installed packages in each image
+ ansible.builtin.script:
+ cmd: >-
+ list-image-packages.sh
+ {{ kolla_build_tests_container_engine }}
+ {{ kolla_build_tests_base_distro }}
+ {{ kolla_build_tests_pkg_dir }}
+ changed_when: false
+ timeout: 1800
+
+ - name: Compare installed packages with parent images
+ kolla_package_report:
+ logdir: "{{ kolla_build_tests_logs_dir }}"
+ pkgdir: "{{ kolla_build_tests_pkg_dir }}"
+ threshold: "{{ kolla_build_tests_threshold }}"
+ register: kolla_build_tests_packages
+
+ - name: Save package report
+ ansible.builtin.copy:
+ content: "{{ kolla_build_tests_packages.report }}"
+ dest: "{{ kolla_build_tests_report_dir }}/packages-info.txt"
+ mode: "0644"
+
+ - name: Report package suggestions to Zuul
+ zuul_return:
+ data:
+ zuul:
+ warnings: "{{ kolla_build_tests_packages.package_warnings | map('regex_replace', '^', zuul.job ~ ': ') | list }}"
+ when:
+ - kolla_build_tests_report_to_zuul | bool
+ - kolla_build_tests_packages.package_warnings | length > 0
+
+ - name: Save package report as JSON
+ vars:
+ packages_info:
+ candidates: "{{ kolla_build_tests_packages.candidates }}"
+ removals: "{{ kolla_build_tests_packages.removals }}"
+ skipped: "{{ kolla_build_tests_packages.skipped }}"
+ package_warnings: "{{ kolla_build_tests_packages.package_warnings }}"
+ ansible.builtin.copy:
+ content: "{{ packages_info | to_nice_json }}"
+ dest: "{{ kolla_build_tests_report_dir }}/packages-info.json"
+ mode: "0644"
+ rescue:
+ - name: Package report failed
+ ansible.builtin.debug:
+ msg: "Package report failed, see the failed task above. Not failing the job."
diff --git a/tests/files/process_build_logs.py b/tests/files/process_build_logs.py
deleted file mode 100755
index 248acf954..000000000
--- a/tests/files/process_build_logs.py
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/usr/bin/python3
-
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import argparse
-import collections
-import glob
-import os
-import re
-import sys
-
-parser = argparse.ArgumentParser(
- description='Parse kolla build logs and extract useful information about '
- 'the installed packages.')
-parser.add_argument('-l', '--logdir',
- help='Path to the build log files',
- required=True)
-parser.add_argument('-b', '--base',
- help='The kolla base_distro',
- required=True)
-args = vars(parser.parse_args())
-
-if args['base'] != 'rocky':
- print("Non rpm-based distros are not yet supported.")
- sys.exit()
-
-obsolete = {}
-pkg_installs = collections.defaultdict(set)
-
-for filename in glob.glob(os.path.join(args['logdir'], '*.log')):
- image = os.path.splitext(os.path.basename(filename))[0]
- with open(filename) as f:
- for line in f:
- m = re.search(r"Package (.+) is obsoleted by (.+),", line)
- if m:
- if not m.group(1) in obsolete:
- obsolete[m.group(1)] = {'obsoleted_by': m.group(2),
- 'images': [image]}
- else:
- obsolete[m.group(1)]['images'].append(image)
-
- m = re.search(r"Package (.+)\..+ .+ will be installed", line)
- if m:
- pkg_installs[m.group(1)].add(image)
-
- m = re.search(r"Processing Dependency: (.+)\(", line)
- if m:
- pkg_installs[m.group(1)].add(image)
-
-if obsolete:
- print("Found %s obsolete(s) package(s):" % len(obsolete))
- for pkg in obsolete:
- print("%s is obsoleted by %s (%s)" %
- (pkg,
- obsolete[pkg]['obsoleted_by'],
- ', '.join(obsolete[pkg]['images'])))
- print('')
-
-move_to_base_candidates = [
- pkg for pkg in pkg_installs if len(pkg_installs[pkg]) > 10
- and not ('base' in pkg_installs[pkg]
- or 'openstack-base' in pkg_installs[pkg])
-]
-
-if move_to_base_candidates:
- print("Consider moving the following packages to a base image:")
- for pkg in move_to_base_candidates:
- print("%s (%s)" %
- (pkg,
- ', '.join(pkg_installs[pkg])))
diff --git a/tests/playbooks/post.yml b/tests/playbooks/post.yml
index a5998468b..028fc7b5e 100644
--- a/tests/playbooks/post.yml
+++ b/tests/playbooks/post.yml
@@ -68,9 +68,12 @@
# last sudo to own all files
sudo chown -R {{ ansible_user_id }}: .
-
- # Parse build logs and extract pkg install info
- {{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/files/process_build_logs.py \
- -l build -b {{ base_distro }} > packages-info.txt
executable: /bin/bash
chdir: "{{ kolla_logs_dir }}"
+
+ - name: Import kolla-build-tests role
+ import_role:
+ name: kolla-build-tests
+ vars:
+ kolla_build_tests_logs_dir: "{{ kolla_build_logs_dir }}"
+ kolla_build_tests_report_dir: "{{ kolla_logs_dir }}"
diff --git a/tests/test_kolla_package_report.py b/tests/test_kolla_package_report.py
new file mode 100644
index 000000000..61618fa3e
--- /dev/null
+++ b/tests/test_kolla_package_report.py
@@ -0,0 +1,174 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import importlib.util
+import os.path
+import sys
+
+import fixtures
+from oslotest import base
+
+
+def load_module(name, path):
+ module_spec = importlib.util.spec_from_file_location(
+ name, path
+ )
+ module = importlib.util.module_from_spec(module_spec)
+ module_spec.loader.exec_module(module)
+ return module
+
+
+# kolla_package_report is an Ansible module in a role, not part of the kolla
+# package, so load it by path.
+this_dir = os.path.dirname(sys.modules[__name__].__file__)
+kolla_package_report = load_module(
+ 'kolla_package_report',
+ os.path.join(this_dir, '..', 'roles', 'kolla-build-tests', 'library',
+ 'kolla_package_report.py'))
+
+
+class ParseParentTest(base.BaseTestCase):
+
+ def test_buildkit(self):
+ self.assertEqual('nova-base', kolla_package_report.parse_parent([
+ 'INFO:kolla.common.utils.nova-api:#2 [internal] load metadata '
+ 'for docker.io/kolla/nova-base:master-rocky-10\n',
+ 'INFO:kolla.common.utils.nova-api:#4 [1/7] FROM '
+ 'docker.io/kolla/nova-base:master-rocky-10@sha256:00\n']))
+
+ def test_buildkit_padded(self):
+ self.assertEqual('openstack-base', kolla_package_report.parse_parent([
+ 'INFO:kolla.common.utils.nova-base:#5 [ 1/23] FROM '
+ 'docker.io/kolla/openstack-base:master-rocky-10@sha256:00\n']))
+
+ def test_podman(self):
+ self.assertEqual('openstack-base', kolla_package_report.parse_parent([
+ 'INFO:kolla.common.utils.nova-base:STEP 1/15: FROM '
+ 'kolla/openstack-base:master-rocky-10\n']))
+
+ def test_external_base(self):
+ self.assertEqual('rockylinux', kolla_package_report.parse_parent([
+ 'INFO:kolla.common.utils.base:#5 [ 1/23] FROM '
+ 'quay.io/rockylinux/rockylinux:10@sha256:00\n']))
+
+ def test_no_from(self):
+ self.assertIsNone(kolla_package_report.parse_parent([
+ 'INFO:kolla.common.utils.base:Building started\n',
+ 'INFO:kolla.common.utils.base:#5 ' + 'x' * 200000 + '\n']))
+
+
+class AnalyseTest(base.BaseTestCase):
+
+ PARENTS = {'base': None, 'openstack-base': 'base',
+ 'nova-base': 'openstack-base', 'nova-api': 'nova-base',
+ 'nova-compute': 'nova-base', 'cinder-base': 'openstack-base'}
+
+ def setUp(self):
+ super().setUp()
+ tmp = self.useFixture(fixtures.TempDir()).path
+ self.logdir = os.path.join(tmp, 'build')
+ self.pkgdir = os.path.join(tmp, 'packages')
+ os.mkdir(self.logdir)
+ os.mkdir(self.pkgdir)
+
+ def _image(self, image, parent, packages=None):
+ with open(os.path.join(self.logdir, image + '.log'), 'w') as f:
+ f.write('INFO:kolla.common.utils.%s:#4 [1/3] FROM '
+ 'docker.io/kolla/%s:master-rocky-10@sha256:00\n' %
+ (image, parent))
+ if packages is not None:
+ with open(os.path.join(self.pkgdir, image + '.txt'), 'w') as f:
+ f.write(''.join(p + '\n' for p in packages))
+
+ def test_common_parent(self):
+ self.assertEqual('nova-base', kolla_package_report.common_parent(
+ ['nova-api', 'nova-compute'], self.PARENTS))
+ self.assertEqual('openstack-base', kolla_package_report.common_parent(
+ ['nova-api', 'cinder-base'], self.PARENTS))
+ self.assertIsNone(kolla_package_report.common_parent(
+ ['base', 'nova-api'], self.PARENTS))
+
+ def test_analyse(self):
+ self._image('base', 'rockylinux', ['bash', 'libbar', 'gpg-pubkey'])
+ self._image('openstack-base', 'base', ['bash', 'git'])
+ self._image('nova-base', 'openstack-base', ['bash', 'git', 'libnl3'])
+ self._image('cinder-base', 'openstack-base', ['bash', 'git', 'libnl3'])
+ self._image('nova-api', 'nova-base',
+ ['bash', 'git', 'libnl3', 'libbar', 'libfoo'])
+ self._image('nova-compute', 'nova-base',
+ ['bash', 'git', 'libnl3', 'libfoo', 'gpg-pubkey'])
+
+ report = kolla_package_report.analyse(self.logdir, self.pkgdir, 1)
+
+ self.assertEqual(
+ [{'package': 'libbar',
+ 'images': ['base', 'nova-api'],
+ 'suggested_parent': None},
+ {'package': 'libfoo',
+ 'images': ['nova-api', 'nova-compute'],
+ 'suggested_parent': 'nova-base'},
+ {'package': 'libnl3',
+ 'images': ['cinder-base', 'nova-base'],
+ 'suggested_parent': 'openstack-base'}],
+ report['candidates'])
+ self.assertEqual(
+ [{'image': 'openstack-base', 'parent': 'base',
+ 'packages': ['libbar']}],
+ report['removals'])
+ self.assertEqual([], report['skipped'])
+ self.assertEqual(
+ ['libbar is installed by 2 images separately, but they have no '
+ 'common parent image',
+ 'libfoo is installed by 2 images separately; consider '
+ 'installing it once in nova-base instead',
+ 'libnl3 is installed by 2 images separately; consider '
+ 'installing it once in openstack-base instead',
+ 'openstack-base removes libbar, which its parent base has '
+ 'installed'],
+ report['warnings'])
+ self.assertEqual([], kolla_package_report.analyse(
+ self.logdir, self.pkgdir, 2)['candidates'])
+
+ def test_parent_without_package_list_skipped(self):
+ self._image('base', 'rockylinux', ['bash'])
+ self._image('openstack-base', 'base')
+ self._image('nova-base', 'openstack-base', ['bash', 'git', 'libnl3'])
+
+ report = kolla_package_report.analyse(self.logdir, self.pkgdir, 0)
+
+ self.assertEqual(['nova-base'], report['skipped'])
+ self.assertEqual(['bash'],
+ [c['package'] for c in report['candidates']])
+
+ def test_format_report(self):
+ report = {'candidates': [{'package': 'libnl3',
+ 'images': ['cinder-base', 'nova-base'],
+ 'suggested_parent': 'openstack-base'},
+ {'package': 'libbar',
+ 'images': ['base', 'nova-api'],
+ 'suggested_parent': None}],
+ 'removals': [{'image': 'cinder-volume',
+ 'parent': 'cinder-base',
+ 'packages': ['foo', 'bar']}],
+ 'skipped': ['nova-base']}
+ self.assertEqual(
+ 'Consider moving the following packages to a parent image:\n'
+ 'libnl3 -> openstack-base (cinder-base, nova-base)\n'
+ 'libbar -> (no common parent) (base, nova-api)\n'
+ '\n'
+ 'Packages removed compared with the parent image:\n'
+ 'cinder-volume (parent cinder-base): foo, bar\n'
+ '\n'
+ 'Skipped (parent has no package list): nova-base\n',
+ kolla_package_report.format_report(report))
+ self.assertEqual('', kolla_package_report.format_report(
+ {'candidates': [], 'removals': [], 'skipped': []}))
diff --git a/zuul.d/base.yaml b/zuul.d/base.yaml
index 21cc98371..f1cce8627 100644
--- a/zuul.d/base.yaml
+++ b/zuul.d/base.yaml
@@ -88,6 +88,9 @@
base_distro_version: "{{ zuul.job.split('-').3 }}"
publisher: false
container_engine: "docker"
+ # Report package suggestions to the change only from the main
+ # kolla-build-<distro>-<version> jobs, not their variants.
+ kolla_build_tests_report_to_zuul: "{{ zuul.job is match('kolla-build-[^-]+-[^-]+$') }}"
extra-vars:
kolla_logs_dir: "{{ zuul_output_dir }}/logs/kolla"
kolla_build_logs_dir: "{{ kolla_logs_dir }}/build"