From a18b3e6588af38cb69cbe02b026a51c44a309f42 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Fri, 12 Sep 2014 12:57:10 -0400 Subject: [PATCH] Ensure Yum update raises on argument errors even with exit code 0 https://bugzilla.redhat.com/show_bug.cgi?id=1136941 --- lib/linux_admin/yum.rb | 7 ++++++- spec/yum_spec.rb | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/linux_admin/yum.rb b/lib/linux_admin/yum.rb index e4f85c1..caf03b3 100644 --- a/lib/linux_admin/yum.rb +++ b/lib/linux_admin/yum.rb @@ -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") + + out end def self.version_available(*packages) diff --git a/spec/yum_spec.rb b/spec/yum_spec.rb index ed2e1e6..edbf388 100644 --- a/spec/yum_spec.rb +++ b/spec/yum_spec.rb @@ -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