From 0ef64af1a9fa72130b14d6fe55cad58eb4ef1e61 Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Thu, 26 Nov 2020 05:09:16 -0800 Subject: [PATCH 1/2] correct RedHat capitalization --- lib/puppet/provider/kernel_parameter/grub2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/kernel_parameter/grub2.rb b/lib/puppet/provider/kernel_parameter/grub2.rb index b95759b..469d3f1 100644 --- a/lib/puppet/provider/kernel_parameter/grub2.rb +++ b/lib/puppet/provider/kernel_parameter/grub2.rb @@ -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' ] From 53b9b4389dd99056ee03a4298c35f9d6924e8152 Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Thu, 26 Nov 2020 05:10:04 -0800 Subject: [PATCH 2/2] attempt at deleting entries from both sections Fixes #52. --- lib/puppet/provider/kernel_parameter/grub2.rb | 7 +++++ .../provider/kernel_parameter/grub2_spec.rb | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/puppet/provider/kernel_parameter/grub2.rb b/lib/puppet/provider/kernel_parameter/grub2.rb index 469d3f1..673043e 100644 --- a/lib/puppet/provider/kernel_parameter/grub2.rb +++ b/lib/puppet/provider/kernel_parameter/grub2.rb @@ -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| diff --git a/spec/unit/puppet/provider/kernel_parameter/grub2_spec.rb b/spec/unit/puppet/provider/kernel_parameter/grub2_spec.rb index 5964c1c..b490b2e 100755 --- a/spec/unit/puppet/provider/kernel_parameter/grub2_spec.rb +++ b/spec/unit/puppet/provider/kernel_parameter/grub2_spec.rb @@ -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