From 42e8fb3ac885547f931acb4a92dbc812c51de29c Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 4 May 2020 15:14:49 -0700 Subject: Fix sysctl :remove action failing with missing :value prop Don't require this when removing. Signed-off-by: Tim Smith --- .../cookbooks/end_to_end/recipes/_alternatives.rb | 51 ++++++++++++++++++++++ .../cookbooks/end_to_end/recipes/_chef-vault.rb | 43 ++++++++++++++++++ .../cookbooks/end_to_end/recipes/_packages.rb | 24 ++++++++++ .../cookbooks/end_to_end/recipes/_sysctl.rb | 12 +++++ .../cookbooks/end_to_end/recipes/_tests.rb | 29 ++++++++++++ .../cookbooks/end_to_end/recipes/alternatives.rb | 51 ---------------------- .../cookbooks/end_to_end/recipes/chef-vault.rb | 43 ------------------ .../cookbooks/end_to_end/recipes/default.rb | 9 ++-- .../cookbooks/end_to_end/recipes/packages.rb | 24 ---------- .../cookbooks/end_to_end/recipes/tests.rb | 29 ------------ 10 files changed, 164 insertions(+), 151 deletions(-) create mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/_alternatives.rb create mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/_chef-vault.rb create mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/_packages.rb create mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb create mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/_tests.rb delete mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/alternatives.rb delete mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/chef-vault.rb delete mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/packages.rb delete mode 100644 kitchen-tests/cookbooks/end_to_end/recipes/tests.rb (limited to 'kitchen-tests/cookbooks') diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_alternatives.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_alternatives.rb new file mode 100644 index 0000000000..8e0a0bb178 --- /dev/null +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_alternatives.rb @@ -0,0 +1,51 @@ +# +# Cookbook:: end_to_end +# Recipe:: alternatives +# + +file "/usr/local/sample-binary-1" do + content '#!/bin/bash + echo sample-binary-v1 + ' + mode "500" +end + +file "/usr/local/sample-binary-2" do + content '#!/bin/bash + echo sample-binary-v2 + ' + mode "550" +end + +alternatives "sample-binary v1" do + link_name "sample-binary" + path "/usr/local/sample-binary-1" + priority 100 + action :install +end + +alternatives "sample-binary v2" do + link_name "sample-binary" + path "/usr/local/sample-binary-2" + priority 101 + action :install +end + +alternatives "set sample-binary v1" do + link_name "sample-binary" + path "/usr/local/sample-binary-1" + action :set +end + +alternatives "sample-binary-test v1" do + link_name "sample-binary-test" + path "/usr/local/sample-binary-1" + priority 100 + action :install +end + +alternatives "sample-binary-test v1" do + link_name "sample-binary-test" + path "/usr/local/sample-binary-1" + action :remove +end diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_chef-vault.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_chef-vault.rb new file mode 100644 index 0000000000..aa01982e3d --- /dev/null +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_chef-vault.rb @@ -0,0 +1,43 @@ +# +# Cookbook:: end_to_end +# Recipe:: chef-vault +# +# Copyright:: Copyright (c) Chef Software Inc. +# + +chef_data_bag "creds" + +openssl_rsa_private_key "/root/bob_bobberson.pem" do + key_length 2048 + action :create +end + +chef_client "bob_bobberson" do + source_key_path "/root/bob_bobberson.pem" +end + +chef_node "bob_bobberson" + +chef_vault_secret "super_secret_1" do + data_bag "creds" + raw_data("auth" => "1234") + admins "bob_bobberson" + search "*:*" +end + +chef_vault_secret "super_secret_2" do + data_bag "creds" + raw_data("auth" => "4321") + admins "bob_bobberson" +end + +ruby_block "load vault item" do + block do + begin + chef_vault_item("creds", "super_secret_1") + rescue ChefVault::Exceptions::SecretDecryption + puts "Not authorized for this key!" + end + end + action :run +end diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_packages.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_packages.rb new file mode 100644 index 0000000000..58ede61f52 --- /dev/null +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_packages.rb @@ -0,0 +1,24 @@ +# +# Cookbook:: end_to_end +# Recipe:: packages +# +# Copyright:: Copyright (c) Chef Software Inc. +# + +# this is just a list of package that exist on every O/S we test, and often aren't installed by default. you don't +# have to get too clever here, you can delete packages if they don't exist everywhere we test. +pkgs = %w{lsof tcpdump strace zsh dmidecode ltrace bc curl wget subversion traceroute htop tmux } + +# this deliberately calls the multipackage API N times in order to do one package installation in order to exercise the +# multipackage cookbook. +pkgs.each do |pkg| + multipackage pkgs +end + +gems = %w{chef-ruby-lvm community_cookbook_releaser} + +gems.each do |gem| + chef_gem gem do + compile_time false + end +end diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb new file mode 100644 index 0000000000..8c644e01c6 --- /dev/null +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_sysctl.rb @@ -0,0 +1,12 @@ +# +# Cookbook:: end_to_end +# Recipe:: sysctl +# + +sysctl "vm.swappiness" do + value 19 +end + +sysctl "kernel.msgmax" do + action :remove +end \ No newline at end of file diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_tests.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_tests.rb new file mode 100644 index 0000000000..d74a310394 --- /dev/null +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_tests.rb @@ -0,0 +1,29 @@ +# +# Cookbook:: end_to_end +# Recipe:: tests +# +# Copyright:: Copyright (c) Chef Software Inc. +# + +# +# this file is for random tests to check specific chef-client internal functionality +# + +file "/tmp/chef-test-ümlauts" do + content "testing UTF-8 char in the filename" +end + +# this caught a regression in 12.14.70 before it was released when i +# ran it in lamont-ci, so added the test here so everyone else other than +# me gets coverage for this as well. +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/cookbooks/end_to_end/recipes/alternatives.rb b/kitchen-tests/cookbooks/end_to_end/recipes/alternatives.rb deleted file mode 100644 index 8e0a0bb178..0000000000 --- a/kitchen-tests/cookbooks/end_to_end/recipes/alternatives.rb +++ /dev/null @@ -1,51 +0,0 @@ -# -# Cookbook:: end_to_end -# Recipe:: alternatives -# - -file "/usr/local/sample-binary-1" do - content '#!/bin/bash - echo sample-binary-v1 - ' - mode "500" -end - -file "/usr/local/sample-binary-2" do - content '#!/bin/bash - echo sample-binary-v2 - ' - mode "550" -end - -alternatives "sample-binary v1" do - link_name "sample-binary" - path "/usr/local/sample-binary-1" - priority 100 - action :install -end - -alternatives "sample-binary v2" do - link_name "sample-binary" - path "/usr/local/sample-binary-2" - priority 101 - action :install -end - -alternatives "set sample-binary v1" do - link_name "sample-binary" - path "/usr/local/sample-binary-1" - action :set -end - -alternatives "sample-binary-test v1" do - link_name "sample-binary-test" - path "/usr/local/sample-binary-1" - priority 100 - action :install -end - -alternatives "sample-binary-test v1" do - link_name "sample-binary-test" - path "/usr/local/sample-binary-1" - action :remove -end diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/chef-vault.rb b/kitchen-tests/cookbooks/end_to_end/recipes/chef-vault.rb deleted file mode 100644 index aa01982e3d..0000000000 --- a/kitchen-tests/cookbooks/end_to_end/recipes/chef-vault.rb +++ /dev/null @@ -1,43 +0,0 @@ -# -# Cookbook:: end_to_end -# Recipe:: chef-vault -# -# Copyright:: Copyright (c) Chef Software Inc. -# - -chef_data_bag "creds" - -openssl_rsa_private_key "/root/bob_bobberson.pem" do - key_length 2048 - action :create -end - -chef_client "bob_bobberson" do - source_key_path "/root/bob_bobberson.pem" -end - -chef_node "bob_bobberson" - -chef_vault_secret "super_secret_1" do - data_bag "creds" - raw_data("auth" => "1234") - admins "bob_bobberson" - search "*:*" -end - -chef_vault_secret "super_secret_2" do - data_bag "creds" - raw_data("auth" => "4321") - admins "bob_bobberson" -end - -ruby_block "load vault item" do - block do - begin - chef_vault_item("creds", "super_secret_1") - rescue ChefVault::Exceptions::SecretDecryption - puts "Not authorized for this key!" - end - end - action :run -end diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/default.rb b/kitchen-tests/cookbooks/end_to_end/recipes/default.rb index 54750039c5..6378d55bcc 100644 --- a/kitchen-tests/cookbooks/end_to_end/recipes/default.rb +++ b/kitchen-tests/cookbooks/end_to_end/recipes/default.rb @@ -40,7 +40,7 @@ build_essential do raise_if_unsupported true end -include_recipe "::packages" +include_recipe "::_packages" include_recipe "ntp" @@ -158,6 +158,7 @@ locale "set system locale" do only_if { debian? } end -include_recipe "::chef-vault" unless includes_recipe?("end_to_end::chef-vault") -include_recipe "::alternatives" -include_recipe "::tests" +include_recipe "::_chef-vault" unless includes_recipe?("end_to_end::chef-vault") +include_recipe "::_sysctl" +include_recipe "::_alternatives" +include_recipe "::_tests" diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/packages.rb b/kitchen-tests/cookbooks/end_to_end/recipes/packages.rb deleted file mode 100644 index 58ede61f52..0000000000 --- a/kitchen-tests/cookbooks/end_to_end/recipes/packages.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -# Cookbook:: end_to_end -# Recipe:: packages -# -# Copyright:: Copyright (c) Chef Software Inc. -# - -# this is just a list of package that exist on every O/S we test, and often aren't installed by default. you don't -# have to get too clever here, you can delete packages if they don't exist everywhere we test. -pkgs = %w{lsof tcpdump strace zsh dmidecode ltrace bc curl wget subversion traceroute htop tmux } - -# this deliberately calls the multipackage API N times in order to do one package installation in order to exercise the -# multipackage cookbook. -pkgs.each do |pkg| - multipackage pkgs -end - -gems = %w{chef-ruby-lvm community_cookbook_releaser} - -gems.each do |gem| - chef_gem gem do - compile_time false - end -end diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb b/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb deleted file mode 100644 index d74a310394..0000000000 --- a/kitchen-tests/cookbooks/end_to_end/recipes/tests.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# Cookbook:: end_to_end -# Recipe:: tests -# -# Copyright:: Copyright (c) Chef Software Inc. -# - -# -# this file is for random tests to check specific chef-client internal functionality -# - -file "/tmp/chef-test-ümlauts" do - content "testing UTF-8 char in the filename" -end - -# this caught a regression in 12.14.70 before it was released when i -# ran it in lamont-ci, so added the test here so everyone else other than -# me gets coverage for this as well. -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 -- cgit v1.2.1