summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-04-21 18:38:18 -0700
committerTim Smith <tsmith@chef.io>2018-05-30 15:18:40 -0700
commitd0d2ba0ec37ee39ffd7f17ae43d60cbf146afc3e (patch)
tree047cd8ef994b69a3aa9cb3ca4ef0b1aeda7369aa
parent4838d32e61faf6d88b0ed34924cdf077465a6419 (diff)
downloadchef-d0d2ba0ec37ee39ffd7f17ae43d60cbf146afc3e.tar.gz
Use shell_out and a file read instead of execute
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/kernel_module.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/chef/resource/kernel_module.rb b/lib/chef/resource/kernel_module.rb
index 9b1836e266..e7c11cb67f 100644
--- a/lib/chef/resource/kernel_module.rb
+++ b/lib/chef/resource/kernel_module.rb
@@ -74,19 +74,25 @@ class Chef
# Load kernel module
action :load do
- declare_resource(:execute, "modprobe #{new_resource.modname}") do
- not_if "cat /proc/modules | grep ^#{new_resource.modname}"
+ unless module_loaded?
+ converge_by("load kernel module #{new_resource.modname}") do
+ shell_out!("modprobe #{new_resource.modname}")
+ end
end
end
# Unload kernel module
action :unload do
- declare_resource(:execute, "modprobe -r #{new_resource.modname}") do
- only_if "cat /proc/modules | grep ^#{new_resource.modname}"
+ if module_loaded?
+ converge_by("unload kernel module #{new_resource.modname}") do
+ shell_out!("modprobe -r #{new_resource.modname}")
+ end
end
end
action_class do
+ # determine the correct command to regen the initramfs based on platform
+ # @return [String]
def initramfs_command
if platform_family?("debian")
"update-initramfs -u"
@@ -94,6 +100,12 @@ class Chef
"dracut -f"
end
end
+
+ # see if the module is listed in /proc/modules or not
+ # @return [Boolean]
+ def module_loaded?
+ /^#{new_resource.modname}/.match?(::File.read("/proc/modules"))
+ end
end
end
end