From ba1f346b198056fb06ae202993828ec981d2b5a1 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 26 Aug 2019 11:42:29 +0200 Subject: [PATCH] ci(kitchen+travis): test with latest Docker images --- .kitchen.yml | 53 ------ .travis.yml | 48 ++++-- Gemfile | 12 +- bin/kitchen | 29 ++++ kitchen.yml | 151 ++++++++++++++++++ test/integration/default/README.md | 50 ++++++ .../default/controls/config_spec.rb | 17 ++ .../default/controls/package_spec.rb | 15 ++ test/integration/default/inspec.yml | 15 ++ test/integration/vim/controls/vim.rb | 16 -- test/integration/vim/inspec.yml | 10 -- test/salt/pillar/vim.sls | 7 + 12 files changed, 328 insertions(+), 95 deletions(-) delete mode 100644 .kitchen.yml create mode 100755 bin/kitchen create mode 100644 kitchen.yml create mode 100644 test/integration/default/README.md create mode 100644 test/integration/default/controls/config_spec.rb create mode 100644 test/integration/default/controls/package_spec.rb create mode 100644 test/integration/default/inspec.yml delete mode 100644 test/integration/vim/controls/vim.rb delete mode 100644 test/integration/vim/inspec.yml create mode 100644 test/salt/pillar/vim.sls diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index 83998ba..0000000 --- a/.kitchen.yml +++ /dev/null @@ -1,53 +0,0 @@ -<% -distrib, infos = ENV.fetch('DISTRIB', 'debian:stretch/9').split(':') -codename, version = infos.split('/') -%> ---- -driver: - name: docker - use_sudo: false - -provisioner: - name: salt_solo - formula: vim - - # Install Salt from official repositories - salt_install: apt - salt_version: latest - salt_apt_repo: https://repo.saltstack.com/apt/<%= distrib %>/<%= version %>/amd64 - salt_apt_repo_key: https://repo.saltstack.com/apt/<%= distrib %>/<%= version %>/amd64/latest/SALTSTACK-GPG-KEY.pub - - # Don't install Chef - require_chef: false - - # Configure Salt - state_top: - base: - '*': - - vim - - pillars: - top.sls: - base: - '*': - - vim - vim.sls: - vim: - managed_vimrc: true - config: - syntax: 'on' - settings: - number: - -platforms: - - name: <%= distrib %>-<%= codename %> - driver_config: - image: "<%= distrib %>:<%= codename %>" - platform: <%= distrib %> - -verifier: - name: inspec - format: progress - -suites: - - name: vim diff --git a/.travis.yml b/.travis.yml index c817be2..f6ebb6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,45 @@ -language: ruby +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +stages: + - test + sudo: required cache: bundler -rvm: - - 2.3.5 +language: ruby +dist: xenial + services: - docker -script: - - bundle exec kitchen test + +# Make sure the instances listed below match up with +# the `platforms` defined in `kitchen.yml` env: matrix: - - DISTRIB=debian:wheezy/7 - - DISTRIB=debian:jessie/8 - - DISTRIB=debian:stretch/9 - - DISTRIB=ubuntu:xenial/16.04 + - INSTANCE: default-debian-10-develop-py3 + # - INSTANCE: default-ubuntu-1804-develop-py3 + # - INSTANCE: default-centos-7-develop-py3 + # - INSTANCE: default-fedora-30-develop-py3 + # - INSTANCE: default-opensuse-leap-15-develop-py3 + # - INSTANCE: default-amazonlinux-2-develop-py2 + # - INSTANCE: default-debian-9-2019-2-py3 + - INSTANCE: default-ubuntu-1804-2019-2-py3 + # - INSTANCE: default-centos-7-2019-2-py3 + # - INSTANCE: default-fedora-30-2019-2-py3 + # - INSTANCE: default-opensuse-leap-15-2019-2-py3 + - INSTANCE: default-amazonlinux-2-2019-2-py2 + # - INSTANCE: default-debian-9-2018-3-py2 + # - INSTANCE: default-ubuntu-1604-2018-3-py2 + # - INSTANCE: default-centos-7-2018-3-py2 + - INSTANCE: default-fedora-29-2018-3-py2 + - INSTANCE: default-opensuse-leap-15-2018-3-py2 + # - INSTANCE: default-amazonlinux-2-2018-3-py2 + # - INSTANCE: default-debian-8-2017-7-py2 + # - INSTANCE: default-ubuntu-1604-2017-7-py2 + - INSTANCE: default-centos-6-2017-7-py2 + # - INSTANCE: default-fedora-29-2017-7-py2 + # - INSTANCE: default-opensuse-leap-15-2017-7-py2 + # - INSTANCE: default-amazonlinux-2-2017-7-py2 + +script: + - bin/kitchen verify ${INSTANCE} diff --git a/Gemfile b/Gemfile index 9f6cc6e..3b36de3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,6 @@ -source 'https://rubygems.org' -ruby '2.3.5' +source "https://rubygems.org" + +gem 'kitchen-docker', '>= 2.9' +gem 'kitchen-salt', '>= 0.6.0' +gem 'kitchen-inspec', '>= 1.1' -gem 'test-kitchen' -gem 'kitchen-docker' -gem 'kitchen-salt' -gem 'kitchen-inspec' -gem 'rake' diff --git a/bin/kitchen b/bin/kitchen new file mode 100755 index 0000000..1cd44f3 --- /dev/null +++ b/bin/kitchen @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'kitchen' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("test-kitchen", "kitchen") diff --git a/kitchen.yml b/kitchen.yml new file mode 100644 index 0000000..7308ece --- /dev/null +++ b/kitchen.yml @@ -0,0 +1,151 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# For help on this file's format, see https://kitchen.ci/ +driver: + name: docker + use_sudo: false + privileged: true + run_command: /lib/systemd/systemd + +# Make sure the platforms listed below match up with +# the `env.matrix` instances defined in `.travis.yml` +platforms: + ## SALT `develop` + - name: debian-10-develop-py3 + driver: + image: netmanagers/salt-develop-py3:debian-10 + provision_command: + - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + - sh bootstrap-salt.sh -XdPbfrq -x python3 git develop + - name: ubuntu-1804-develop-py3 + driver: + image: netmanagers/salt-develop-py3:ubuntu-18.04 + provision_command: + - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + - sh bootstrap-salt.sh -XdPbfrq -x python3 git develop + - name: centos-7-develop-py3 + driver: + image: netmanagers/salt-develop-py3:centos-7 + provision_command: + - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + - sh bootstrap-salt.sh -XdPbfrq -x python3 git develop + - name: fedora-30-develop-py3 + driver: + image: netmanagers/salt-develop-py3:fedora-30 + provision_command: + - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + - sh bootstrap-salt.sh -XdPbfrq -x python3 git develop + - name: opensuse-leap-15-develop-py3 + driver: + image: netmanagers/salt-develop-py3:opensuse-leap-15 + provision_command: + - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + - sh bootstrap-salt.sh -XdPbfrq -x python3 git develop + run_command: /usr/lib/systemd/systemd + - name: amazonlinux-2-develop-py2 + driver: + image: netmanagers/salt-develop-py2:amazonlinux-2 + provision_command: + - curl -o bootstrap-salt.sh -L https://bootstrap.saltstack.com + - sh bootstrap-salt.sh -XdPbfrq -x python2 git develop + + ## SALT `2019.2` + - name: debian-9-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:debian-9 + - name: ubuntu-1804-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:ubuntu-18.04 + - name: centos-7-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:centos-7 + - name: fedora-30-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:fedora-30 + - name: opensuse-leap-15-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:opensuse-leap-15 + run_command: /usr/lib/systemd/systemd + - name: amazonlinux-2-2019-2-py2 + driver: + image: netmanagers/salt-2019.2-py2:amazonlinux-2 + + ## SALT `2018.3` + - name: debian-9-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:debian-9 + - name: ubuntu-1604-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:ubuntu-16.04 + - name: centos-7-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:centos-7 + - name: fedora-29-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:fedora-29 + - name: opensuse-leap-15-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:opensuse-leap-15 + run_command: /usr/lib/systemd/systemd + - name: amazonlinux-2-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:amazonlinux-2 + + ## SALT `2017.7` + - name: debian-8-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:debian-8 + - name: ubuntu-1604-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:ubuntu-16.04 + - name: centos-6-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:centos-6 + run_command: /sbin/init + - name: fedora-29-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:fedora-29 + - name: opensuse-leap-15-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:opensuse-leap-15 + run_command: /usr/lib/systemd/systemd + - name: amazonlinux-2-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:amazonlinux-2 + +provisioner: + name: salt_solo + log_level: info + salt_install: none + require_chef: false + formula: vim + salt_copy_filter: + - .kitchen + - .git + +verifier: + # https://www.inspec.io/ + name: inspec + sudo: true + # cli, documentation, html, progress, json, json-min, json-rspec, junit + reporter: + - cli + +suites: + - name: default + provisioner: + state_top: + base: + '*': + - vim + pillars: + top.sls: + base: + '*': + - vim + pillars_from_files: + vim.sls: test/salt/pillar/vim.sls + verifier: + inspec_tests: + - path: test/integration/default diff --git a/test/integration/default/README.md b/test/integration/default/README.md new file mode 100644 index 0000000..37cf963 --- /dev/null +++ b/test/integration/default/README.md @@ -0,0 +1,50 @@ +# InSpec Profile: `default` + +This shows the implementation of the `default` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md). + +## Verify a profile + +InSpec ships with built-in features to verify a profile structure. + +```bash +$ inspec check default +Summary +------- +Location: default +Profile: profile +Controls: 4 +Timestamp: 2019-06-24T23:09:01+00:00 +Valid: true + +Errors +------ + +Warnings +-------- +``` + +## Execute a profile + +To run all **supported** controls on a local machine use `inspec exec /path/to/profile`. + +```bash +$ inspec exec default +.. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +8 examples, 0 failures +``` + +## Execute a specific control from a profile + +To run one control from the profile use `inspec exec /path/to/profile --controls name`. + +```bash +$ inspec exec default --controls package +. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +1 examples, 0 failures +``` + +See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb). diff --git a/test/integration/default/controls/config_spec.rb b/test/integration/default/controls/config_spec.rb new file mode 100644 index 0000000..fe356cf --- /dev/null +++ b/test/integration/default/controls/config_spec.rb @@ -0,0 +1,17 @@ +control 'Vim configuration' do + title 'should match desired lines' + + config_file = + case os[:family] + when 'debian' + '/etc/vim/vimrc' + else + '/etc/vimrc' + end + + describe file(config_file) do + # Custom config from pillar + its('content') { should include 'syntax on' } + its('content') { should include 'set number' } + end +end diff --git a/test/integration/default/controls/package_spec.rb b/test/integration/default/controls/package_spec.rb new file mode 100644 index 0000000..96361d8 --- /dev/null +++ b/test/integration/default/controls/package_spec.rb @@ -0,0 +1,15 @@ +control 'Vim package' do + title 'should be installed' + + package_name = + case os[:family] + when 'debian', 'suse' + 'vim' + else + 'vim-enhanced' + end + + describe package(package_name) do + it { should be_installed } + end +end diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml new file mode 100644 index 0000000..ab62277 --- /dev/null +++ b/test/integration/default/inspec.yml @@ -0,0 +1,15 @@ +--- +name: default +title: vim formula +maintainer: SaltStack Formulas +license: Apache-2.0 +summary: Verify that the vim formula is setup and configured correctly +supports: + - platform-name: debian + - platform-name: ubuntu + - platform-name: centos + - platform-name: fedora + - platform-name: opensuse + - platform-name: suse + - platform-name: freebsd + - platform-name: amazon diff --git a/test/integration/vim/controls/vim.rb b/test/integration/vim/controls/vim.rb deleted file mode 100644 index 0699219..0000000 --- a/test/integration/vim/controls/vim.rb +++ /dev/null @@ -1,16 +0,0 @@ -# encoding: utf-8 - -title 'Test Vim installation' - -describe package('vim') do - it { should be_installed } -end - -describe file('/etc/vim/vimrc') do - # Default config - its('content') { should include 'runtime! debian.vim' } - - # Custom config from pillar - its('content') { should include 'syntax on' } - its('content') { should include 'set number' } -end diff --git a/test/integration/vim/inspec.yml b/test/integration/vim/inspec.yml deleted file mode 100644 index eabc246..0000000 --- a/test/integration/vim/inspec.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: vim -title: Vim Profile -maintainer: Nicolas Rodriguez -copyright: Nicolas Rodriguez -copyright_email: nicoladmin@free.fr -license: MIT -summary: Vim Compliance Profile -version: 0.1.0 -supports: -- os-name: debian diff --git a/test/salt/pillar/vim.sls b/test/salt/pillar/vim.sls new file mode 100644 index 0000000..23355ee --- /dev/null +++ b/test/salt/pillar/vim.sls @@ -0,0 +1,7 @@ +--- +vim: + managed_vimrc: true + config: + syntax: 'on' + settings: + number: