summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqubitrenegade <qubitrenegade@gmail.com>2021-09-29 16:41:53 -0600
committerqubitrenegade <qubitrenegade@gmail.com>2021-10-18 14:36:15 -0600
commit37bd2e469c8fe86e20c312241bd64e2d5cf225c4 (patch)
tree77acf291778d5f9a660e677ecabe05ef819fe6fb
parent4a6e808ff905aa92aad8ad65b19b41ea73ac2706 (diff)
downloadchef-37bd2e469c8fe86e20c312241bd64e2d5cf225c4.tar.gz
Add 'enable' action to 'kernel_module' resource to reverse 'disable' action. Fixes #12104
Signed-off-by: qubitrenegade <qubitrenegade@gmail.com>
-rw-r--r--lib/chef/resource/kernel_module.rb29
-rw-r--r--spec/unit/resource/kernel_module_spec.rb3
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/chef/resource/kernel_module.rb b/lib/chef/resource/kernel_module.rb
index c4a36af9eb..6f548d8363 100644
--- a/lib/chef/resource/kernel_module.rb
+++ b/lib/chef/resource/kernel_module.rb
@@ -15,7 +15,7 @@ class Chef
provides :kernel_module
- description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, install, and uninstall modules."
+ description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, enable, install, and uninstall modules."
introduced "14.3"
examples <<~DOC
Install and load a kernel module, and ensure it loads on reboot.
@@ -68,13 +68,21 @@ class Chef
end
```
- Disable a kernel module.
+ Disable a kernel module so that it is uninstallable.
```ruby
kernel_module 'loop' do
action :disable
end
```
+
+ Enable a kernel module so that it is installable. Does not load or install.
+
+ ```ruby
+ kernel_module 'loop' do
+ action :enable
+ end
+ ```
DOC
property :modname, String,
@@ -101,6 +109,9 @@ class Chef
end
end
+ # Remove the "disable file" before trying to install
+ action_enable
+
# create options file before loading the module
unless new_resource.options.nil?
file "#{new_resource.unload_dir}/options_#{new_resource.modname}.conf" do
@@ -178,6 +189,20 @@ class Chef
action_unload
end
+ action :enable, description: "Enable a kernel module. Reverse :disable actions" do
+ with_run_context :root do
+ find_resource(:execute, "update initramfs") do
+ command initramfs_command
+ action :nothing
+ end
+ end
+
+ file "#{new_resource.unload_dir}/disable_#{new_resource.modname}.conf" do
+ action :delete
+ notifies :run, "execute[update initramfs]", :delayed
+ end
+ end
+
action :load, description: "Load a kernel module." do
unless module_loaded?
converge_by("load kernel module #{new_resource.modname}") do
diff --git a/spec/unit/resource/kernel_module_spec.rb b/spec/unit/resource/kernel_module_spec.rb
index aed31e03c8..b283fba0b8 100644
--- a/spec/unit/resource/kernel_module_spec.rb
+++ b/spec/unit/resource/kernel_module_spec.rb
@@ -32,10 +32,11 @@ describe Chef::Resource::KernelModule do
expect(resource.modname).to eql("foo")
end
- it "supports :create and :flush actions" do
+ it "supports various actions" do
expect { resource.action :install }.not_to raise_error
expect { resource.action :uninstall }.not_to raise_error
expect { resource.action :blacklist }.not_to raise_error
+ expect { resource.action :enable }.not_to raise_error
expect { resource.action :disable }.not_to raise_error
expect { resource.action :load }.not_to raise_error
expect { resource.action :unload }.not_to raise_error