Skip to content

Commit

Permalink
Merge 24e3c52 into 06124bf
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 5, 2022
2 parents 06124bf + 24e3c52 commit b437a0b
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 10 deletions.
57 changes: 48 additions & 9 deletions src/lib/kdump/kdump_calibrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class KdumpCalibrator
KDUMPTOOL_CMD = "/usr/sbin/kdumptool %s calibrate".freeze
KDUMPTOOL_ARG = "--configfile '%s'".freeze
KEYS_MAP = {
"Low" => :default_low,
"MinLow" => :min_low,
"MaxLow" => :max_low,
"High" => :default_high,
"MinHigh" => :min_high,
"MaxHigh" => :max_high,
"Total" => :total_memory
"Low" => :default_low,
"MinLow" => :min_low,
"MaxLow" => :max_low,
"High" => :default_high,
"MinHigh" => :min_high,
"MaxHigh" => :max_high,
"Fadump" => :default_fadump,
"MinFadump" => :min_fadump,
"MaxFadump" => :max_fadump,
"Total" => :total_memory
}.freeze

def initialize(configfile = nil)
Expand All @@ -38,6 +41,13 @@ def high_memory_supported?
!max_high.zero?
end

# Determines whether fadump support is available
#
# @return [Boolean] true if it's available; 'false' otherwise.
def fadump_supported?
!max_fadump.zero?
end

# Determines what's the recommended quantity of low memory
#
# If high memory is not supported, this is the total recommended memory.
Expand Down Expand Up @@ -99,6 +109,32 @@ def max_high
end
end

# Determines what's the recommended quantity of fadump memory
#
# @return [Fixnum] Memory size (in MiB)
def default_fadump
run_kdumptool unless @kdumptool_executed
@default_fadump ||= min_fadump
end

# Determines what's the minimum quantity of fadump memory
#
# @return [Fixnum] Memory size (in MiB)
def min_fadump
run_kdumptool unless @kdumptool_executed
@min_fadump ||= 0
end

# Determines what's the recommended maximum quantity of low memory
#
# If high memory is not supported, this is 0.
#
# @return [Fixnum] Memory size (in MiB)
def max_fadump
run_kdumptool unless @kdumptool_executed
@max_fadump ||= system.supports_fadump? ? total_memory : 0
end

# System available memory
#
# @return [Fixnum] Memory size (in MiB)
Expand All @@ -115,8 +151,11 @@ def total_memory
#
# @return [Hash] Memory limits
def memory_limits
{ min_low: min_low, max_low: max_low, default_low: default_low,
min_high: min_high, max_high: max_high, default_high: default_high }
{
min_low: min_low, max_low: max_low, default_low: default_low,
min_high: min_high, max_high: max_high, default_high: default_high,
min_fadump: min_fadump, max_fadump: max_fadump, default_fadump: default_fadump
}
end

private
Expand Down
200 changes: 199 additions & 1 deletion test/lib/kdump/kdump_calibrator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
KDUMPTOOL_OK = {
"exit" => 0,
"stdout" => "Low: 108\nMinLow: 32\nMaxLow: 712\n"\
"High: 2048\nMinHigh: 1024\nMaxHigh: 4096\nTotal: 16079\n"
"High: 2048\nMinHigh: 1024\nMaxHigh: 4096\n"\
"Fadump: 0\nMinFadump: 0\nMaxFadump: 0\nTotal: 16079\n"
}.freeze
KDUMPTOOL_OLD = { "exit" => 0, "stdout" => "64\n" }.freeze
KDUMPTOOL_ERROR = { "exit" => 1, "stdout" => "" }.freeze

let(:configfile) { "/var/lib/YaST2/kdump.conf" }
let(:x86_64) { true }
let(:ppc64) { false }
let(:kdumptool_output) { KDUMPTOOL_OK }

