Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 25, 2024
1 parent fa7f458 commit 20b9098
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 33 deletions.
14 changes: 7 additions & 7 deletions src/lib/installation/cio_ignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
88 changes: 62 additions & 26 deletions test/cio_ignore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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 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
Expand Down Expand Up @@ -161,15 +170,19 @@
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)

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)
Expand All @@ -179,20 +192,22 @@
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")
end
end

describe "Device blacklisting is enabled" do


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
Expand All @@ -205,9 +220,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
Expand All @@ -216,12 +231,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
Expand All @@ -233,9 +269,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
Expand All @@ -251,9 +287,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
Expand Down

0 comments on commit 20b9098

Please sign in to comment.