Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to litmus acceptance testing #10

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
368ab71
Very rough initial conversion to litmus
pegasd Sep 8, 2019
a006aa6
Make acceptance and ed25519 groups optional in Gemfile
pegasd Sep 8, 2019
5f6d50c
Only require litmus if installed
pegasd Sep 8, 2019
ce739c5
RuboCop
pegasd Sep 8, 2019
698803b
Will this make it skip optional groups?
pegasd Sep 8, 2019
3b684e8
Change install script to exclude optional Gemfile groups
pegasd Sep 8, 2019
797aa32
Change install script to exclude optional Gemfile groups [fix]
pegasd Sep 8, 2019
08e4825
Require serverspec and only run on puppet 6
pegasd Sep 8, 2019
0bc36ae
Fix provisioning
pegasd Sep 8, 2019
335d9c4
Update before script
pegasd Sep 9, 2019
dc23b14
Try more puppet versions
pegasd Sep 9, 2019
216e335
Add .ruby-verison with Ruby 2.6.4
pegasd Sep 9, 2019
bdd0bdf
Add debugging
pegasd Sep 9, 2019
1b64b9f
Clean up bundle config
pegasd Sep 9, 2019
ff9ea09
Clean up bundle config :: 2
pegasd Sep 9, 2019
ccaa2b5
Remove optional: true from Gemfile. Does not work anyway.
pegasd Sep 9, 2019
681b683
Switch to Ruby 2.6.3
pegasd Sep 9, 2019
cc1e4c8
Update bundler on before_install
pegasd Sep 9, 2019
b680292
Check which versions of Ruby RVM has
pegasd Sep 9, 2019
e18685c
Drop ed25519 group for now
pegasd Sep 9, 2019
def9d4d
Switch to pre-installed Ruby version
pegasd Sep 9, 2019
cc5353a
Fix debugging
pegasd Sep 9, 2019
e1af272
Make acceptance optional again
pegasd Sep 9, 2019
ca17477
Dirty workaround for litmus and older Puppet versions
pegasd Sep 9, 2019
8cdc6c8
Add serverspec
pegasd Sep 9, 2019
660f63e
Run acceptance
pegasd Sep 9, 2019
bb6e384
Update spec_helper_acceptance.rb and switch to using built-in idempot…
pegasd Sep 17, 2019
8d9b105
Try suggested spec_helper_acceptance
pegasd Sep 22, 2019
5040ebd
Exclude spec_helper_acceptance from RuboCop
pegasd Sep 22, 2019
aeba87c
Revert spec_helper_acceptance and use waffle image
pegasd Sep 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ fixtures:
cron: "#{source_dir}"
repositories:
stdlib: https://github.com/puppetlabs/puppetlabs-stdlib
# Litmus
provision: git://github.com/puppetlabs/provision.git
puppet_agent: git://github.com/puppetlabs/puppetlabs-puppet_agent.git
facts: git://github.com/puppetlabs/puppetlabs-facts.git
forge_modules:
cron_core:
repo: puppetlabs/cron_core
Expand Down
8 changes: 4 additions & 4 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ spec/spec_helper.rb:

# deleted
.rspec:
unmanaged: true
delete: true
appveyor.yml:
unmanaged: true
delete: true
.gitlab-ci.yml:
unmanaged: true
delete: true
.vscode/extensions.json:
unmanaged: true
delete: true

# custom
.rubocop.yml:
Expand Down
36 changes: 12 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
# TODO This is for acceptance testing only
sudo: required
services: [ docker ]

before_install: rm Gemfile.lock || true
cache: bundler

language: ruby

cache: bundler
before_install:
- rm -f Gemfile.lock
- gem --version
- bundle --version
script: bundle exec rake $DO

jobs:
Expand All @@ -32,26 +34,12 @@ jobs:
- DO=spec
- PUPPET='~> 6'
- stage: acceptance
env:
- DO=beaker
- BEAKER_set=ubuntu_1404
- BEAKER_PUPPET_COLLECTION=puppet5
- env:
- DO=beaker
- BEAKER_set=ubuntu_1604
- BEAKER_PUPPET_COLLECTION=puppet5
- env:
- DO=beaker
- BEAKER_set=ubuntu_1604
- BEAKER_PUPPET_COLLECTION=puppet6
- env:
- DO=beaker
- BEAKER_set=ubuntu_1804
- BEAKER_PUPPET_COLLECTION=puppet5
- env:
- DO=beaker
- BEAKER_set=ubuntu_1804
- BEAKER_PUPPET_COLLECTION=puppet6
bundler_args: --with acceptance
script:
- bundle exec rake 'litmus:provision_list[default]'
- bundle exec rake 'litmus:install_agent'
- bundle exec rake 'litmus:install_module'
- bundle exec rake 'litmus:acceptance:parallel'
- stage: deploy
script: true
env:
Expand Down
15 changes: 6 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

source 'https://rubygems.org'

group :ed25519 do
group :acceptance, optional: true do
gem 'puppet_litmus' if ENV['PUPPET'] !~ /(4|5)$/
gem 'serverspec'
end

group :ed25519, optional: true do
gem 'bcrypt_pbkdf', '< 2.0'
gem 'rbnacl', '< 5.0'
gem 'rbnacl-libsodium'
end

