Skip to content

Commit

Permalink
Fixed issue with yum package module regarding packages with epoch not…
Browse files Browse the repository at this point in the history
… validating

Packages would be installed but the promise would fail due to the installed list not including the epoch number.
The updates list generated by the module included the epoch number so validation would fail.

e.g. findutils:1:4.8.0-7.el9:x86_64 would not match findutils:4.8.0-7.el9:x86_64

Fix this by including epoch in rpm_output_format and removing (none): where the package has no epoch.

Ticket: ENT-12538
Changelog: title
  • Loading branch information
craigcomstock committed Dec 18, 2024
1 parent b719d69 commit 18bee76
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions modules/packages/vendored/yum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import re

rpm_cmd = os.environ.get('CFENGINE_TEST_RPM_CMD', "/bin/rpm")
rpm_quiet_option = ["--quiet"]
rpm_output_format = "Name=%{name}\nVersion=%{version}-%{release}\nArchitecture=%{arch}\n"
rpm_output_format = "Name=%{name}\nVersion=%{epoch}:%{version}-%{release}\nArchitecture=%{arch}\n"

yum_cmd = os.environ.get('CFENGINE_TEST_YUM_CMD', "/usr/bin/yum")
yum_options = ["--quiet", "-y"]
Expand Down Expand Up @@ -87,7 +87,16 @@ def get_package_data():
# Absolute file.
sys.stdout.write("PackageType=file\n")
sys.stdout.flush()
return subprocess_call([rpm_cmd, "--qf", rpm_output_format, "-qp", pkg_string])
process = subprocess_Popen([rpm_cmd, "--qf", rpm_output_format, "-qp", pkg_string], stdout=subprocess.PIPE)
(stdoutdata, _) = process.communicate()

if process.returncode != 0:
return process.returncode

for line in stdoutdata.decode("utf-8").splitlines():
sys.stdout.write(line.replace("(none):","") + "\n")

return 0
elif re.search("[:,]", pkg_string):
# Contains an illegal symbol.
sys.stdout.write(line + "ErrorMessage: Package string with illegal format\n")
Expand All @@ -102,7 +111,16 @@ def list_installed():
# Ignore everything.
sys.stdin.readlines()

return subprocess_call([rpm_cmd, "-qa", "--qf", rpm_output_format])
process = subprocess_Popen([rpm_cmd, "-qa", "--qf", rpm_output_format], stdout=subprocess.PIPE)
(stdoutdata, _) = process.communicate()

if process.returncode != 0:
return process.returncode

for line in stdoutdata.decode("utf-8").splitlines():
sys.stdout.write(line.replace("(none):","") + "\n")

return 0


def list_updates(online):
Expand Down

0 comments on commit 18bee76

Please sign in to comment.