From cb0e0e903dc0dbfb130622c752788629f01d80d9 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 25 Nov 2015 14:31:50 +1100 Subject: [PATCH] Use dnf to cleanup old kernels As described in the comment, there is a dnf equivalent of this command that doesn't require us installing yum-utils (which drags in yum on dnf-only systems such as f23) This is a small consequence to this -- due to us not installing yum-utils some installs will now be completely yum free. This causes a breakage in ironic-agent 99-remove-extra-packages where we remove the yum package. There is a long-standing bug/feature where missing packages in a group of packages do not cause yum/dnf to exit with failure, but uninstalling a single package will. Because we have made the systems yum-free, the uninstall of yum can fail in this corner case. It has always been like this, so I'm in favour of the "ain't broke" approach. To work-around this, I have just put yum into the existing list of packages to be cleaned up. I have added a note to the yum installer taking note of this behaviour for future reference. Change-Id: I8bbdc07ccdb89a105b4fc70d5a215077c42fcd03 --- .../finalise.d/99-remove-extra-packages | 21 +++++++++++-------- .../finalise.d/01-clean-old-kernels | 14 +++++++++++-- elements/yum/bin/install-packages | 8 +++++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/elements/ironic-agent/finalise.d/99-remove-extra-packages b/elements/ironic-agent/finalise.d/99-remove-extra-packages index 91ccc14f..b3f722bb 100755 --- a/elements/ironic-agent/finalise.d/99-remove-extra-packages +++ b/elements/ironic-agent/finalise.d/99-remove-extra-packages @@ -9,18 +9,21 @@ set -o pipefail # TODO(lucasagomes): optimize the ramdisk for other OSs if [ $DISTRO_NAME = 'fedora' ] ; then - install-packages -e kernel-debug-devel gcc fedora-logos python3 rsync sudo pykickstart grubby make genisoimage tcpdump man-db policycoreutils kbd-misc plymouth cronie - + _remove_yum='' if [ $DIB_RELEASE -ge 22 ]; then - # Remove yum, >= F22 defaults to dnf - dnf remove yum -y - # Remove package manager cache - dnf clean all - else - # Remove package manager cache - yum clean all + # if we are on F22, we can remove yum if there, because it has + # been superseeded by dnf + _remove_yum='yum' fi + install-packages -e kernel-debug-devel gcc fedora-logos \ + python3 rsync sudo pykickstart \ + grubby make genisoimage tcpdump \ + man-db policycoreutils kbd-misc \ + plymouth cronie ${_remove_yum} + + ${YUM:-yum} clean all + # Rebuilding the rpm database after removing packages will reduce # its size rpm --rebuilddb diff --git a/elements/redhat-common/finalise.d/01-clean-old-kernels b/elements/redhat-common/finalise.d/01-clean-old-kernels index 1e1e71c9..60c7b0fe 100755 --- a/elements/redhat-common/finalise.d/01-clean-old-kernels +++ b/elements/redhat-common/finalise.d/01-clean-old-kernels @@ -6,6 +6,16 @@ fi set -eu set -o pipefail -install-packages yum-utils +YUM=${YUM:-yum} -package-cleanup --oldkernels -y --count=1 +if [[ ${YUM} == "dnf" ]]; then + # cribbed from + # http://dnf.readthedocs.org/en/latest/cli_vs_yum.html + _old_kernels="$(dnf repoquery --installonly --latest-limit -1 -q)" + if [[ -n "${_old_kernels}" ]]; then + dnf remove -y ${_old_kernels} + fi +else + install-packages yum-utils + package-cleanup --oldkernels -y --count=1 +fi diff --git a/elements/yum/bin/install-packages b/elements/yum/bin/install-packages index dac71738..2bef134a 100755 --- a/elements/yum/bin/install-packages +++ b/elements/yum/bin/install-packages @@ -122,6 +122,14 @@ if [ -n "$WHITELIST" ]; then exit 0 fi + # yum & dnf have a feature/bug where missing packages in a list of + # packages for install/erase do not raise an error exit [1]. + # There is a corner case when specifying just *one* package, where + # it will fail if the package is missing. Thus install-packages + # follows this behaviour; we may need to re-evaluate this at some + # point. + # + # [1] https://bugzilla.redhat.com/show_bug.cgi?id=965567 ${YUM} -v -y $ACTION $EXTRA_ARGS $PKGS if [ "$ACTION" == "install" ]; then