summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-01-21 10:08:24 -0800
committerGitHub <noreply@github.com>2019-01-21 10:08:24 -0800
commitf6b4553c8dfd5ddd998f106be3786b95a9fe1ec9 (patch)
tree3796b4efce4b14012f497ff115635590096a66cb
parent50fb680ed3abffdc3ce1152ebf758615d132e7f8 (diff)
parent50cda82a9be3a4c08f82dcb074cc7edf87037c2d (diff)
downloadchef-f6b4553c8dfd5ddd998f106be3786b95a9fe1ec9.tar.gz
Merge pull request #8142 from chef/sysctl_14
systctl: 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