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

Ensure kernel parameters are absent from both GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT #62

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/puppet/provider/kernel_parameter/grub2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.mkconfig_path
which("grub2-mkconfig") or which("grub-mkconfig") or '/usr/sbin/grub-mkconfig'
end

defaultfor :osfamily => 'Redhat', :operatingsystemmajrelease => [ '7' ]
defaultfor :osfamily => 'RedHat', :operatingsystemmajrelease => [ '7' ]
defaultfor :operatingsystem => 'Debian', :operatingsystemmajrelease => [ '8' ]
defaultfor :operatingsystem => 'Ubuntu', :operatingsystemmajrelease => [ '14.04' ]

Expand Down Expand Up @@ -77,6 +77,13 @@ def create
self.value=(resource[:value])
end

def destroy
augopen! do |aug|
aug.rm("$target/GRUB_CMDLINE_LINUX_DEFAULT/value[.=~regexp('^#{resource[:name]}(=.*)?$')]")
aug.rm("$target/GRUB_CMDLINE_LINUX/value[.=~regexp('^#{resource[:name]}(=.*)?$')]")
end
end

def value
augopen do |aug|
aug.match('$resource').map {|vp|
Expand Down
26 changes: 26 additions & 0 deletions spec/unit/puppet/provider/kernel_parameter/grub2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,32 @@
')
end

it "should delete entries from GRUB_CMDLINE_LINUX_DEFAULT with bootmode all" do
provider_class.any_instance.expects(:mkconfig).with("-o", "/boot/grub2/grub.cfg")
provider_class.any_instance.expects(:mkconfig).with("-o", "/etc/grub2-efi.cfg")

apply!(Puppet::Type.type(:kernel_parameter).new(
:name => "rhgb",
:ensure => "absent",
:bootmode => :all,
:target => target,
:provider => "grub2"
))

augparse_filter(target, LENS, FILTER, '
{ "GRUB_CMDLINE_LINUX"
{ "quote" = "\"" }
{ "value" = "quiet" }
{ "value" = "elevator=noop" }
{ "value" = "divider=10" }
}
{ "GRUB_CMDLINE_LINUX_DEFAULT"
{ "quote" = "\"" }
{ "value" = "nohz=on" }
}
')
end

describe "when modifying values" do
before :each do
provider_class.any_instance.stubs(:create).never
Expand Down