Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it work to add Upgrades to this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastelfreak sorry for not responding that long. It was really a lengthy... Cyber Awareness October...

I'm no Ruby expert, but no I don't think this would work. In my understanding .partition() splits the whole content into partitions. I think the .first would then give the first element of the resulting array and due to the new header this would by an empty partition before the partition we're interested in, due to the new (unexpected) dividing element.

I think that's the reason @muald chose to modify body.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, .partition is returning some empty strings. Have you considered just filtering them out with .reject!(&:empty?)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@binford2k as stated in #555 (comment) I would go for using the --json parameter (when available, else fall back to current behavior) if I had the time to rewrite. IMHO this would be a robuster approach.

In my understanding this PR is more a quick fix for the non-JSON based parsing. So I wouldn't want to pour too much energy into this.


body = body.gsub(/^Upgrades.*?$/m, '')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body = body.gsub(/^Upgrades.*?$/m, '')
body = body.gsub(/^Upgrades.*?$/m, '')

I would keep the empty newline after the body modifications.

Suggested change
body = body.gsub(/^Upgrades.*?$/m, '')
body.gsub!(/^Upgrades.*?$/m, '')

@OpenVoxProject do you prefer the in-place gsub call?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muald I just learnt that in Ruby RegExp the anchors ^ and $ match in m mode actually at the line boundaries and not at the string boundaries (according to the back of my head this used to be different... in Python). This means, due to the $ anchor the match will definitely anchor at the end of the first line. As we want the whole first line gone, we then probably don't need the non-greedy ?.

But we definitely need the m mode otherwise $ would anchor at the end of the whole body string.

We do leave an empty newline after the substitution.

Alternatively, without m mode, we could also do this:

Suggested change
body = body.gsub(/^Upgrades.*?$/m, '')
# https://regex101.com/r/LiVD53/2/substitution
body.gsub!(/^Upgrades.*\R/, '')

This would remove only the whole first line of the body, if it starts with Upgrades.

@bastelfreak what do you think?

updates = Hash.new { |h, k| h[k] = [] }

body.split(/^\s*\n/).each do |line|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Updating and loading repositories:
Repositories loaded.
Upgrades
curl.x86_64 8.18.0-14.fc44 updates
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Updating and loading repositories:
Repositories loaded.
curl.x86_64 8.15.0-10.fc43 updates
36 changes: 36 additions & 0 deletions spec/unit/provider/package/yum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Loading