summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-04-27 12:08:08 -0700
committerTim Smith <tsmith@chef.io>2018-04-27 12:21:47 -0700
commitd677bf1741aa69004efc0e97c074bb1a4a7eb53d (patch)
tree85cb2d20e0b8ec953c8b4ecc06e8bbc8e5b70f52
parented82d81fb3d1aac8c20fe6ea6101834f39366f19 (diff)
downloadchef-d677bf1741aa69004efc0e97c074bb1a4a7eb53d.tar.gz
Simplify how we fetch systctl current values
Remove the raise that wasn't needed since we pass -e Remove the .to_s on the shell_out value since stdout is already a string Fail hard if we can't shellout for some reason by using shell_out! not shell_out Don't create an object out of the shellout result since we don't need that Kill the method entirely since it's now only a single line Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/sysctl.rb12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/chef/resource/sysctl.rb b/lib/chef/resource/sysctl.rb
index 75d2ef3262..faa9d59e95 100644
--- a/lib/chef/resource/sysctl.rb
+++ b/lib/chef/resource/sysctl.rb
@@ -63,14 +63,12 @@ class Chef
end
end
- def get_sysctl_value(key)
- o = shell_out("sysctl -n -e #{key}")
- raise "Unknown sysctl key #{key}!" if o.error?
- o.stdout.to_s.tr("\t", " ").strip
- end
-
+ # shellout to systctl to get the current value
+ # ignore missing keys by using '-e'
+ # convert tabs to spaces since systctl tab deliminates multivalue parameters
+ # strip the newline off the end of the output as well
load_current_value do
- value get_sysctl_value(key)
+ value shell_out!("sysctl -n -e #{key}").stdout.tr("\t", " ").strip
end
action :apply do