Skip to content
Merged
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
7 changes: 6 additions & 1 deletion lib/linux_admin/yum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def self.update(*packages)
cmd = "yum -y update"
params = {nil => packages} unless packages.blank?

run!(cmd, :params => params)
out = run!(cmd, :params => params)

# Handle errors that exit 0 https://bugzilla.redhat.com/show_bug.cgi?id=1141318
raise AwesomeSpawn::CommandResultError.new(out.error, out) if out.error.include?("No Match for argument")
Copy link
Member

Choose a reason for hiding this comment

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

This begs for a comment or something.

Does it make sense to use run and instead to make it obvious that yum in some cases is exiting 0 on errors:

raise ... if (out.exit_status != 0) || (out.exit_status == 0 && out.error.include?("No Match for argument"))

Copy link
Member

Choose a reason for hiding this comment

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

Forget if it's exit_code or exit_status....

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather get yum fixed and have it exit 1 and let run! handle it. I'll open a bug on yum and make a comment with the BZ id.


out
end

def self.version_available(*packages)
Expand Down
10 changes: 8 additions & 2 deletions spec/yum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,20 @@

context ".update" do
it "no arguments" do
expect(described_class).to receive(:run!).once.with("yum -y update", {:params=>nil})
expect(described_class).to receive(:run!).once.with("yum -y update", :params => nil).and_return(AwesomeSpawn::CommandResult.new("", "", "", 0))
described_class.update
end

it "with arguments" do
expect(described_class).to receive(:run!).once.with("yum -y update", {:params=>{nil=>["1 2", "3"]}})
expect(described_class).to receive(:run!).once.with("yum -y update", :params => {nil => ["1 2", "3"]}).and_return(AwesomeSpawn::CommandResult.new("", "", "", 0))
described_class.update("1 2", "3")
end

it "with bad arguments" do
error = AwesomeSpawn::CommandResult.new("", "Loaded plugins: product-id\nNo Packages marked for Update\n", "Blah blah ...\nNo Match for argument: \n", 0)
expect(described_class).to receive(:run!).once.with("yum -y update", :params => {nil => [""]}).and_return(error)
expect { described_class.update("") }.to raise_error(AwesomeSpawn::CommandResultError)
end
end

context ".version_available" do
Expand Down