From 648c488172f570597b8c08a7a5e2e3856fe2739b Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 7 Sep 2016 21:55:32 -0700 Subject: [PATCH] Testing updates Signed-off-by: Tim Smith --- .gitignore | 5 +- .kitchen.docker.yml | 103 +++++++++++++----- .kitchen.yml | 18 +-- .rubocop.yml | 34 ------ .travis.yml | 37 ++++--- Berksfile | 1 - Gemfile | 32 ++---- MAINTAINERS.md | 4 +- MAINTAINERS.toml | 4 +- Rakefile | 72 ++++++++---- tasks/maintainers.rb | 4 +- test/fixtures/cookbooks/fake/metadata.rb | 3 - .../fixtures/cookbooks/fake/recipes/omnios.rb | 5 - 13 files changed, 172 insertions(+), 150 deletions(-) delete mode 100644 .rubocop.yml delete mode 100644 test/fixtures/cookbooks/fake/metadata.rb delete mode 100644 test/fixtures/cookbooks/fake/recipes/omnios.rb diff --git a/.gitignore b/.gitignore index ac3eac0..6c97e28 100644 --- a/.gitignore +++ b/.gitignore @@ -34,15 +34,16 @@ _yardoc doc/ .idea -#chef stuff +# chef stuff Berksfile.lock .kitchen .kitchen.local.yml vendor/ .coverage/ .zero-knife.rb +Policyfile.lock.json -#vagrant stuff +# vagrant stuff .vagrant/ .vagrant.d/ .kitchen/ diff --git a/.kitchen.docker.yml b/.kitchen.docker.yml index 098ead2..b2eebdd 100644 --- a/.kitchen.docker.yml +++ b/.kitchen.docker.yml @@ -1,51 +1,100 @@ -settings: - parallel: true - driver: - name: docker - # privileged is required otherwise the container doesn't boot right - privileged: true + name: dokken + chef_version: latest + privileged: true # because Docker and SystemD/Upstart + +transport: + name: dokken + +provisioner: + name: dokken + +verifier: + root_path: '/opt/verifier' + sudo: false 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 lsb-release procps -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 lsb-release -y + - name: centos-5 driver: image: centos:5 platform: rhel - run_command: /sbin/init - provision_command: - - /usr/bin/yum install -y initscripts net-tools wget + pid_one_command: /sbin/init + intermediate_instructions: + - RUN yum install -y which initscripts + - name: centos-6 driver: image: centos:6 platform: rhel - run_command: /sbin/init - provision_command: - - /usr/bin/yum install -y initscripts net-tools wget + pid_one_command: /sbin/init + intermediate_instructions: + - RUN yum -y install which initscripts + - name: centos-7 driver: image: centos:7 platform: rhel - run_command: /usr/lib/systemd/systemd - provision_command: - - /bin/yum install -y initscripts net-tools wget + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN yum -y install lsof which systemd-sysv initscripts + +- name: fedora-latest + driver: + image: fedora:latest + pid_one_command: /usr/lib/systemd/systemd + intermediate_instructions: + - RUN dnf -y install yum which systemd-sysv initscripts + - name: ubuntu-12.04 driver: image: ubuntu-upstart:12.04 - platform: ubuntu - disable_upstart: false - run_command: /sbin/init - provision_command: - - /usr/bin/apt-get update - - /usr/bin/apt-get install apt-transport-https net-tools -y + pid_one_command: /sbin/init + intermediate_instructions: + - RUN /usr/bin/apt-get update + - name: ubuntu-14.04 driver: image: ubuntu-upstart:14.04 - platform: ubuntu - disable_upstart: false - run_command: /sbin/init - provision_command: - - /usr/bin/apt-get update - - /usr/bin/apt-get install apt-transport-https net-tools -y + pid_one_command: /sbin/init + intermediate_instructions: + - RUN /usr/bin/apt-get update + +- name: ubuntu-16.04 + driver: + image: ubuntu:16.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + +- name: opensuse-13.2 + driver: + image: opensuse:13.2 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN zypper --non-interactive install aaa_base perl-Getopt-Long-Descriptive which net-tools + +- name: opensuse-42.1 + driver: + image: opensuse:42.1 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN zypper --non-interactive install aaa_base perl-Getopt-Long-Descriptive which hostname suites: - name: default diff --git a/.kitchen.yml b/.kitchen.yml index e4773a9..416949d 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -6,26 +6,20 @@ provisioner: platforms: - name: centos-5.11 - - name: centos-6.7 + - name: centos-6.8 - name: centos-7.2 - - name: debian-7.10 + - name: debian-7.11 run_list: apt::default - - name: debian-8.4 + - name: debian-8.5 run_list: apt::default - - name: fedora-22 - run_list: yum::dnf_yum_compat - - name: fedora-23 + - name: fedora-24 run_list: yum::dnf_yum_compat - name: ubuntu-12.04 run_list: apt::default - name: ubuntu-14.04 run_list: apt::default - - name: omnios-r151014 - driver: - box: omnios-r151014 - box_url: http://omnios.omniti.com/media/omnios-r151014.box - run_list: - - recipe[fake::omnios] + - name: ubuntu-16.04 + run_list: apt::default suites: - name: default diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 7b24da2..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,34 +0,0 @@ -AllCops: - Exclude: - - vendor/**/* - - Guardfile - - test/**/* - -AlignParameters: - Enabled: false -ClassLength: - Enabled: false -CyclomaticComplexity: - Enabled: false -Documentation: - Enabled: false -Encoding: - Enabled: false -Style/FileName: - Enabled: false -Style/Alias: - Enabled: false -Style/SpaceBeforeFirstArg: - Enabled: false -LineLength: - Enabled: false -MethodLength: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/ModuleLength: - Enabled: false -PerceivedComplexity: - Enabled: false -Style/ClassAndModuleChildren: - Enabled: false diff --git a/.travis.yml b/.travis.yml index 5488293..4f45072 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,34 +5,41 @@ dist: trusty addons: apt: sources: - - chef-current-precise + - chef-current-trusty packages: - chefdk +# Don't `bundle install` which takes about 1.5 mins +install: echo "skip bundle install" + +branches: + only: + - master + services: docker env: matrix: - INSTANCE=default-ubuntu-1204 - INSTANCE=default-ubuntu-1404 + - INSTANCE=default-ubuntu-1604 - INSTANCE=default-centos-5 - INSTANCE=default-centos-6 - INSTANCE=default-centos-7 -# Don't `bundle install` -install: echo "skip bundle install" - -# Ensure we make ChefDK's Ruby the default before_script: - # https://github.com/zuazo/kitchen-in-travis-native/issues/1#issuecomment-142230889 - 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 gem install kitchen-docker -script: - - /opt/chefdk/embedded/bin/chef --version - - /opt/chefdk/embedded/bin/rubocop --version - - /opt/chefdk/embedded/bin/rubocop - - /opt/chefdk/embedded/bin/foodcritic --version - - /opt/chefdk/embedded/bin/foodcritic . --exclude spec -f any - - /opt/chefdk/embedded/bin/rspec - - KITCHEN_LOCAL_YAML=.kitchen.docker.yml /opt/chefdk/embedded/bin/kitchen verify ${INSTANCE} + +script: KITCHEN_LOCAL_YAML=.kitchen.docker.yml /opt/chefdk/embedded/bin/kitchen verify ${INSTANCE} + +matrix: + include: + - before_script: + - 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 + - script: + - /opt/chefdk/bin/chef exec rake + env: UNIT_AND_LINT=1 diff --git a/Berksfile b/Berksfile index 67c4024..ce6a658 100644 --- a/Berksfile +++ b/Berksfile @@ -5,6 +5,5 @@ metadata group :integration do cookbook 'yum' cookbook 'apt' - cookbook 'fake', path: 'test/fixtures/cookbooks/fake' cookbook 'wrapper', path: 'test/fixtures/cookbooks/wrapper' end diff --git a/Gemfile b/Gemfile index f2ab086..d914365 100644 --- a/Gemfile +++ b/Gemfile @@ -1,24 +1,12 @@ +# This gemfile provides additional gems for testing and releasing this cookbook +# It is meant to be installed on top of ChefDK which provides the majority +# of the necessary gems for testing this cookbook +# +# Run 'chef exec bundle install' to install these dependencies + source 'https://rubygems.org' -group :rake do - gem 'rake' - gem 'tomlrb' -end - -group :lint do - gem 'foodcritic', '~> 6.0' - gem 'rubocop', '~> 0.38' -end - -group :unit do - gem 'berkshelf', '~> 4.3' - gem 'chefspec', '~> 4.6' -end - -group :kitchen_common do - gem 'test-kitchen', '~> 1.6' -end - -group :kitchen_vagrant do - gem 'kitchen-vagrant', '~> 0.19' -end +gem 'tomlrb' +gem 'rake' +gem 'stove' +gem 'community_cookbook_releaser' diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 00eed8d..c8f99e2 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -2,8 +2,8 @@ # Maintainers This file lists how this cookbook project is maintained. When making changes to the system, this -file tells you who needs to review your patch - you need a simple majority of maintainers -for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need +file tells you who needs to review your patch - you need a review from an existing maintainer +for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead. Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) diff --git a/MAINTAINERS.toml b/MAINTAINERS.toml index d378766..e56145b 100644 --- a/MAINTAINERS.toml +++ b/MAINTAINERS.toml @@ -6,8 +6,8 @@ title = "Maintainers" text = """ This file lists how this cookbook project is maintained. When making changes to the system, this -file tells you who needs to review your patch - you need a simple majority of maintainers -for the relevant subsystems to provide a :+1: on your pull request. Additionally, you need +file tells you who needs to review your patch - you need a review from an existing maintainer +for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead. Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) diff --git a/Rakefile b/Rakefile index e3ef8ea..293ccde 100644 --- a/Rakefile +++ b/Rakefile @@ -1,43 +1,69 @@ -require 'rspec/core/rake_task' -require 'rubocop/rake_task' -require 'foodcritic' -require 'kitchen' +#!/usr/bin/env rake require_relative 'tasks/maintainers' -# Style tests. Rubocop and Foodcritic +# Style tests. cookstyle (rubocop) and Foodcritic namespace :style do - desc 'Run Ruby style checks' - RuboCop::RakeTask.new(:ruby) + begin + require 'cookstyle' + require 'rubocop/rake_task' - desc 'Run Chef style checks' - FoodCritic::Rake::LintTask.new(:chef) do |t| - t.options = { - fail_tags: ['any'] - } + desc 'Run Ruby style checks' + RuboCop::RakeTask.new(:ruby) + rescue LoadError => e + puts ">>> Gem load error: #{e}, omitting style:ruby" 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 + puts ">>> Gem load error: #{e}, omitting style:chef" unless ENV['CI'] end end desc 'Run all style checks' task style: ['style:chef', 'style:ruby'] -# Rspec and ChefSpec -desc 'Run ChefSpec examples' -RSpec::Core::RakeTask.new(:spec) +# ChefSpec +begin + require 'rspec/core/rake_task' + + desc 'Run ChefSpec examples' + RSpec::Core::RakeTask.new(:spec) +rescue LoadError => e + puts ">>> Gem load error: #{e}, omitting spec" 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 ">>> Kitchen error: #{e}, omitting #{task.name}" unless ENV['CI'] end end -desc 'Run all tests on Travis' -task travis: ['style', 'spec', 'integration:cloud'] +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) diff --git a/tasks/maintainers.rb b/tasks/maintainers.rb index 7e99633..1ce3302 100644 --- a/tasks/maintainers.rb +++ b/tasks/maintainers.rb @@ -1,5 +1,5 @@ # -# Copyright:: Copyright (c) 2015 Chef Software, Inc. +# Copyright:: Copyright (c) 2015-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,7 +41,7 @@ begin end rescue LoadError - STDERR.puts "\n*** TomlRb not available.\n\n" + STDERR.puts "\n*** TomlRb not available. Skipping the Maintainers Rake task\n\n" end private diff --git a/test/fixtures/cookbooks/fake/metadata.rb b/test/fixtures/cookbooks/fake/metadata.rb deleted file mode 100644 index 9ded389..0000000 --- a/test/fixtures/cookbooks/fake/metadata.rb +++ /dev/null @@ -1,3 +0,0 @@ -name 'fake' -version '0.0.1' -description 'Not a real cookbook, used for testing only.' diff --git a/test/fixtures/cookbooks/fake/recipes/omnios.rb b/test/fixtures/cookbooks/fake/recipes/omnios.rb deleted file mode 100644 index 006c5f6..0000000 --- a/test/fixtures/cookbooks/fake/recipes/omnios.rb +++ /dev/null @@ -1,5 +0,0 @@ -execute 'pkg set-publisher -g http://pkg.omniti.com/omniti-ms/ ms.omniti.com' do - not_if 'pkg publisher ms.omniti.com' -end - -execute 'pkg refresh --full'