diff --git a/.fixtures.yml b/.fixtures.yml index fb78f41..2a16a44 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,3 +1,7 @@ fixtures: forge_modules: stdlib: "puppetlabs/stdlib" + repositories: + facts: 'git://github.com/puppetlabs/puppetlabs-facts.git' + puppet_agent: 'git://github.com/puppetlabs/puppetlabs-puppet_agent.git' + provision: 'git://github.com/puppetlabs/provision.git' diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 0000000..4a0f488 --- /dev/null +++ b/provision.yaml @@ -0,0 +1,4 @@ +--- +default: + provisioner: docker + images: ['ubuntu:18.04', 'centos:7'] diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb deleted file mode 100644 index 0ef9c4c..0000000 --- a/spec/acceptance/class_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'munin and munin-node' do - context 'default parameters' do - # Using puppet_apply as a helper - it 'works idempotently with no errors' do - pp = <<-PUPPET_CODE - class { 'munin::master': } - class { 'munin::node': } - PUPPET_CODE - - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe package('munin') do - it { is_expected.to be_installed } - end - - describe package('munin-node') do - it { is_expected.to be_installed } - end - - describe service('munin-node') do - it { is_expected.to be_enabled } - it { is_expected.to be_running } - end - end -end diff --git a/spec/acceptance/master_spec.rb b/spec/acceptance/master_spec.rb new file mode 100644 index 0000000..d518cec --- /dev/null +++ b/spec/acceptance/master_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_acceptance' + +describe 'munin::master' do + let(:pp) do + <<-MANIFEST + include munin::master + munin::master::node_definition { 'localhost': + address => 'munin://localhost', + config => [ 'load.graph_future 30', + 'load.load.trend yes', + 'load.load.predict 86400,12' ], + } + MANIFEST + end + + it 'applies the manifest twice with no stderr' do + idempotent_apply(pp) + end + + describe package('munin') do + it { is_expected.to be_installed } + end +end diff --git a/spec/acceptance/munin__master_spec.rb b/spec/acceptance/munin__master_spec.rb deleted file mode 100644 index 082abf4..0000000 --- a/spec/acceptance/munin__master_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'munin::master class' do - context 'default parameters' do - # Using puppet_apply as a helper - it 'works idempotently with no errors' do - pp = <<-PUPPET_CODE - class { 'munin::master': } - PUPPET_CODE - - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe package('munin') do - it { is_expected.to be_installed } - end - end -end diff --git a/spec/acceptance/munin__node_spec.rb b/spec/acceptance/munin__node_spec.rb deleted file mode 100644 index 5cab9b2..0000000 --- a/spec/acceptance/munin__node_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'munin::node class' do - context 'default parameters' do - # Using puppet_apply as a helper - it 'works idempotently with no errors' do - pp = <<-PUPPET_CODE - class { 'munin::node': } - PUPPET_CODE - - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) - end - - describe package('munin-node') do - it { is_expected.to be_installed } - end - - describe service('munin-node') do - it { is_expected.to be_enabled } - it { is_expected.to be_running } - end - end -end diff --git a/spec/acceptance/node_spec.rb b/spec/acceptance/node_spec.rb new file mode 100644 index 0000000..e66be1e --- /dev/null +++ b/spec/acceptance/node_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper_acceptance' + +describe 'munin::node' do + let(:pp) do + <<-MANIFEST + include munin::node + munin::plugin { 'test_link': + ensure => link + } + MANIFEST + end + + it 'applies the manifest twice with no stderr' do + idempotent_apply(pp) + end + + describe package('munin-node') do + it { is_expected.to be_installed } + end + + describe service('munin-node') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe file('/etc/munin/plugins/test_link') do + it { is_expected.to be_symlink } + end +end diff --git a/spec/acceptance/nodesets/centos-511-x64.yml b/spec/acceptance/nodesets/centos-511-x64.yml deleted file mode 100644 index 155926d..0000000 --- a/spec/acceptance/nodesets/centos-511-x64.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - centos-511-x64: - roles: - - master - platform: el-5-x86_64 - box: puppetlabs/centos-5.11-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-5.11-64-nocm - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/centos-66-x64.yml b/spec/acceptance/nodesets/centos-66-x64.yml deleted file mode 100644 index 07843d5..0000000 --- a/spec/acceptance/nodesets/centos-66-x64.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - centos-66-x64: - roles: - - master - platform: el-6-x86_64 - box: puppetlabs/centos-6.6-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-6.6-64-nocm - hypervisor: vagrant -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml deleted file mode 100644 index 028a1b5..0000000 --- a/spec/acceptance/nodesets/centos-7-x64.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - centos-7-x64: - roles: - - master - platform: el-7-x86_64 - box: puppetlabs/centos-7.0-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-7.0-64-nocm - hypervisor: vagrant -CONFIG: - log_level: verbose - type: foss \ No newline at end of file diff --git a/spec/acceptance/nodesets/debian-609-x64.yml b/spec/acceptance/nodesets/debian-609-x64.yml deleted file mode 100644 index e2451ea..0000000 --- a/spec/acceptance/nodesets/debian-609-x64.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - debian-609-x64: - roles: - - master - platform: debian-6-amd64 - box: puppetlabs/debian-6.0.9-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/debian-6.0.9-64-nocm - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/debian-78-x64.yml b/spec/acceptance/nodesets/debian-78-x64.yml deleted file mode 100644 index c4062fd..0000000 --- a/spec/acceptance/nodesets/debian-78-x64.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - debian-78-x64: - roles: - - master - platform: debian-7-amd64 - box: puppetlabs/debian-7.8-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/debian-7.8-64-nocm - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/debian-8-x64.yml b/spec/acceptance/nodesets/debian-8-x64.yml deleted file mode 100644 index 845be5a..0000000 --- a/spec/acceptance/nodesets/debian-8-x64.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - debian-8-amd64: - roles: - - master - platform: debian-8-amd64 - box: debian/jessie64 - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 100644 index c4062fd..0000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - debian-78-x64: - roles: - - master - platform: debian-7-amd64 - box: puppetlabs/debian-7.8-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/debian-7.8-64-nocm - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/fedora-20-x64.yml b/spec/acceptance/nodesets/fedora-20-x64.yml deleted file mode 100644 index 138341f..0000000 --- a/spec/acceptance/nodesets/fedora-20-x64.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - fedora-20-x64: - roles: - - master - platform: el-7-x86_64 - box: chef/fedora-20 - box_url: https://vagrantcloud.com/chef/boxes/fedora-20 - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/nodesets/ubuntu-1204-x64.yml b/spec/acceptance/nodesets/ubuntu-1204-x64.yml deleted file mode 100644 index b4e7d55..0000000 --- a/spec/acceptance/nodesets/ubuntu-1204-x64.yml +++ /dev/null @@ -1,13 +0,0 @@ -HOSTS: - ubuntu-1204-x64: - roles: - - master - platform: ubuntu-1204-amd64 - box: puppetlabs/ubuntu-12.04-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-12.04-64-nocm - hypervisor: vagrant - -CONFIG: - log_level: verbose - color: false - type: foss diff --git a/spec/acceptance/nodesets/ubuntu-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-1404-x64.yml deleted file mode 100644 index edc1d12..0000000 --- a/spec/acceptance/nodesets/ubuntu-1404-x64.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - ubuntu-1404-x64: - roles: - - master - platform: ubuntu-1404-amd64 - box: puppetlabs/ubuntu-14.04-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 9740985..aabeb0b 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,22 +1,82 @@ -require 'beaker-rspec/spec_helper' -require 'beaker-rspec/helpers/serverspec' -require 'beaker/puppet_install_helper' +# frozen_string_literal: true -run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no' +require 'serverspec' +require 'puppet_litmus' +require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) +include PuppetLitmus -RSpec.configure do |c| - # Project root - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) +if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost' + puts 'Running tests against this machine !' + if Gem.win_platform? + set :backend, :cmd + else + set :backend, :exec + end +else + # load inventory + inventory_hash = inventory_hash_from_inventory_file + node_config = config_from_node(inventory_hash, ENV['TARGET_HOST']) + + if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes') + host = ENV['TARGET_HOST'] + set :backend, :docker + set :docker_container, host + elsif 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[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil? + options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil? + # Support both net-ssh 4 and 5. + # rubocop:disable Metrics/BlockNesting + options[:verify_host_key] = if node_config.dig('ssh', 'host-key-check').nil? + # Fall back to SSH behavior. This variable will only be set in net-ssh 5.3+. + if @strict_host_key_checking.nil? || @strict_host_key_checking + Net::SSH::Verifiers::Always.new + else + # SSH's behavior with StrictHostKeyChecking=no: adds new keys to known_hosts. + # If known_hosts points to /dev/null, then equivalent to :never where it + # accepts any key beacuse they're all new. + Net::SSH::Verifiers::AcceptNewOrLocalTunnel.new + end + elsif node_config.dig('ssh', 'host-key-check') + if defined?(Net::SSH::Verifiers::Always) + Net::SSH::Verifiers::Always.new + else + Net::SSH::Verifiers::Secure.new + end + elsif defined?(Net::SSH::Verifiers::Never) + Net::SSH::Verifiers::Never.new + else + Net::SSH::Verifiers::Null.new + end + # rubocop:enable Metrics/BlockNesting + host = if ENV['TARGET_HOST'].include?(':') + ENV['TARGET_HOST'].split(':').first + else + ENV['TARGET_HOST'] + end + set :host, options[:host_name] || host + set :ssh_options, options + set :request_pty, true + elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes') + require 'winrm' + + set :backend, :winrm + set :os, family: 'windows' + user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil? + pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil? + endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" - # Readable test descriptions - c.formatter = :documentation + opts = { + user: user, + password: pass, + endpoint: endpoint, + operation_timeout: 300, + } - # Configure all nodes in nodeset - c.before :suite do - # Install module and dependencies - puppet_module_install(source: proj_root, module_name: 'munin') - hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] - end + winrm = WinRM::Connection.new opts + Specinfra.configuration.winrm = winrm end end