Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change facts used by module #13

Merged
merged 1 commit into from Aug 19, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/facter/crashkernel.rb
@@ -0,0 +1,25 @@
# Fact: crashkernel
#
# Purpose:
# This fact checks for current crashkernel in kernel boot
#
# Resolution:
# Checks `proc/cmdline`
#
# Caveats:
# Only supports Linux.
#

Facter.add(:crashkernel) do
confine kernel: :linux
setcode do
crashkernel = false
kernel_arguments = Facter.value(:kdump_kernel_arguments)
if kernel_arguments
if kernel_arguments =~ %r{crashkernel=(\S+)}
crashkernel = Regexp.last_match(1)
end
end
crashkernel
end
end
@@ -1,4 +1,4 @@
# Fact: kernel_arguments
# Fact: kdump_kernel_arguments
#
# Purpose:
# This fact provides the arguments used for the currently running kernel
Expand All @@ -10,7 +10,7 @@
# Only supports Linux.
#

Facter.add(:kernel_arguments) do
Facter.add(:kdump_kernel_arguments) do
confine kernel: :linux
setcode do
cmdline_out = Facter::Core::Execution.execute('cat /proc/cmdline 2>/dev/null')
Expand Down
4 changes: 2 additions & 2 deletions manifests/init.pp
Expand Up @@ -132,7 +132,7 @@
notify => Service['kdump'],
}

if $::kernel_arguments !~ /crashkernel/ {
if ! $facts['crashkernel'] {
notify { 'kdump':
message => 'A reboot is required to fully enable the crashkernel'
}
Expand All @@ -151,7 +151,7 @@
}
}

if $::kernel_arguments =~ /crashkernel/ {
if $facts['crashkernel'] {
notify { 'kdump':
message => 'A reboot is required to fully disable the crashkernel'
}
Expand Down
6 changes: 3 additions & 3 deletions spec/classes/kdump_spec.rb
Expand Up @@ -4,7 +4,7 @@
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge(kernel_arguments: my_fixture_read('kernelargs-with-crash.txt'))
facts.merge(crashkernel: 'auto')
end

let(:kernel_parameter_provider) do
Expand Down Expand Up @@ -62,7 +62,7 @@

context 'when kernel_arguments does not contain crashkernel' do
let(:facts) do
facts.merge(kernel_arguments: my_fixture_read('kernelargs-without-crash.txt'))
facts.merge(crashkernel: false)
end

it do
Expand Down Expand Up @@ -109,7 +109,7 @@

context 'when kernel_arguments does not contain crashkernel' do
let(:facts) do
facts.merge(kernel_arguments: my_fixture_read('kernelargs-without-crash.txt'))
facts.merge(crashkernel: false)
end

it do
Expand Down
@@ -0,0 +1 @@
ro root=/dev/mapper/vg_sys-lv_root rd_LVM_LV=vg_sys/lv_swap rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD KEYTABLE=us nofb quiet splash=quiet SYSFONT=latarcyrheb-sun16 rd_LVM_LV=vg_sys/lv_root rd_NO_DM rhgb quiet
1 change: 1 addition & 0 deletions spec/fixtures/unit/facter/kdump_kernel_arguments/cmdline1
@@ -0,0 +1 @@
ro root=/dev/mapper/vg_sys-lv_root rd_LVM_LV=vg_sys/lv_swap rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD KEYTABLE=us nofb quiet splash=quiet SYSFONT=latarcyrheb-sun16 rd_LVM_LV=vg_sys/lv_root rd_NO_DM rhgb quiet crashkernel=131M@0M
20 changes: 20 additions & 0 deletions spec/unit/facter/crashkernel_spec.rb
@@ -0,0 +1,20 @@
require 'spec_helper'

describe 'crashkernel fact' do
before :each do
Facter.clear
end

context 'kernel is linux' do
it 'returns crashkernel' do
allow(Facter::Core::Execution).to receive(:exec).with('uname -s').and_return('Linux')
allow(Facter).to receive(:value).with(:kdump_kernel_arguments).and_return(my_fixture_read('kernelargs-with-crash.txt'))
expect(Facter.fact(:crashkernel).value).to eq('131M@0M')
end
it 'returns false' do
allow(Facter::Core::Execution).to receive(:exec).with('uname -s').and_return('Linux')
allow(Facter).to receive(:value).with(:kdump_kernel_arguments).and_return(my_fixture_read('kernelargs-without-crash.txt'))
expect(Facter.fact(:crashkernel).value).to eq(false)
end
end
end
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'kernel_arguments fact' do
describe 'kdump_kernel_arguments fact' do
before :each do
Facter.clear
end
Expand All @@ -10,7 +10,7 @@
expected_value = my_fixture_read('cmdline1')
allow(Facter::Core::Execution).to receive(:exec).with('uname -s').and_return('Linux')
allow(Facter::Core::Execution).to receive(:execute).with('cat /proc/cmdline 2>/dev/null').and_return(expected_value)
expect(Facter.fact(:kernel_arguments).value).to eq(expected_value)
expect(Facter.fact(:kdump_kernel_arguments).value).to eq(expected_value)
end
end
end