Speed up execution time of yum_update.sh

Doing a yum update with an explicit list of packages where many of
those packages are already up-to-date has a significant time penalty.
This change includes version comparison to remove packages from
packages_for_update where the installed and available versions are
identical.

This change also only installs yum-plugin-priorities if it is not
already installed, for some extra time saving.

For a specific example of time saved, I had a
centos-binary-rsyslog-base with the following timings.

Without this change
-------------------
packages passed to yum update: 87
packages actually updated:     11
time taken                     35s

With this change
-------------------
packages passed to yum update: 11
packages actually updated:     11
time taken                     10s

This time saved should add up over all of the container images during
image prepare in CI.

Change-Id: Ie282acd1cdc0de8d875959ec9578122fe34f98ac
This commit is contained in:
Steve Baker 2019-02-07 16:25:37 +13:00 committed by yatin
parent 8f0c6bf141
commit 9014df9472
1 changed files with 17 additions and 5 deletions

View File

@ -4,9 +4,17 @@ set -eoux pipefail
packages_for_update=
if [ -n "$1" ] && command -v repoquery >/dev/null 2>&1; then
installed=$(rpm -qa --qf "%{NAME}\n" | sort)
available=$(repoquery --provides --disablerepo='*' --enablerepo=$1 --qf %{NAME} -a | cut -d= -f1 | sort)
packages_for_update=$(comm -12 <(printf "%s\n" $installed) <(printf "%s\n" $available))
installed_versions=$(rpm -qa --qf "%{NAME} = %{VERSION}-%{RELEASE}\n" | sort)
available_versions=$(repoquery --provides --disablerepo='*' --enablerepo=$1 -a | sort)
uptodate_versions=$(comm -12 <(printf "%s\n" "$installed_versions") <(printf "%s\n" "$available_versions"))
installed=$(printf "%s\n" "$installed_versions" | cut -d= -f1 | sort)
available=$(printf "%s\n" "$available_versions" | cut -d= -f1 | sort)
uptodate=$(printf "%s\n" "$uptodate_versions" | cut -d= -f1 | sort)
installed_for_update=$(comm -23 <(printf "%s\n" $installed) <(printf "%s\n" $uptodate))
packages_for_update=$(comm -12 <(printf "%s\n" $installed_for_update) <(printf "%s\n" $available))
fi
if [ -z "$packages_for_update" ]; then
@ -18,9 +26,13 @@ PKG="$(command -v dnf || command -v yum)"
PKG_MGR="$(echo ${PKG:(-3)})"
if [ $PKG_MGR == "dnf" ]; then
$PKG install -y dnf-plugins-core
if ! echo $installed | grep -qw dnf-plugins-core; then
$PKG install -y dnf-plugins-core
fi
else:
$PKG install -y yum-plugin-priorities
if ! echo $installed | grep -qw yum-plugin-priorities; then
$PKG install -y yum-plugin-priorities
fi
fi
$PKG -y update $packages_for_update
rm -rf /var/cache/$PKG_MGR