group :acceptance do
gem 'beaker-docker'
gem 'beaker-module_install_helper'
gem 'beaker-puppet'
gem 'beaker-puppet_install_helper'
gem 'beaker-rspec'
end

group :documentation do
gem 'puppet-strings'
gem 'rgen'
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require 'metadata-json-lint/rake_task'
require 'puppet-strings/tasks'
require 'rubocop/rake_task'
require 'yamllint/rake_task'
require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any?

PuppetLint.configuration.relative = true
PuppetLint.configuration.ignore_paths = ['spec/fixtures/**/*.pp', 'spec/_fixtures/**/*.pp']
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"version_requirement": ">= 4.4.0 < 7.0.0"
}
],
"pdk-version": "1.12.0",
"pdk-version": "1.13.0",
"template-url": "https://github.com/puppetlabs/pdk-templates#master",
"template-ref": "1.12.0-0-g55d9ae2"
"template-ref": "1.13.0-0-g66e1443"
}
5 changes: 5 additions & 0 deletions provision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default:
provisioner: docker
images: [ 'waffleimage/ubuntu18.04' ]
...
4 changes: 2 additions & 2 deletions spec/acceptance/cron_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

PUPPET

apply_and_test_idempotence(pp)
idempotent_apply(pp)

describe cron do
it { is_expected.to have_entry '* * * * * echo hi > /tmp/say_hi' }
Expand Down Expand Up @@ -44,7 +44,7 @@

PUPPET

apply_and_test_idempotence(pp)
idempotent_apply(pp)

describe file('/tmp/say_hi') do
it { is_expected.not_to exist }
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/install_remove_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

PUPPET

apply_and_test_idempotence(pp)
idempotent_apply(pp)

describe package('cron') do
it { is_expected.to be_installed }
Expand Down Expand Up @@ -44,7 +44,7 @@ class { 'cron':

PUPPET

apply_and_test_idempotence(pp)
idempotent_apply(pp)

describe package('cron') do
it { is_expected.not_to be_installed }
Expand Down
16 changes: 0 additions & 16 deletions spec/acceptance/nodesets/default.yml

This file was deleted.

16 changes: 0 additions & 16 deletions spec/acceptance/nodesets/ubuntu_1404.yml

This file was deleted.

13 changes: 0 additions & 13 deletions spec/acceptance/nodesets/ubuntu_1604.yml

This file was deleted.

13 changes: 0 additions & 13 deletions spec/acceptance/nodesets/ubuntu_1804.yml

This file was deleted.

4 changes: 2 additions & 2 deletions spec/acceptance/purge_cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

PUPPET

apply_and_test_idempotence(pp)
idempotent_apply(pp)

describe cron do
it { is_expected.to have_entry '* * * * * /usr/bin/backup' }
Expand All @@ -45,7 +45,7 @@

PUPPET

apply_and_test_idempotence(pp)
idempotent_apply(pp)

describe cron do
it { is_expected.to have_entry '* * * * * /usr/bin/backup' }
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/regular_user_crontab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

PUPPET

apply_and_test_idempotence pp
idempotent_apply pp

describe command('sudo -u luke env EDITOR=cat crontab -e') do
its(:exit_status) { is_expected.to eq 1 }
Expand All @@ -31,7 +31,7 @@ class { 'cron':

PUPPET

apply_and_test_idempotence pp
idempotent_apply pp

describe command('sudo -u luke env EDITOR=cat crontab -e') do
its(:exit_status) { is_expected.to eq 0 }
Expand All @@ -47,7 +47,7 @@ class { 'cron':

PUPPET

apply_and_test_idempotence pp
idempotent_apply pp

describe user('luke') do
it { is_expected.not_to exist }
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/whitelist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class { 'cron':
PUPPET

context 'whitelist a cron job in /etc/cron.d' do
apply_and_test_idempotence(pp)
idempotent_apply(pp)
end

context 'fake a cron job and see that it is not purged' do
Expand Down
42 changes: 20 additions & 22 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
# frozen_string_literal: true

require 'beaker-rspec'
require 'beaker-puppet'
require 'beaker/puppet_install_helper'
require 'beaker/module_install_helper'

run_puppet_install_helper
install_module_on(hosts)
install_module_dependencies_on(hosts)
require 'serverspec'
require 'puppet_litmus'
include PuppetLitmus # rubocop:disable Style/MixinUsage

RSpec.configure do |c|
c.color = true
c.formatter = :documentation
end

# This runs the supplied manifest twice on the host.
#
# First time checking for failures.
# Second time checking for changes.
#
# Idempotent and clean. Just the way I like it.
def apply_and_test_idempotence(manifest)
context 'applying manifest and testing for idempotence' do
it 'does not fail the first time around' do
apply_manifest(manifest, catch_failures: true)
end
if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
puts 'Running tests against this machine !'
set :backend, :exec
else
inventory_hash = inventory_hash_from_inventory_file
node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])

it 'does not change anything on the second run' do
apply_manifest(manifest, catch_changes: true)
end
if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
set :backend, :ssh
options = Net::SSH::Config.for(host)
options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
options[:verify_host_key] = Net::SSH::Verifiers::Always.new unless node_config.dig('ssh', 'host-key-check').nil?
host = ENV['TARGET_HOST'].split(':').first
set :host, options[:host_name] || host
set :ssh_options, options
set :request_pty, true
end
end