diff --git a/.foodcritic b/.foodcritic new file mode 100644 index 0000000..1aa8e2b --- /dev/null +++ b/.foodcritic @@ -0,0 +1,4 @@ +~FC007 +~FC015 +~FC023 +~FC059 diff --git a/.kitchen.dokken.yml b/.kitchen.dokken.yml new file mode 100644 index 0000000..575c2b7 --- /dev/null +++ b/.kitchen.dokken.yml @@ -0,0 +1,72 @@ +driver: + name: dokken + privileged: true # because Docker and SystemD/Upstart + +transport: + name: dokken + +provisioner: + name: dokken + +platforms: +- name: debian-7 + driver: + image: debian:7 + pid_one_command: /sbin/init + intermediate_instructions: + - RUN /usr/bin/apt-get update + - RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y + +- name: debian-8 + driver: + image: debian:8 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + - RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y + +- name: centos-6 + driver: + image: centos:6 + platform: rhel + pid_one_command: /sbin/init + intermediate_instructions: + - RUN yum -y install lsof which initscripts net-tools wget net-tools + +- name: centos-7 + driver: + image: centos:7 + platform: rhel + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN yum -y install lsof which systemd-sysv initscripts wget net-tools + +- name: fedora-25 + driver: + image: fedora:latest + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN dnf -y install yum which systemd-sysv initscripts wget net-tools + +- name: ubuntu-14.04 + driver: + image: ubuntu-upstart:14.04 + pid_one_command: /sbin/init + intermediate_instructions: + - RUN /usr/bin/apt-get update + - RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y + +- name: ubuntu-16.04 + driver: + image: ubuntu:16.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + - RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y + +- name: opensuse-leap + driver: + image: opensuse:leap + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN zypper --non-interactive install aaa_base perl-Getopt-Long-Descriptive which net-tools diff --git a/.kitchen.yml b/.kitchen.yml index 026d59d..781e9c9 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,42 +1,34 @@ --- driver: name: vagrant + chef_version: current provisioner: - name: chef_solo + name: chef_zero data_bags_path: "data_bags" - roles_path: "roles" - environments_path: "environments" - require_chef_omnibus: true + +verifier: + name: inspec client_rb: treat_deprecation_warnings_as_errors: true resource_cloning: false platforms: +- name: debian-7.11 +- name: debian-8.7 +- name: centos-6.8 +- name: centos-7.3 +- name: fedora-25 - name: ubuntu-14.04 - name: ubuntu-16.04 -- name: debian-7.10 -- name: debian-8.4 -- name: centos-6.7 -- name: centos-7.2 -- name: scientific-6.4 - driver: - box: lyte-scientific-6-minimal - box_url: http://lyte.id.au/vagrant/sl6-64-lyte.box -- name: srijn-arch-2014-01-07 - driver: - box: srijn-arch-2014-01-07 - box_url: http://vagrant.srijn.net/archlinux-x64-2014-01-07.box -- name: fedora-18 -- name: fedora-23 -- name: freebsd-10.3 +- name: freebsd-11.0 +- name: opensuse-leap-42.1 suites: - name: default run_list: - - recipe[sysctl_test] - - recipe[sysctl_test::tcp_wmem] + - recipe[sysctl_test::default] - recipe[sysctl::ohai_plugin] attributes: sysctl: @@ -49,7 +41,6 @@ suites: - name: lwrps run_list: - recipe[sysctl_test] - - recipe[sysctl_test::tcp_wmem] - name: attributes run_list: - recipe[sysctl::apply] @@ -58,6 +49,6 @@ suites: params: vm: swappiness: 19 - net: - ipv4: - tcp_fin_timeout: 29 + dev: + cdrom: + autoeject: 1 diff --git a/.travis.yml b/.travis.yml index 09fec80..30e9ce2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,14 @@ +sudo: required +dist: trusty + +# install the pre-release chef-dk. Use chef-stable-trusty to install the stable release +addons: + apt: + sources: + - chef-stable-trusty + packages: + - chefdk + notifications: webhooks: urls: @@ -5,11 +16,52 @@ notifications: on_success: change # options: [always|never|change] default: always on_failure: always # options: [always|never|change] default: always on_start: false # default: false -language: ruby -rvm: - - 2.3.1 -bundler_args: --without integration development -script: - - bundle exec foodcritic -f any . --tags ~FC007 --tags ~FC015 --tags ~FC023 --tags ~FC059 - - bundle exec rubocop -r cookstyle - - bundle exec rspec + +# Don't `bundle install` which takes about 1.5 mins +install: echo "skip bundle install" + +branches: + only: + - master + +services: docker + +env: + matrix: + - INSTANCE=default-debian-7 + - INSTANCE=default-debian-8 + - INSTANCE=default-centos-6 + - INSTANCE=default-centos-7 + - INSTANCE=default-fedora-25 + # - INSTANCE=default-opensuse-leap + - INSTANCE=lwrps-debian-7 + - INSTANCE=lwrps-debian-8 + - INSTANCE=lwrps-centos-6 + - INSTANCE=lwrps-centos-7 + - INSTANCE=lwrps-fedora-25 + - INSTANCE=lwrps-ubuntu-1604 + # - INSTANCE=lwrps-opensuse-leap + - INSTANCE=attributes-debian-7 + - INSTANCE=attributes-debian-8 + - INSTANCE=attributes-centos-6 + - INSTANCE=attributes-centos-7 + - INSTANCE=attributes-fedora-25 + - INSTANCE=attributes-ubuntu-1404 + - INSTANCE=attributes-ubuntu-1604 + # - INSTANCE=attributes-opensuse-leap + +before_script: + - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) + - eval "$(/opt/chefdk/bin/chef shell-init bash)" + - /opt/chefdk/embedded/bin/chef --version + - /opt/chefdk/embedded/bin/cookstyle --version + - /opt/chefdk/embedded/bin/foodcritic --version + - chef gem install kitchen-dokken + +script: KITCHEN_LOCAL_YAML=.kitchen.dokken.yml /opt/chefdk/embedded/bin/kitchen verify ${INSTANCE} + +matrix: + include: + - script: + - /opt/chefdk/bin/chef exec rake + env: UNIT_AND_LINT=1 diff --git a/Berksfile b/Berksfile index d6b6139..dc66ad3 100644 --- a/Berksfile +++ b/Berksfile @@ -3,7 +3,5 @@ source 'https://supermarket.chef.io' metadata group :integration do - cookbook 'apt', '~> 3.0.0' cookbook 'sysctl_test', :path => './test/cookbooks/sysctl_test' - cookbook 'yum', '~> 3.10.0' end diff --git a/Berksfile.lock b/Berksfile.lock index 0ab0c85..a57e61e 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -1,19 +1,13 @@ DEPENDENCIES - apt (~> 3.0.0) sysctl path: . metadata: true sysctl_test path: test/cookbooks/sysctl_test - yum (~> 3.10.0) GRAPH - apt (3.0.0) - compat_resource (12.10.6) - ohai (4.1.1) - compat_resource (>= 12.10) + ohai (5.0.0) sysctl (0.8.1) ohai (>= 4.0.0) sysctl_test (0.1.0) sysctl (>= 0.0.0) - yum (3.10.0) diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 363b394..0000000 --- a/Gemfile +++ /dev/null @@ -1,23 +0,0 @@ -source 'https://rubygems.org' - -# resolve nokogiri updates for chefdk, although it may force chefdk now -# https://github.com/chef/chef-dk/issues/278#issuecomment-89251860 -ENV['PKG_CONFIG_PATH'] = '/opt/chefdk/embedded/lib/pkgconfig' - -gem 'berkshelf', '~> 5.1', '>= 5.1.0' - -group :unit do - gem 'chefspec', '~> 5.3', '>= 5.3.0' - gem 'foodcritic', '~> 8.1', '>= 8.1.0' - gem 'rubocop', '= 0.39' - gem 'chefspec', '~> 5.3', '>= 5.3.0' - gem 'cookstyle' -end - -group :integration do - gem 'kitchen-digitalocean', :require => false - gem 'kitchen-docker', :require => false - gem 'kitchen-ec2', :require => false - gem 'kitchen-vagrant', :require => false - gem 'test-kitchen', '~> 1.13.2' -end diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index f413748..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,342 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (5.0.0.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.5.0) - public_suffix (~> 2.0, >= 2.0.2) - artifactory (2.5.1) - ast (2.3.0) - aws-sdk (2.6.35) - aws-sdk-resources (= 2.6.35) - aws-sdk-core (2.6.35) - aws-sigv4 (~> 1.0) - jmespath (~> 1.0) - aws-sdk-resources (2.6.35) - aws-sdk-core (= 2.6.35) - aws-sigv4 (1.0.0) - axiom-types (0.1.1) - descendants_tracker (~> 0.0.4) - ice_nine (~> 0.11.0) - thread_safe (~> 0.3, >= 0.3.1) - backports (3.6.8) - berkshelf (5.2.0) - addressable (~> 2.3, >= 2.3.4) - berkshelf-api-client (>= 2.0.2, < 4.0) - buff-config (~> 2.0) - buff-extensions (~> 2.0) - buff-shell_out (~> 1.0) - cleanroom (~> 1.0) - faraday (~> 0.9) - httpclient (~> 2.7) - minitar (~> 0.5, >= 0.5.4) - mixlib-archive (~> 0.1) - octokit (~> 4.0) - retryable (~> 2.0) - ridley (~> 5.0) - solve (> 2.0, < 4.0) - thor (~> 0.19) - berkshelf-api-client (3.0.0) - faraday (~> 0.9) - httpclient (~> 2.7) - ridley (>= 4.5, < 6.0) - buff-config (2.0.0) - buff-extensions (~> 2.0) - varia_model (~> 0.6) - buff-extensions (2.0.0) - buff-ignore (1.2.0) - buff-ruby_engine (1.0.0) - buff-shell_out (1.1.0) - buff-ruby_engine (~> 1.0) - builder (3.2.2) - celluloid (0.16.0) - timers (~> 4.0.0) - celluloid-io (0.16.2) - celluloid (>= 0.16.0) - nio4r (>= 1.1.0) - chef (12.16.42) - addressable - bundler (>= 1.10) - chef-config (= 12.16.42) - chef-zero (>= 4.8) - diff-lcs (~> 1.2, >= 1.2.4) - erubis (~> 2.7) - ffi-yajl (~> 2.2) - highline (~> 1.6, >= 1.6.9) - iniparse (~> 1.4) - mixlib-archive (>= 0.2.0) - mixlib-authentication (~> 1.4) - mixlib-cli (~> 1.7) - mixlib-log (~> 1.3) - mixlib-shellout (~> 2.0) - net-sftp (~> 2.1, >= 2.1.2) - net-ssh (>= 2.9, < 4.0) - net-ssh-multi (~> 1.1) - ohai (>= 8.6.0.alpha.1, < 9) - plist (~> 3.2) - proxifier (~> 1.0) - rspec-core (~> 3.5) - rspec-expectations (~> 3.5) - rspec-mocks (~> 3.5) - rspec_junit_formatter (~> 0.2.0) - serverspec (~> 2.7) - specinfra (~> 2.10) - syslog-logger (~> 1.6) - uuidtools (~> 2.1.5) - chef-config (12.16.42) - addressable - fuzzyurl - mixlib-config (~> 2.0) - mixlib-shellout (~> 2.0) - chef-zero (5.1.0) - ffi-yajl (~> 2.2) - hashie (>= 2.0, < 4.0) - mixlib-log (~> 1.3) - rack (~> 2.0) - uuidtools (~> 2.1) - chefspec (5.3.0) - chef (>= 12.0) - fauxhai (~> 3.6) - rspec (~> 3.0) - cleanroom (1.0.0) - coercible (1.0.0) - descendants_tracker (~> 0.0.1) - concurrent-ruby (1.0.2) - cookstyle (0.0.1) - rubocop (= 0.39.0) - cucumber-core (2.0.0) - backports (~> 3.6) - gherkin (~> 4.0) - descendants_tracker (0.0.4) - thread_safe (~> 0.3, >= 0.3.1) - diff-lcs (1.2.5) - droplet_kit (1.4.3) - activesupport (> 3.0, < 5.1) - faraday (~> 0.9.1) - kartograph (~> 0.2.3) - resource_kit (~> 0.1.5) - virtus (~> 1.0.3) - equalizer (0.0.11) - erubis (2.7.0) - excon (0.54.0) - faraday (0.9.2) - multipart-post (>= 1.2, < 3) - fauxhai (3.10.0) - net-ssh - ffi (1.9.14) - ffi-yajl (2.3.0) - libyajl2 (~> 1.2) - foodcritic (8.1.0) - cucumber-core (>= 1.3) - erubis - nokogiri (>= 1.5, < 2.0) - rake - rufus-lru (~> 1.0) - treetop (~> 1.4) - yajl-ruby (~> 1.1) - fuzzyurl (0.9.0) - gherkin (4.0.0) - hashie (3.4.6) - highline (1.7.8) - hitimes (1.2.4) - httpclient (2.8.3) - i18n (0.7.0) - ice_nine (0.11.2) - iniparse (1.4.2) - ipaddress (0.8.3) - jmespath (1.3.1) - json (2.0.2) - kartograph (0.2.4) - kitchen-digitalocean (0.9.5) - droplet_kit (~> 1.0) - test-kitchen (~> 1.2) - kitchen-docker (2.6.0) - test-kitchen (>= 1.0.0) - kitchen-ec2 (1.2.0) - aws-sdk (~> 2) - excon - multi_json - retryable (~> 2.0) - test-kitchen (~> 1.4, >= 1.4.1) - kitchen-vagrant (0.21.1) - test-kitchen (~> 1.4) - libyajl2 (1.2.0) - mini_portile2 (2.1.0) - minitar (0.5.4) - minitest (5.10.1) - mixlib-archive (0.2.0) - mixlib-log - mixlib-authentication (1.4.1) - mixlib-log - mixlib-cli (1.7.0) - mixlib-config (2.2.4) - mixlib-install (2.1.9) - artifactory - mixlib-shellout - mixlib-versioning - thor - mixlib-log (1.7.1) - mixlib-shellout (2.2.7) - mixlib-versioning (1.1.0) - molinillo (0.5.4) - multi_json (1.12.1) - multipart-post (2.0.0) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-sftp (2.1.2) - net-ssh (>= 2.6.5) - net-ssh (3.2.0) - net-ssh-gateway (1.2.0) - net-ssh (>= 2.6.5) - net-ssh-multi (1.2.1) - net-ssh (>= 2.6.5) - net-ssh-gateway (>= 1.2.0) - net-telnet (0.1.1) - nio4r (1.2.1) - nokogiri (1.6.8.1) - mini_portile2 (~> 2.1.0) - octokit (4.6.2) - sawyer (~> 0.8.0, >= 0.5.3) - ohai (8.22.1) - chef-config (>= 12.5.0.alpha.1, < 13) - ffi (~> 1.9) - ffi-yajl (~> 2.2) - ipaddress - mixlib-cli - mixlib-config (~> 2.0) - mixlib-log (>= 1.7.1, < 2.0) - mixlib-shellout (~> 2.0) - plist (~> 3.1) - systemu (~> 2.6.4) - wmi-lite (~> 1.0) - parser (2.3.3.1) - ast (~> 2.2) - plist (3.2.0) - polyglot (0.3.5) - powerpack (0.1.1) - proxifier (1.0.3) - public_suffix (2.0.4) - rack (2.0.1) - rainbow (2.1.0) - rake (12.0.0) - resource_kit (0.1.6) - addressable (>= 2.3.6, < 3.0.0) - retryable (2.0.4) - ridley (5.1.0) - addressable - buff-config (~> 2.0) - buff-extensions (~> 2.0) - buff-ignore (~> 1.2) - buff-shell_out (~> 1.0) - celluloid (~> 0.16.0) - celluloid-io (~> 0.16.1) - chef-config (>= 12.5.0) - erubis - faraday (~> 0.9.0) - hashie (>= 2.0.2, < 4.0.0) - httpclient (~> 2.7) - json (>= 1.7.7) - mixlib-authentication (>= 1.3.0) - retryable (~> 2.0) - semverse (~> 2.0) - varia_model (~> 0.6) - rspec (3.5.0) - rspec-core (~> 3.5.0) - rspec-expectations (~> 3.5.0) - rspec-mocks (~> 3.5.0) - rspec-core (3.5.4) - rspec-support (~> 3.5.0) - rspec-expectations (3.5.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-its (1.2.0) - rspec-core (>= 3.0.0) - rspec-expectations (>= 3.0.0) - rspec-mocks (3.5.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-support (3.5.0) - rspec_junit_formatter (0.2.3) - builder (< 4) - rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.39.0) - parser (>= 2.3.0.7, < 3.0) - powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) - ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.8.1) - rufus-lru (1.1.0) - safe_yaml (1.0.4) - sawyer (0.8.1) - addressable (>= 2.3.5, < 2.6) - faraday (~> 0.8, < 1.0) - semverse (2.0.0) - serverspec (2.37.2) - multi_json - rspec (~> 3.0) - rspec-its - specinfra (~> 2.53) - sfl (2.3) - solve (3.1.0) - molinillo (>= 0.5) - semverse (>= 1.1, < 3.0) - specinfra (2.66.2) - net-scp - net-ssh (>= 2.7, < 4.0) - net-telnet - sfl - syslog-logger (1.6.8) - systemu (2.6.5) - test-kitchen (1.13.2) - mixlib-install (>= 1.2, < 3.0) - mixlib-shellout (>= 1.2, < 3.0) - net-scp (~> 1.1) - net-ssh (>= 2.9, < 4.0) - net-ssh-gateway (~> 1.2.0) - safe_yaml (~> 1.0) - thor (~> 0.18) - thor (0.19.4) - thread_safe (0.3.5) - timers (4.0.4) - hitimes - treetop (1.6.8) - polyglot (~> 0.3) - tzinfo (1.2.2) - thread_safe (~> 0.1) - unicode-display_width (1.1.2) - uuidtools (2.1.5) - varia_model (0.6.0) - buff-extensions (~> 2.0) - hashie (>= 2.0.2, < 4.0.0) - virtus (1.0.5) - axiom-types (~> 0.1) - coercible (~> 1.0) - descendants_tracker (~> 0.0, >= 0.0.3) - equalizer (~> 0.0, >= 0.0.9) - wmi-lite (1.0.0) - yajl-ruby (1.3.0) - -PLATFORMS - ruby - -DEPENDENCIES - berkshelf (~> 5.1, >= 5.1.0) - chefspec (~> 5.3, >= 5.3.0) - cookstyle - foodcritic (~> 8.1, >= 8.1.0) - kitchen-digitalocean - kitchen-docker - kitchen-ec2 - kitchen-vagrant (~> 0.20) - rb-fsevent - rb-inotify - rubocop (= 0.39) - terminal-notifier-guard - test-kitchen (~> 1.13.2) - -BUNDLED WITH - 1.12.5 diff --git a/Rakefile b/Rakefile index 4754a0b..3162eaa 100644 --- a/Rakefile +++ b/Rakefile @@ -1,42 +1,67 @@ -require 'rspec/core/rake_task' -require 'rubocop/rake_task' -require 'foodcritic' -require 'kitchen' +#!/usr/bin/env rake -# Style tests. Rubocop and Foodcritic +# Style tests. cookstyle (rubocop) and Foodcritic namespace :style do - desc 'Run Ruby style checks' - RuboCop::RakeTask.new(:ruby) - - desc 'Run Chef style checks' - FoodCritic::Rake::LintTask.new(:chef) do |t| - t.options = { - fail_tags: ['any'], - tags: %w(~FC007 ~FC015 ~FC023 ~FC059) - } + begin + require 'cookstyle' + require 'rubocop/rake_task' + + desc 'Run Ruby style checks' + RuboCop::RakeTask.new(:ruby) + rescue LoadError => e + puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI'] + end + + begin + require 'foodcritic' + + desc 'Run Chef style checks' + FoodCritic::Rake::LintTask.new(:chef) do |t| + t.options = { + fail_tags: ['any'], + progress: true, + } + end + rescue LoadError => e + puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI'] end end desc 'Run all style checks' -task style: %w(style:chef style:ruby) +task style: ['style:chef', 'style:ruby'] + +# ChefSpec +begin + require 'rspec/core/rake_task' -# Rspec and ChefSpec -desc 'Run ChefSpec examples' -RSpec::Core::RakeTask.new(:spec) + desc 'Run ChefSpec examples' + RSpec::Core::RakeTask.new(:spec) +rescue LoadError => e + puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI'] +end # Integration tests. Kitchen.ci namespace :integration do - desc 'Run Test Kitchen with Vagrant' - task :vagrant do - Kitchen.logger = Kitchen.default_file_logger - Kitchen::Config.new.instances.each do |instance| - instance.test(:always) - end + begin + require 'kitchen/rake_tasks' + + desc 'Run kitchen integration tests' + Kitchen::RakeTasks.new + rescue StandardError => e + puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI'] end end -desc 'Run all tests on Travis' -task travis: %w(style spec) +namespace :supermarket do + begin + require 'stove/rake_task' + + desc 'Publish cookbook to Supermarket with Stove' + Stove::RakeTask.new + rescue LoadError => e + puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI'] + end +end # Default -task default: %w(style spec integration:vagrant) +task default: %w(style spec) diff --git a/metadata.rb b/metadata.rb index 4903242..2411b83 100644 --- a/metadata.rb +++ b/metadata.rb @@ -7,12 +7,12 @@ description 'Configures sysctl parameters' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '0.8.1' -chef_version '>= 12' +chef_version '>= 12.5' ohai_version '>= 8' -supports 'ubuntu', '>= 12.04' +supports 'ubuntu', '>= 14.04' supports 'debian', '>= 7.0' -supports 'centos', '>= 5.9' +supports 'centos', '>= 6.0' supports 'scientific', '>= 6.4' supports 'suse', '>= 11.0' supports 'redhat' diff --git a/recipes/service.rb b/recipes/service.rb index 708dcd1..fdde70f 100644 --- a/recipes/service.rb +++ b/recipes/service.rb @@ -25,38 +25,5 @@ service 'procps' do supports :restart => true, :reload => true, :status => false - case node['platform'] - when 'freebsd' - service_name 'sysctl' - when 'arch', 'exherbo' - service_name 'systemd-sysctl' - provider Chef::Provider::Service::Systemd - when 'centos', 'redhat', 'scientific' - if node['platform_version'].to_f >= 7.0 - service_name 'systemd-sysctl' - provider Chef::Provider::Service::Systemd - end - when 'fedora' - if node['platform_version'].to_f >= 18 - service_name 'systemd-sysctl' - provider Chef::Provider::Service::Systemd - end - when 'ubuntu' - if node['platform_version'].to_f >= 9.10 && node['platform_version'].to_f < 15.04 - service_name 'procps-instance' if node['platform_version'].to_f >= 14.10 - provider Chef::Provider::Service::Upstart - elsif node['platform_version'].to_f >= 15.04 - service_name 'systemd-sysctl' - provider Chef::Provider::Service::Init::Systemd - end - when 'suse' - if node['platform_version'].to_f < 12.0 - supports :restart => false, :reload => false, :status => true - service_name 'boot.sysctl' - elsif node['platform_version'].to_f >= 12.0 - service_name 'systemd-sysctl' - provider Chef::Provider::Service::Systemd - end - end action :enable end diff --git a/spec/apply_spec.rb b/spec/apply_spec.rb index 710ad9d..0a97564 100644 --- a/spec/apply_spec.rb +++ b/spec/apply_spec.rb @@ -10,7 +10,7 @@ 'redhat' => ['6.5', '7.0'], 'centos' => ['6.5', '7.0'], 'freebsd' => ['10.3'], - 'suse' => ['11.2', '12.0'] + 'suse' => ['11.2', '12.0'], } # Test all generic stuff on all platforms @@ -22,13 +22,13 @@ runner.node.default['sysctl']['conf_dir'] = '/etc/sysctl.d' runner.node.default['sysctl']['params'] = { 'vm' => { - 'swappiness' => 19 + 'swappiness' => 19, }, 'net' => { 'ipv4' => { - 'tcp_fin_timeout' => 29 - } - } + 'tcp_fin_timeout' => 29, + }, + }, } runner.converge('sysctl::apply') end diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 672dee6..ca35618 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -10,7 +10,7 @@ 'redhat' => ['6.6', '7.1'], 'centos' => ['6.7', '7.2.1511'], 'freebsd' => ['10.3'], - 'opensuse' => ['12.3', '13.2'] + 'opensuse' => ['12.3', '13.2'], } # Test all generic stuff on all platforms @@ -22,13 +22,13 @@ node.default['sysctl']['conf_dir'] = '/etc/sysctl.d' node.default['sysctl']['params'] = { 'vm' => { - 'swappiness' => 19 + 'swappiness' => 19, }, 'net' => { 'ipv4' => { - 'tcp_fin_timeout' => 29 - } - } + 'tcp_fin_timeout' => 29, + }, + }, } end.converge('sysctl::default') end @@ -82,13 +82,13 @@ runner.node.default['sysctl']['conf_dir'] = '/etc/sysctl.d' runner.node.default['sysctl']['params'] = { 'vm' => { - 'swappiness' => 19 + 'swappiness' => 19, }, 'net' => { 'ipv4' => { - 'tcp_fin_timeout' => 29 - } - } + 'tcp_fin_timeout' => 29, + }, + }, } runner.converge('sysctl::default') end diff --git a/spec/service_spec.rb b/spec/service_spec.rb index 49d396c..9f9cfc8 100644 --- a/spec/service_spec.rb +++ b/spec/service_spec.rb @@ -10,7 +10,7 @@ 'redhat' => ['6.5', '7.0'], 'centos' => ['6.5', '7.0'], 'freebsd' => ['10.3'], - 'suse' => ['11.2', '12.0'] + 'suse' => ['11.2', '12.0'], } # Test all generic stuff on all platforms @@ -22,13 +22,13 @@ runner.node.default['sysctl']['conf_dir'] = '/etc/sysctl.d' runner.node.default['sysctl']['params'] = { 'vm' => { - 'swappiness' => 19 + 'swappiness' => 19, }, 'net' => { 'ipv4' => { - 'tcp_fin_timeout' => 29 - } - } + 'tcp_fin_timeout' => 29, + }, + }, } runner.converge('sysctl::service') end diff --git a/spec/sysctl_test_spec.rb b/spec/sysctl_test_spec.rb index d57d416..8f44395 100644 --- a/spec/sysctl_test_spec.rb +++ b/spec/sysctl_test_spec.rb @@ -7,7 +7,7 @@ node.default['sysctl']['conf_dir'] = '/etc/sysctl.d' node.default['sysctl']['params'] = {} node.default['sysctl']['allow_sysctl_conf'] = false - end.converge 'sysctl_test' + end.converge 'sysctl_test::chefspec' end it 'applies a sysctl_param named net.ipv4.tcp_max_syn_backlog with value 12345' do diff --git a/test/cookbooks/sysctl_test/Gemfile b/test/cookbooks/sysctl_test/Gemfile deleted file mode 100644 index 3017623..0000000 --- a/test/cookbooks/sysctl_test/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'https://rubygems.org' - -gem 'berkshelf' diff --git a/test/cookbooks/sysctl_test/recipes/chefspec.rb b/test/cookbooks/sysctl_test/recipes/chefspec.rb new file mode 100644 index 0000000..00393d4 --- /dev/null +++ b/test/cookbooks/sysctl_test/recipes/chefspec.rb @@ -0,0 +1,33 @@ +# +# Cookbook Name:: test_sysctl +# Attributes:: default +# +# Copyright 2013-2014, OneHealth Solutions, Inc. +# Copyright 2014, Viverae, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +include_recipe 'sysctl' + +sysctl_param 'net.ipv4.tcp_max_syn_backlog' do + value 12_345 +end + +sysctl_param 'net.ipv4.tcp_rmem' do + value '4096 16384 33554432' +end + +# remove sysctl parameter and set net.ipv4.tcp_fin_timeout back to default +# sysctl_param 'net.ipv4.tcp_fin_timeout' do +# action :remove +# end diff --git a/test/cookbooks/sysctl_test/recipes/default.rb b/test/cookbooks/sysctl_test/recipes/default.rb index 00393d4..004a10b 100644 --- a/test/cookbooks/sysctl_test/recipes/default.rb +++ b/test/cookbooks/sysctl_test/recipes/default.rb @@ -19,12 +19,20 @@ # include_recipe 'sysctl' -sysctl_param 'net.ipv4.tcp_max_syn_backlog' do - value 12_345 +# sysctl_param 'net.ipv4.tcp_max_syn_backlog' do +# value 12_345 +# end + +# sysctl_param 'net.ipv4.tcp_rmem' do +# value '4096 16384 33554432' +# end +# +sysctl_param 'dev.cdrom.autoeject' do + value 1 end -sysctl_param 'net.ipv4.tcp_rmem' do - value '4096 16384 33554432' +sysctl_param 'vm.swappiness' do + value '19' end # remove sysctl parameter and set net.ipv4.tcp_fin_timeout back to default diff --git a/test/integration/default/serverspec/attrs_spec.rb b/test/integration/attributes/attrs_spec.rb similarity index 70% rename from test/integration/default/serverspec/attrs_spec.rb rename to test/integration/attributes/attrs_spec.rb index 0b2f144..b1e1427 100644 --- a/test/integration/default/serverspec/attrs_spec.rb +++ b/test/integration/attributes/attrs_spec.rb @@ -1,13 +1,11 @@ -require 'spec_helper' - -describe file('/proc/sys/net/ipv4/tcp_fin_timeout') do +describe file('/proc/sys/dev/cdrom/autoeject') do it { should be_file } - it { should contain '29' } + its('content') { should match /1/ } end describe file('/proc/sys/vm/swappiness') do it { should be_file } - it { should contain '19' } + its('content') { should match /19/ } end persistence_file = case os[:family].downcase @@ -23,6 +21,6 @@ describe file(persistence_file) do it { should be_file } - it { should contain 'vm.swappiness=19' } - it { should contain 'net.ipv4.tcp_fin_timeout=29' } + its('content') { should match /vm.swappiness=19/ } + its('content') { should match /dev.cdrom.autoeject=1/ } end diff --git a/test/integration/attributes/serverspec/spec_helper.rb b/test/integration/attributes/serverspec/spec_helper.rb deleted file mode 100644 index 37af1b4..0000000 --- a/test/integration/attributes/serverspec/spec_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'serverspec' - -set :backend, :exec diff --git a/test/integration/attributes/serverspec/attrs_spec.rb b/test/integration/default/attrs_spec.rb similarity index 70% rename from test/integration/attributes/serverspec/attrs_spec.rb rename to test/integration/default/attrs_spec.rb index 0b2f144..b1e1427 100644 --- a/test/integration/attributes/serverspec/attrs_spec.rb +++ b/test/integration/default/attrs_spec.rb @@ -1,13 +1,11 @@ -require 'spec_helper' - -describe file('/proc/sys/net/ipv4/tcp_fin_timeout') do +describe file('/proc/sys/dev/cdrom/autoeject') do it { should be_file } - it { should contain '29' } + its('content') { should match /1/ } end describe file('/proc/sys/vm/swappiness') do it { should be_file } - it { should contain '19' } + its('content') { should match /19/ } end persistence_file = case os[:family].downcase @@ -23,6 +21,6 @@ describe file(persistence_file) do it { should be_file } - it { should contain 'vm.swappiness=19' } - it { should contain 'net.ipv4.tcp_fin_timeout=29' } + its('content') { should match /vm.swappiness=19/ } + its('content') { should match /dev.cdrom.autoeject=1/ } end diff --git a/test/integration/lwrps/serverspec/lwrps_spec.rb b/test/integration/default/lwrps_spec.rb similarity index 53% rename from test/integration/lwrps/serverspec/lwrps_spec.rb rename to test/integration/default/lwrps_spec.rb index 99b8642..7487490 100644 --- a/test/integration/lwrps/serverspec/lwrps_spec.rb +++ b/test/integration/default/lwrps_spec.rb @@ -1,13 +1,6 @@ -require 'spec_helper' - -describe file('/proc/sys/net/ipv4/tcp_max_syn_backlog') do - it { should be_file } - it { should contain '12345' } -end - -describe file('/proc/sys/net/ipv4/tcp_rmem') do +describe file('/proc/sys/dev/cdrom/autoeject') do it { should be_file } - it { should contain '4096 16384 33554432' } + its('content') { should match /1/ } end persistence_file = case os[:family].downcase @@ -23,7 +16,6 @@ describe file(persistence_file) do it { should be_file } - it { should contain 'net.ipv4.tcp_max_syn_backlog=12345' } - it { should contain 'net.ipv4.tcp_rmem=4096 16384 33554432' } - it { should contain 'net.ipv4.tcp_wmem=1024 32768 33554432' } + its('content') { should match /dev.cdrom.autoeject=1/ } + its('content') { should match /vm.swappiness=19/ } end diff --git a/test/integration/default/serverspec/ohai_plugin_spec.rb b/test/integration/default/ohai_plugin_spec.rb similarity index 50% rename from test/integration/default/serverspec/ohai_plugin_spec.rb rename to test/integration/default/ohai_plugin_spec.rb index 861920d..3ee7545 100644 --- a/test/integration/default/serverspec/ohai_plugin_spec.rb +++ b/test/integration/default/ohai_plugin_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -describe command('ohai -d /tmp/kitchen/ohai/plugins sys') do +describe bash('/opt/chef/embedded/bin/ohai -d /opt/kitchen/ohai/plugins/ sys') do its(:exit_status) { should eq 0 } its(:stdout) { should match %r("net": {) } end diff --git a/test/integration/default/serverspec/spec_helper.rb b/test/integration/default/serverspec/spec_helper.rb deleted file mode 100644 index 37af1b4..0000000 --- a/test/integration/default/serverspec/spec_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'serverspec' - -set :backend, :exec diff --git a/test/integration/default/serverspec/lwrps_spec.rb b/test/integration/lwrps/lwrps_spec.rb similarity index 53% rename from test/integration/default/serverspec/lwrps_spec.rb rename to test/integration/lwrps/lwrps_spec.rb index 99b8642..7487490 100644 --- a/test/integration/default/serverspec/lwrps_spec.rb +++ b/test/integration/lwrps/lwrps_spec.rb @@ -1,13 +1,6 @@ -require 'spec_helper' - -describe file('/proc/sys/net/ipv4/tcp_max_syn_backlog') do - it { should be_file } - it { should contain '12345' } -end - -describe file('/proc/sys/net/ipv4/tcp_rmem') do +describe file('/proc/sys/dev/cdrom/autoeject') do it { should be_file } - it { should contain '4096 16384 33554432' } + its('content') { should match /1/ } end persistence_file = case os[:family].downcase @@ -23,7 +16,6 @@ describe file(persistence_file) do it { should be_file } - it { should contain 'net.ipv4.tcp_max_syn_backlog=12345' } - it { should contain 'net.ipv4.tcp_rmem=4096 16384 33554432' } - it { should contain 'net.ipv4.tcp_wmem=1024 32768 33554432' } + its('content') { should match /dev.cdrom.autoeject=1/ } + its('content') { should match /vm.swappiness=19/ } end diff --git a/test/integration/lwrps/serverspec/spec_helper.rb b/test/integration/lwrps/serverspec/spec_helper.rb deleted file mode 100644 index 37af1b4..0000000 --- a/test/integration/lwrps/serverspec/spec_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'serverspec' - -set :backend, :exec