diff --git a/src/lib/installation/cio_ignore.rb b/src/lib/installation/cio_ignore.rb index 3edaaa252..706717134 100644 --- a/src/lib/installation/cio_ignore.rb +++ b/src/lib/installation/cio_ignore.rb @@ -242,14 +242,14 @@ def add_cio_boot_kernel_parameters param = Yast::Bootloader.kernel_param(:common, "cio_ignore") - if param == :missing - res = Yast::WFM.Execute(YAST_LOCAL_BASH_PATH, "/sbin/cio_ignore -k") + return unless param == :missing - raise "cio_ignore -k failed with #{res["stderr"]}" if res["exit"] != 0 + res = Yast::WFM.Execute(YAST_LOCAL_BASH_PATH, "/sbin/cio_ignore -k") - # boot code is already proposed and will be written in next step, so just modify - Yast::Bootloader.modify_kernel_params("cio_ignore" => res["stdout"].lines.first) - end + raise "cio_ignore -k failed with #{res["stderr"]}" if res["exit"] != 0 + + # boot code is already proposed and will be written in next step, so just modify + Yast::Bootloader.modify_kernel_params("cio_ignore" => res["stdout"].lines.first) end ACTIVE_DEVICES_FILE = "/boot/zipl/active_devices.txt".freeze @@ -267,7 +267,7 @@ def store_active_devices # make sure the file ends with a new line character devices << "" unless devices.empty? - log.info "active devices to be written: #{devices.join(',')}" + log.info "active devices to be written: #{devices.join(",")}" File.write(target_file, devices.join("\n")) end diff --git a/test/cio_ignore_test.rb b/test/cio_ignore_test.rb index b3be07cdc..87b181720 100755 --- a/test/cio_ignore_test.rb +++ b/test/cio_ignore_test.rb @@ -12,19 +12,28 @@ end describe "cio_ignore enable/disable" do - it "take AutoYaST cio_ignore setting" do - allow(Yast::Mode).to receive(:autoinst).and_return(true) - allow(Yast::AutoinstConfig).to receive(:cio_ignore).and_return(false) - ::Installation::CIOIgnore.instance.reset - expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(false) + let(:auto) { false } + + before do + allow(Yast::Mode).to receive(:autoinst).and_return(auto) end - it "take default cio_ignore entry if it is in the normal workflow" do - allow(Yast::Mode).to receive(:autoinst).and_return(false) - expect(Yast::AutoinstConfig).not_to receive(:cio_ignore) - expect(File).to receive(:exist?).with("/proc/sysinfo").exactly(2).times.and_return(false) - ::Installation::CIOIgnore.instance.reset - expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(true) + context "in autoinstallation" do + let(:auto) { true } + + it "takes AutoYaST cio_ignore setting" do + allow(Yast::AutoinstConfig).to receive(:cio_ignore).and_return(false) + ::Installation::CIOIgnore.instance.reset + expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(false) + end + end + + context "in other modes" do + it "takes the default cio_ignore entry" do + expect(Yast::AutoinstConfig).not_to receive(:cio_ignore) + ::Installation::CIOIgnore.instance.reset + expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(true) + end end end end @@ -161,6 +170,8 @@ end describe "first parameter \"Write\"" do + let(:param) { "all,!ipldev,!condev" } + before(:each) do stub_const("Yast::Installation", double(destdir: "/mnt")) stub_const("Yast::Bootloader", double) @@ -168,8 +179,10 @@ allow(Yast::Bootloader).to receive(:Write) { true } allow(Yast::Bootloader).to receive(:Read) { true } allow(Yast::Bootloader).to receive(:modify_kernel_params) { true } + allow(Yast::Bootloader).to receive(:kernel_param) + .with(:common, "cio_ignore").and_return(param) - allow(Yast::SCR).to receive(:Execute) + allow(Yast::WFM).to receive(:Execute) .and_return("exit" => 0, "stdout" => "", "stderr" => "") allow(File).to receive(:write) @@ -179,7 +192,7 @@ it "does nothing" do ::Installation::CIOIgnore.instance.cio_enabled = false - expect(Yast::SCR).to_not receive(:Execute) + expect(Yast::WFM).to_not receive(:Execute) expect(Yast::Bootloader).to_not receive(:Read) subject.run("Write") @@ -190,9 +203,9 @@ it "calls `cio_ignore --unused --purge`" do ::Installation::CIOIgnore.instance.cio_enabled = true - expect(Yast::SCR).to receive(:Execute) + expect(Yast::WFM).to receive(:Execute) .with( - ::Installation::CIOIgnoreFinish::YAST_BASH_PATH, + ::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH, "/sbin/cio_ignore --unused --purge" ) .once @@ -205,9 +218,9 @@ ::Installation::CIOIgnore.instance.cio_enabled = true stderr = "HORRIBLE ERROR!!!" - expect(Yast::SCR).to receive(:Execute) + expect(Yast::WFM).to receive(:Execute) .with( - ::Installation::CIOIgnoreFinish::YAST_BASH_PATH, + ::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH, "/sbin/cio_ignore --unused --purge" ) .once @@ -216,12 +229,33 @@ expect { subject.run("Write") }.to raise_error(RuntimeError, /stderr/) end - it "adds kernel parameters IPLDEV and CONDEV to the bootloader" do - expect(Yast::Bootloader).to receive(:modify_kernel_params) - .with("cio_ignore" => "all,!ipldev,!condev").once - .and_return(true) + context "when the cio_ignore kernel argument is already given" do + it "does not touch the kernel parameters" do + expect(Yast::Bootloader).to_not receive(:modify_kernel_params) + .with("cio_ignore" => anything) - subject.run("Write") + subject.run("Write") + end + end + + context "when the cio_ignore kernel argument is not given" do + let(:param) { :missing } + let(:cio_k_output) { "all,!0009,!0160,!0800-0802" } + + it "adds the parameter using the 'cio_ignore -k' output to the bootloader" do + expect(Yast::WFM).to receive(:Execute) + .with( + Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH, + "/sbin/cio_ignore -k" + ) + .once + .and_return("exit" => 0, "stdout" => cio_k_output, "stderr" => "") + expect(Yast::Bootloader).to receive(:modify_kernel_params) + .with("cio_ignore" => cio_k_output).once + .and_return(true) + + subject.run("Write") + end end it "writes list of active devices to zipl so it is not blocked" do @@ -233,9 +267,9 @@ 0.0.0700-0.0.0702 0.0.fc00 CIO_IGNORE - expect(Yast::SCR).to receive(:Execute) + expect(Yast::WFM).to receive(:Execute) .with( - ::Installation::CIOIgnoreFinish::YAST_BASH_PATH, + ::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH, "/sbin/cio_ignore -L" ) .once @@ -251,9 +285,9 @@ end it "raises an exception if cio_ignore -L failed" do - expect(Yast::SCR).to receive(:Execute) + expect(Yast::WFM).to receive(:Execute) .with( - ::Installation::CIOIgnoreFinish::YAST_BASH_PATH, + ::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH, "/sbin/cio_ignore -L" ) .once