diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb index 27af23513b..91333a75ad 100644 --- a/lib/puppet/provider/package/yum.rb +++ b/lib/puppet/provider/package/yum.rb @@ -133,7 +133,7 @@ def self.check_updates(disablerepo, enablerepo, disableexcludes) def self.parse_updates(str) # Strip off all content that contains Obsoleting, Security: or Update body = str.partition(/^(Obsoleting|Security:|Update)/).first - + body = body.gsub(/^Upgrades.*?$/m, '') updates = Hash.new { |h, k| h[k] = [] } body.split(/^\s*\n/).each do |line| diff --git a/spec/fixtures/unit/provider/package/yum/yum-check-update-with-bare-updates-header.txt b/spec/fixtures/unit/provider/package/yum/yum-check-update-with-bare-updates-header.txt new file mode 100644 index 0000000000..313dc3c36a --- /dev/null +++ b/spec/fixtures/unit/provider/package/yum/yum-check-update-with-bare-updates-header.txt @@ -0,0 +1,4 @@ +Updating and loading repositories: +Repositories loaded. +Upgrades +curl.x86_64 8.18.0-14.fc44 updates diff --git a/spec/fixtures/unit/provider/package/yum/yum-check-update-with-updates-header.txt b/spec/fixtures/unit/provider/package/yum/yum-check-update-with-updates-header.txt new file mode 100644 index 0000000000..38b913cd11 --- /dev/null +++ b/spec/fixtures/unit/provider/package/yum/yum-check-update-with-updates-header.txt @@ -0,0 +1,4 @@ +Updating and loading repositories: +Repositories loaded. +Upgrades (available for reinstall, available for upgrade) +curl.x86_64 8.18.0-10.fc44 updates diff --git a/spec/fixtures/unit/provider/package/yum/yum-check-update-without-updates-header.txt b/spec/fixtures/unit/provider/package/yum/yum-check-update-without-updates-header.txt new file mode 100644 index 0000000000..b4f531802b --- /dev/null +++ b/spec/fixtures/unit/provider/package/yum/yum-check-update-without-updates-header.txt @@ -0,0 +1,3 @@ +Updating and loading repositories: +Repositories loaded. +curl.x86_64 8.15.0-10.fc43 updates diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 40325b4348..03911abe11 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -278,6 +278,42 @@ end end + context "without updates header" do + let(:check_update) { File.read(my_fixture("yum-check-update-without-updates-header.txt")) } + let(:output) { described_class.parse_updates(check_update) } + + it "parses correctly formatted entries" do + expect(output['curl']).to eq([{:name => 'curl', :epoch => '0', :version => '8.15.0', :release => '10.fc43', :arch => 'x86_64'}]) + end + + it "ignores all mentions of updates header" do + expect(output).not_to include("Upgrades (available for reinstall, available for upgrade)") + end + end + + context "with updates header" do + let(:check_update) { File.read(my_fixture("yum-check-update-with-updates-header.txt")) } + let(:output) { described_class.parse_updates(check_update) } + + it "parses correctly formatted entries" do + expect(output['curl']).to eq([{:name => 'curl', :epoch => '0', :version => '8.18.0', :release => '10.fc44', :arch => 'x86_64'}]) + end + + it "ignores all mentions of updates header" do + expect(output).not_to include("Upgrades (available for reinstall, available for upgrade)") + end + end + + context "with bare updates header (dnf5 5.4)" do + let(:check_update) { File.read(my_fixture("yum-check-update-with-bare-updates-header.txt")) } + let(:output) { described_class.parse_updates(check_update) } + + it "parses only the package entries" do + expect(output.keys).to contain_exactly('curl', 'curl.x86_64') + expect(output['curl']).to eq([{:name => 'curl', :epoch => '0', :version => '8.18.0', :release => '14.fc44', :arch => 'x86_64'}]) + end + end + context "with subscription manager enabled " do let(:check_update) { File.read(my_fixture("yum-check-update-subscription-manager.txt")) } let(:output) { described_class.parse_updates(check_update) }