before do
allow(Yast::Arch).to receive(:x86_64).and_return(x86_64)
allow(Yast::Arch).to receive(:ppc64).and_return(ppc64)
allow(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"), anything).and_return(kdumptool_output)
allow(Yast::SCR).to receive(:Read).with(path(".probe.memory"))
Expand Down Expand Up @@ -94,6 +97,7 @@
end
end
end

context "#max_low" do
context "when kdumptool succeeds" do
it "returns the value found in kdumptool" do
Expand Down Expand Up @@ -300,4 +304,198 @@
end
end
end

describe "#min_fadump" do
context "when kdumptool succeeds" do
let(:kdumptool_output) {
{
"exit" => 0,
"stdout" => "Low: 108\nMinLow: 32\nMaxLow: 712\n"\
"High: 2048\nMinHigh: 1024\nMaxHigh: 4096\n"\
"Fadump: 256\nMinFadump: 128\nMaxFadump: 8192\nTotal: 16079\n"
}
}

it "returns the value found by kdumptool" do
expect(subject.min_fadump).to eq(128)
end
end

context "when kdumptool uses the old format" do
let(:kdumptool_output) { KDUMPTOOL_OLD }

it "returns 0" do
expect(subject.min_fadump).to eq(0)
end
end

context "when kdumptool fails" do
let(:kdumptool_output) { KDUMPTOOL_ERROR }

it "returns 0" do
expect(subject.min_fadump).to eq(0)
end
end
end

describe "#default_fadump" do
context "when kdumptool succeeds" do
let(:kdumptool_output) {
{
"exit" => 0,
"stdout" => "Low: 108\nMinLow: 32\nMaxLow: 712\n"\
"High: 2048\nMinHigh: 1024\nMaxHigh: 4096\n"\
"Fadump: 256\nMinFadump: 128\nMaxFadump: 8192\nTotal: 16079\n"
}
}

it "returns the value found by kdumptool" do
expect(subject.default_fadump).to eq(256)
end
end

context "when kdumptool uses the old format" do
let(:kdumptool_output) { KDUMPTOOL_OLD }

it "returns 0 (the minimum fallback)" do
expect(subject.default_fadump).to eq(0)
end
end

context "when kdumptool fails" do
let(:kdumptool_output) { KDUMPTOOL_ERROR }

it "returns 0 (the minimum fallback)" do
expect(subject.default_fadump).to eq(0)
end
end
end

describe "#max_fadump" do
context "when kdumptool succeeds" do
let(:kdumptool_output) {
{
"exit" => 0,
"stdout" => "Low: 108\nMinLow: 32\nMaxLow: 712\n"\
"High: 2048\nMinHigh: 1024\nMaxHigh: 4096\n"\
"Fadump: 256\nMinFadump: 128\nMaxFadump: 8192\nTotal: 16079\n"
}
}

it "returns the value found by kdumptool" do
expect(subject.max_fadump).to eq(8192)
end
end

context "when kdumptool fails" do
let(:kdumptool_output) { KDUMPTOOL_ERROR }

context "when fadump memory is supported" do
let(:ppc64) { true }

it "returns total_memory" do
allow(subject).to receive(:total_memory).and_return(4096)

expect(subject.max_fadump).to eq(4096)
end
end

context "when fadump memory is not supported" do
let(:ppc64) { false }

it "returns 0" do
expect(subject.max_fadump).to eq(0)
end
end
end

context "when kdumptool uses the old format" do
let(:kdumptool_output) { KDUMPTOOL_OLD }

context "when fadump memory is supported" do
let(:ppc64) { true }

it "returns total_memory" do
allow(subject).to receive(:total_memory).and_return(4096)

expect(subject.max_fadump).to eq(4096)
end
end

context "when fadump memory is not supported" do
let(:ppc64) { false }

it "returns 0" do
expect(subject.max_fadump).to eq(0)
end
end
end
end

describe "#fadump_supported?" do
subject(:supported) { described_class.new(configfile).fadump_supported? }

context "when kdumptool succeeds" do
context "if kdumptool allows fadump memory" do
let(:kdumptool_output) {
{
"exit" => 0,
"stdout" => "Low: 108\nMinLow: 32\nMaxLow: 712\n"\
"High: 2048\nMinHigh: 1024\nMaxHigh: 4096\n"\
"Fadump: 256\nMinFadump: 128\nMaxFadump: 8192\nTotal: 16079\n"
}
}

it "returns true" do
expect(supported).to eq(true)
end
end

context "if kdumptool returns 0 for fadump memory" do
it "returns false" do
expect(supported).to eq(false)
end
end
end

context "when kdumptool fails" do
let(:kdumptool_output) { KDUMPTOOL_ERROR }

context "when architecture is ppc64" do
let(:ppc64) { true }

it "returns true" do
expect(supported).to eq(true)
end
end

context "when architecture is not ppc64" do
let(:ppc64) { false }

it "returns false" do
expect(supported).to eq(false)
end
end
end

context "when kdumptool uses the old format" do
let(:kdumptool_output) { KDUMPTOOL_OLD }

context "when architecture is ppc64" do
let(:ppc64) { true }

it "returns true" do
expect(supported).to eq(true)
end
end

context "when architecture is not ppc64" do
let(:ppc64) { false }

it "returns false" do
expect(supported).to eq(false)
end
end
end
end
end

0 comments on commit b437a0b

Please sign in to comment.