summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-10-21 17:28:09 -0700
committerGitHub <noreply@github.com>2021-10-21 17:28:09 -0700
commit2fafbc8d5ac411880878d7b64eda4054efea2867 (patch)
treeae35bb8a174d9522b229489a2748ea5a69aa728e
parent7ee28b18d1c2c40c2fb13a9c14a45c63c95a8b0e (diff)
parent3f5def1f1425e4905fbc832dab125f857b1ecd7f (diff)
downloadchef-2fafbc8d5ac411880878d7b64eda4054efea2867.tar.gz
Merge pull request #12105 from qubitrenegade/qbrd/kernel_module-enable
Add 'enable' action to 'kernel_module' resource to reverse 'disable' action.
-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..4084dcbd70 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 not installable.
```ruby
kernel_module 'loop' do
action :disable
end
```
+
+ Enable a kernel module so that it is can be installed. 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