summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-01-21 09:01:07 -0800
committerGitHub <noreply@github.com>2019-01-21 09:01:07 -0800
commit35e9edbecaff6f10dca4eef463d8d1e0c00338e5 (patch)
tree44adfeafe207b0d87b13a2eb9dda09a27e0eda48
parent1a58742eadbe1a2c236f06cc4167cff30be7cd60 (diff)
parent7c00ecf30ea22d67d10e5c848a8c36c50ab31a05 (diff)
downloadchef-35e9edbecaff6f10dca4eef463d8d1e0c00338e5.tar.gz
Merge pull request #8136 from MsysTechnologiesllc/Kapil/MSYS-931_Sysctl_doesn't_work_when_key_has_a_._in_the_name
Sysctl: Allow slashes in key or block name
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/tests.rb8
-rw-r--r--kitchen-tests/kitchen.yml1
-rw-r--r--lib/chef/resource/sysctl.rb12
3 files changed, 15 insertions, 6 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb b/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb
index 1c9171b9f3..b53fc39e17 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb
@@ -19,3 +19,11 @@ end
file "/tmp/chef-test-\xFDmlaut" do
content "testing illegal UTF-8 char in the filename"
end
+
+node["network"]["interfaces"].each do |interface_data|
+ interface = interface_data[0]
+ sysctl_param "net/ipv4/conf/#{interface}/rp_filter" do
+ value 0
+ ignore_failure true
+ end
+end
diff --git a/kitchen-tests/kitchen.yml b/kitchen-tests/kitchen.yml
index 7e654f1491..fd8e5383ea 100644
--- a/kitchen-tests/kitchen.yml
+++ b/kitchen-tests/kitchen.yml
@@ -37,3 +37,4 @@ suites:
- name: end-to-end
run_list:
- recipe[end_to_end::default]
+ - recipe[end_to_end::tests]
diff --git a/lib/chef/resource/sysctl.rb b/lib/chef/resource/sysctl.rb
index a5568904ba..53dfb0663e 100644
--- a/lib/chef/resource/sysctl.rb
+++ b/lib/chef/resource/sysctl.rb
@@ -80,7 +80,7 @@ class Chef
directory new_resource.conf_dir
- file "#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
+ file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf" do
content "#{new_resource.key} = #{new_resource.value}"
end
@@ -96,9 +96,9 @@ class Chef
description "Remove a sysctl value."
# only converge the resource if the file actually exists to delete
- if ::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf")
- converge_by "removing sysctl config at #{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
- file "#{new_resource.conf_dir}/99-chef-#{new_resource.key}.conf" do
+ if ::File.exist?("#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf")
+ converge_by "removing sysctl config at #{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf" do
+ file "#{new_resource.conf_dir}/99-chef-#{new_resource.key.tr('/', '.')}.conf" do
action :delete
end
@@ -140,8 +140,8 @@ class Chef
# return the value. Raise in case this conf file needs to be created
# or updated
def get_sysctld_value(key)
- raise unless ::File.exist?("/etc/sysctl.d/99-chef-#{key}.conf")
- k, v = ::File.read("/etc/sysctl.d/99-chef-#{key}.conf").match(/(.*) = (.*)/).captures
+ raise unless ::File.exist?("/etc/sysctl.d/99-chef-#{key.tr('/', '.')}.conf")
+ k, v = ::File.read("/etc/sysctl.d/99-chef-#{key.tr('/', '.')}.conf").match(/(.*) = (.*)/).captures
raise "Unknown sysctl key!" if k.nil?
raise "Unknown sysctl value!" if v.nil?
v