From d03e584cb5ffd90e85b1435c92a727d2175b9e5c Mon Sep 17 00:00:00 2001 From: tphoney Date: Mon, 22 Jul 2019 11:17:06 +0100 Subject: [PATCH] (FM-8220) convert to use litmus --- .fixtures.yml | 3 + .sync.yml | 36 ++-- .travis.yml | 56 +++++- Gemfile | 6 +- distelli-manifest.yml | 25 +++ metadata.json | 3 +- provision.yaml | 13 ++ spec/acceptance/basic_spec.rb | 12 +- spec/acceptance/defaults_spec.rb | 8 +- spec/acceptance/frontbackend_spec.rb | 12 +- spec/acceptance/listen_spec.rb | 14 +- spec/acceptance/nodesets/centos-7-x64.yml | 10 - spec/acceptance/nodesets/debian-8-x64.yml | 10 - spec/acceptance/nodesets/default.yml | 18 -- spec/acceptance/nodesets/docker/centos-7.yml | 12 -- spec/acceptance/nodesets/docker/debian-8.yml | 11 -- .../nodesets/docker/ubuntu-14.04.yml | 12 -- spec/acceptance/userlist_spec.rb | 12 +- spec/spec_helper.rb | 5 + spec/spec_helper_acceptance.rb | 174 ++++++------------ spec/spec_helper_acceptance_local.rb | 49 +++++ spec/support/script-5556.sh | 3 + spec/support/script-5557.sh | 3 + 23 files changed, 251 insertions(+), 256 deletions(-) create mode 100644 distelli-manifest.yml create mode 100644 provision.yaml delete mode 100644 spec/acceptance/nodesets/centos-7-x64.yml delete mode 100644 spec/acceptance/nodesets/debian-8-x64.yml delete mode 100644 spec/acceptance/nodesets/default.yml delete mode 100644 spec/acceptance/nodesets/docker/centos-7.yml delete mode 100644 spec/acceptance/nodesets/docker/debian-8.yml delete mode 100644 spec/acceptance/nodesets/docker/ubuntu-14.04.yml create mode 100644 spec/spec_helper_acceptance_local.rb create mode 100644 spec/support/script-5556.sh create mode 100644 spec/support/script-5557.sh diff --git a/.fixtures.yml b/.fixtures.yml index 12652019..2e56af3e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -4,5 +4,8 @@ fixtures: repo: "git://github.com/puppetlabs/puppetlabs-concat.git" stdlib: repo: "git://github.com/puppetlabs/puppetlabs-stdlib.git" + 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' symlinks: haproxy: "#{source_dir}" diff --git a/.sync.yml b/.sync.yml index 2ec49852..9e6a50d9 100644 --- a/.sync.yml +++ b/.sync.yml @@ -3,6 +3,9 @@ required: - ---.project +.gitlab-ci.yml: + unmanaged: true + .travis.yml: docker_sets: - set: docker/centos-7 @@ -13,16 +16,17 @@ branches: - release +.rubocop.yml: + default_configs: + inherit_from: .rubocop_todo.yml + require: + - rubocop-i18n + - rubocop-rspec + +appveyor.yml: + delete: true + Gemfile: - required: - ':system_tests': - - gem: 'puppet-module-posix-system-r#{minor_version}' - platforms: ruby - - gem: 'puppet-module-win-system-r#{minor_version}' - platforms: - - mswin - - mingw - - x64_mingw optional: ':development': - gem: 'github_changelog_generator' @@ -30,15 +34,9 @@ Gemfile: ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')" -appveyor.yml: - delete: true - -.rubocop.yml: - default_configs: - inherit_from: .rubocop_todo.yml - -.gitlab-ci.yml: - unmanaged: true - Rakefile: changelog_user: puppetlabs + +spec/spec_helper.rb: + mock_with: ':rspec' + coverage_report: true diff --git a/.travis.yml b/.travis.yml index b6064dd0..33684c9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,22 +24,58 @@ matrix: fast_finish: true include: - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/centos-7 BEAKER_TESTMODE=apply - rvm: 2.5.3 - script: bundle exec rake beaker + env: PLATFORMS=deb_puppet5 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_deb]' + - bundle exec bolt command run 'apt-get install wget -y' --inventoryfile inventory.yaml --nodes='*' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel services: docker - stage: acceptance sudo: required - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/ubuntu-14.04 BEAKER_TESTMODE=apply - rvm: 2.5.3 - script: bundle exec rake beaker + env: PLATFORMS=deb_puppet6 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_deb]' + - bundle exec bolt command run 'apt-get install wget -y' --inventoryfile inventory.yaml --nodes='*' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORMS=el_puppet5 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_el]' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORMS=el_puppet6 + rvm: 2.5.1 + before_script: + - bundle exec rake 'litmus:provision_list[travis_el]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel services: docker - stage: acceptance sudo: required - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" diff --git a/Gemfile b/Gemfile index 60f245f4..731902c4 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ end ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments minor_version = ruby_version_segments[0..1].join('.') - +gem 'rb-readline' group :development do gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0') gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0') @@ -29,10 +29,6 @@ group :development do gem "puppet-module-win-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') end -group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] -end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] diff --git a/distelli-manifest.yml b/distelli-manifest.yml new file mode 100644 index 00000000..8fb4b9b8 --- /dev/null +++ b/distelli-manifest.yml @@ -0,0 +1,25 @@ +team-modules/puppetlabs-haproxy: + PreBuild: + - source /opt/rh/rh-ruby25/enable + - echo "--- LETS update BUNDLER ---" + - bundle install --path vendor/bundle --jobs 3 + Build: + - echo "--- PROVISIONING ---" + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:provision_list[release_checks] + - cat inventory.yaml + - echo "--- AGENT INSTALLATION ---" + - bundle exec rake litmus:install_agent + - echo "--- MODULE INSTALLATION ---" + - bundle exec rake litmus:install_module + - echo "--- TESTS RUNNING ---" + - bundle exec rake litmus:acceptance:parallel + AfterBuildSuccess: + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:tear_down + AfterBuildFailure: + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:tear_down + CommitData: + - RepoType: Git + - RepoPath: . diff --git a/metadata.json b/metadata.json index 8621802e..e98f73f7 100644 --- a/metadata.json +++ b/metadata.json @@ -22,6 +22,7 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", + "6", "7" ] }, @@ -70,7 +71,7 @@ "version_requirement": ">= 5.5.10 < 7.0.0" } ], - "template-url": "https://github.com/puppetlabs/pdk-templates#master", + "template-url": "https://github.com/puppetlabs/pdk-templates/#master", "template-ref": "heads/master-0-gb096033", "pdk-version": "1.11.1" } diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 00000000..6285f51d --- /dev/null +++ b/provision.yaml @@ -0,0 +1,13 @@ +--- +default: + provisioner: docker + images: ['waffleimage/debian8'] +travis_deb: + provisioner: docker + images: ['debian:8', 'debian:9', 'ubuntu:14.04', 'ubuntu:16.04', 'ubuntu:18.04'] +travis_el: + provisioner: docker_exp + images: ['centos:6', 'centos:7', 'oraclelinux:6', 'oraclelinux:7'] +release_checks: + provisioner: vmpooler + images: ['redhat-6-x86_64', 'redhat-7-x86_64', 'centos-6-x86_64', 'centos-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'ubuntu-1404-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64' ] diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb index 7e691b8f..c3148ee9 100644 --- a/spec/acceptance/basic_spec.rb +++ b/spec/acceptance/basic_spec.rb @@ -54,9 +54,9 @@ class { 'haproxy': } it 'has stats listening on each port' do ['9090', '9091'].each do |port| - shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r| - r.stdout.should =~ %r{HAProxy} - r.exit_code.should == 0 + run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r| + expect(r.stdout).to contain %r{HAProxy} + expect(r.exit_code).to eq 0 end end end @@ -83,9 +83,9 @@ class { 'haproxy': } it 'has stats listening on each port' do ['9090', '9091'].each do |port| - shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r| - r.stdout.should =~ %r{HAProxy} - r.exit_code.should == 0 + run_shell("/usr/bin/curl -u puppet:puppet localhost:#{port}") do |r| + expect(r.stdout).to contain %r{HAProxy} + expect(r.exit_code).to eq 0 end end end diff --git a/spec/acceptance/defaults_spec.rb b/spec/acceptance/defaults_spec.rb index 0cb996f2..ef1cf1d3 100644 --- a/spec/acceptance/defaults_spec.rb +++ b/spec/acceptance/defaults_spec.rb @@ -55,8 +55,8 @@ class { 'haproxy': } end it 'does a curl against the LB to make sure it gets a response from each port' do - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 555(6|7)}) - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 555(6|7)}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 555(6|7)}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 555(6|7)}) end pp_two = <<-PUPPETCODE @@ -122,7 +122,7 @@ class { 'haproxy': } end it 'does a curl against the LB to make sure it gets a response from each port #oldstyle' do - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) - shell('curl localhost:6666').stdout.chomp.should match(%r{Response on 5557}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) + expect(run_shell('curl localhost:6666').stdout.chomp).to match(%r{Response on 5557}) end end diff --git a/spec/acceptance/frontbackend_spec.rb b/spec/acceptance/frontbackend_spec.rb index aec57ec8..1947511a 100644 --- a/spec/acceptance/frontbackend_spec.rb +++ b/spec/acceptance/frontbackend_spec.rb @@ -32,12 +32,12 @@ class { 'haproxy': } # balancer. Something with retries would be better. # C9945 it 'does a curl against the LB to make sure it gets a response from each port' do - response_connection = shell('curl localhost:5555').stdout.chomp - response_connection.should match(%r{Response on 555(6|7)}) + response_connection = run_shell('curl localhost:5555').stdout.chomp + expect(response_connection).to match(%r{Response on 555(6|7)}) if response_connection == 'Response on 5556' - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5557}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5557}) else - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) end end @@ -70,8 +70,8 @@ class { 'haproxy': } # C9951 it 'does a curl against the LB to make sure it gets a response from each port #onenodeup' do - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) end pp_three = <<-PUPPETCODE diff --git a/spec/acceptance/listen_spec.rb b/spec/acceptance/listen_spec.rb index e5e8ed78..3a3dad11 100644 --- a/spec/acceptance/listen_spec.rb +++ b/spec/acceptance/listen_spec.rb @@ -27,8 +27,8 @@ class { 'haproxy': } # balancer. Something with retries would be better. # C9876 C9877 C9941 C9954 it 'does a curl against the LB to make sure it gets a response from each port' do - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 555(6|7)}) - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 555(6|7)}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 555(6|7)}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 555(6|7)}) end # C9955 @@ -53,14 +53,14 @@ class { 'haproxy': } PUPPETCODE it 'is able to configure the listen active/passive' do retry_on_error_matching do - idempotent_apply(default, pp_two, {}) + idempotent_apply(pp_two) end end it 'does a curl against the LB to make sure it only gets a response from the active port' do sleep(10) - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) end # C9942 C9944 WONTFIX @@ -89,8 +89,8 @@ class { 'haproxy': } end it 'does a curl against the LB to make sure it gets a response from each port #onenodeup' do - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) - shell('curl localhost:5555').stdout.chomp.should match(%r{Response on 5556}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) + expect(run_shell('curl localhost:5555').stdout.chomp).to match(%r{Response on 5556}) end pp_four = <<-PUPPETCODE diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml deleted file mode 100644 index 5eebdefb..00000000 --- a/spec/acceptance/nodesets/centos-7-x64.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - centos-7-x64: - roles: - - agent - - default - platform: el-7-x86_64 - hypervisor: vagrant - box: puppetlabs/centos-7.2-64-nocm -CONFIG: - 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 fef6e63c..00000000 --- a/spec/acceptance/nodesets/debian-8-x64.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - debian-8-x64: - roles: - - agent - - default - platform: debian-8-amd64 - hypervisor: vagrant - box: puppetlabs/debian-8.2-64-nocm -CONFIG: - type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml deleted file mode 100644 index 07423769..00000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -HOSTS: - redhat5-64-1: - pe_dir: - pe_ver: - pe_upgrade_dir: - pe_upgrade_ver: - platform: el-5-x86_64 - packaging_platform: el-5-x86_64 - template: redhat-5-x86_64 - hypervisor: vmpooler - roles: - - agent - - default -CONFIG: - nfs_server: none - consoleport: 443 - pooling_api: http://vmpooler.delivery.puppetlabs.net/ \ No newline at end of file diff --git a/spec/acceptance/nodesets/docker/centos-7.yml b/spec/acceptance/nodesets/docker/centos-7.yml deleted file mode 100644 index a3333aac..00000000 --- a/spec/acceptance/nodesets/docker/centos-7.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - centos-7-x64: - platform: el-7-x86_64 - hypervisor: docker - image: centos:7 - docker_preserve_image: true - docker_cmd: '["/usr/sbin/init"]' - # install various tools required to get the image up to usable levels - docker_image_commands: - - 'yum install -y crontabs tar wget openssl sysvinit-tools iproute which initscripts' -CONFIG: - trace_limit: 200 diff --git a/spec/acceptance/nodesets/docker/debian-8.yml b/spec/acceptance/nodesets/docker/debian-8.yml deleted file mode 100644 index df5c3194..00000000 --- a/spec/acceptance/nodesets/docker/debian-8.yml +++ /dev/null @@ -1,11 +0,0 @@ -HOSTS: - debian-8-x64: - platform: debian-8-amd64 - hypervisor: docker - image: debian:8 - docker_preserve_image: true - docker_cmd: '["/sbin/init"]' - docker_image_commands: - - 'apt-get update && apt-get install -y net-tools wget locales strace lsof && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen' -CONFIG: - trace_limit: 200 diff --git a/spec/acceptance/nodesets/docker/ubuntu-14.04.yml b/spec/acceptance/nodesets/docker/ubuntu-14.04.yml deleted file mode 100644 index b1efa583..00000000 --- a/spec/acceptance/nodesets/docker/ubuntu-14.04.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - ubuntu-1404-x64: - platform: ubuntu-14.04-amd64 - hypervisor: docker - image: ubuntu:14.04 - docker_preserve_image: true - docker_cmd: '["/sbin/init"]' - docker_image_commands: - # ensure that upstart is booting correctly in the container - - 'rm /usr/sbin/policy-rc.d && rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl && apt-get update && apt-get install -y net-tools wget && locale-gen en_US.UTF-8' -CONFIG: - trace_limit: 200 diff --git a/spec/acceptance/userlist_spec.rb b/spec/acceptance/userlist_spec.rb index f29dad37..4a7b531e 100644 --- a/spec/acceptance/userlist_spec.rb +++ b/spec/acceptance/userlist_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -describe 'userlist define', unless: (fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') == '5') do +describe 'userlist define', unless: (os[:family] == 'RedHat' && host_inventory['facter']['os']['release']['major'] == '5') do pp_one = <<-PUPPETCODE class { 'haproxy': } haproxy::userlist { 'users_groups': @@ -54,25 +54,25 @@ class { 'haproxy': } # C9957 it 'test1 should auth as user' do - shell('curl http://test1:elgato@localhost:5555').stdout.chomp.should eq('Response on 5556') + expect(run_shell('curl http://test1:elgato@localhost:5555').stdout.chomp).to eq('Response on 5556') end it 'test2 should auth as user' do - shell('curl http://test2:elgato@localhost:5555').stdout.chomp.should eq('Response on 5556') + expect(run_shell('curl http://test2:elgato@localhost:5555').stdout.chomp).to eq('Response on 5556') end # C9958 it 'does not auth as user' do - shell('curl http://test3:elgato@localhost:5555').stdout.chomp.should_not eq('Response on 5556') + expect(run_shell('curl http://test3:elgato@localhost:5555').stdout.chomp).not_to eq('Response on 5556') end # C9959 it 'auths as group' do - shell('curl http://test1:elgato@localhost:5554').stdout.chomp.should eq('Response on 5556') + expect(run_shell('curl http://test1:elgato@localhost:5554').stdout.chomp).to eq('Response on 5556') end # C9960 it 'does not auth as group' do - shell('curl http://test2:elgato@localhost:5554').stdout.chomp.should_not eq('Response on 5556') + expect(run_shell('curl http://test2:elgato@localhost:5554').stdout.chomp).not_to eq('Response on 5556') end # C9965 C9967 C9968 C9969 WONTFIX diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index feb57204..c09e0024 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,7 @@ +RSpec.configure do |c| + c.mock_with :rspec +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' @@ -39,6 +43,7 @@ end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 27cb63cc..2bb630c8 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,122 +1,58 @@ -require 'beaker-pe' -require 'beaker-puppet' -require 'beaker-rspec' -require 'beaker/puppet_install_helper' - -run_puppet_install_helper -configure_type_defaults_on(hosts) - -def idempotent_apply(hosts, manifest, opts = {}, &block) - block_on hosts, opts do |host| - file_path = host.tmpfile('apply_manifest.pp') - create_remote_file(host, file_path, manifest + "\n") - - puppet_apply_opts = { :verbose => nil, 'detailed-exitcodes' => nil } - on_options = { acceptable_exit_codes: [0, 2] } - on host, puppet('apply', file_path, puppet_apply_opts), on_options, &block - puppet_apply_opts2 = { :verbose => nil, 'detailed-exitcodes' => nil } - on_options2 = { acceptable_exit_codes: [0] } - on host, puppet('apply', file_path, puppet_apply_opts2), on_options2, &block - end -end - -UNSUPPORTED_PLATFORMS = ['RedHat', 'Suse', 'windows', 'AIX', 'Solaris'].freeze -MAX_RETRY_COUNT = 12 -RETRY_WAIT = 10 -ERROR_MATCHER = %r{(no valid OpenPGP data found|keyserver timed out|keyserver receive failed)} - -# This method allows a block to be passed in and if an exception is raised -# that matches the 'error_matcher' matcher, the block will wait a set number -# of seconds before retrying. -# Params: -# - max_retry_count - Max number of retries -# - retry_wait_interval_secs - Number of seconds to wait before retry -# - error_matcher - Matcher which the exception raised must match to allow retry -# Example Usage: -# retry_on_error_matching(3, 5, /OpenGPG Error/) do -# apply_manifest(pp, :catch_failures => true) -# end -def retry_on_error_matching(max_retry_count = MAX_RETRY_COUNT, retry_wait_interval_secs = RETRY_WAIT, error_matcher = ERROR_MATCHER) - try = 0 - begin - puts "retry_on_error_matching: try #{try}" unless try.zero? - try += 1 - yield - rescue StandardError => e - raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher) - sleep retry_wait_interval_secs - retry +# frozen_string_literal: true + +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 + +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 -end - -RSpec.configure do |c| - # Project root - proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - - # Readable test descriptions - c.formatter = :documentation - - # Configure all nodes in nodeset - c.before :suite do - # Install module and dependencies - puppet_module_install(source: proj_root, module_name: 'haproxy') - hosts.each do |host| - on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0, 1] - on host, puppet('module', 'install', 'puppetlabs-concat'), acceptable_exit_codes: [0, 1] - if fact('osfamily') == 'RedHat' - on host, puppet('module', 'install', 'stahnma/epel'), acceptable_exit_codes: [0, 1] - end - if fact('operatingsystem') == 'Debian' - on host, puppet('module', 'install', 'puppetlabs-apt'), acceptable_exit_codes: [0, 1] - apply_manifest(%( - include apt - include apt::backports - )) - end - pp = <<-PUPPETCODE - package { 'socat': ensure => present, } - package { 'screen': ensure => present, } - if $::osfamily == 'RedHat' { - if $::operatingsystemmajrelease == '5' or ($::operatingsystem == 'OracleLinux' and $::operatingsystemmajrelease == '6'){ - class { 'epel': - epel_baseurl => "http://osmirror.delivery.puppetlabs.net/epel${::operatingsystemmajrelease}-\\$basearch/RPMS.all", - epel_mirrorlist => "http://osmirror.delivery.puppetlabs.net/epel${::operatingsystemmajrelease}-\\$basearch/RPMS.all", - before => Package['socat'], - } - } else { - class { 'epel': - before => Package['socat'], - } - } - service { 'iptables': ensure => stopped, } - exec { 'setenforce 0': - path => ['/bin','/usr/bin','/sbin','/usr/sbin'], - onlyif => 'which getenforce && getenforce | grep Enforcing', - } - } - if ($::osfamily == 'RedHat' and $::operatingsystemmajrelease == '7') or ($::osfamily == 'Debian' and ($::operatingsystemmajrelease == '9' or $::operatingsystemmajrelease == '18.04')) { - # For `netstat` for serverspec - package { 'net-tools': ensure => present, } - } - PUPPETCODE - apply_manifest(pp, catch_failures: true) - - ['5556', '5557'].each do |port| - content = "socat -v tcp-l:#{port},reuseaddr,fork system:\"printf \\'HTTP/1.1 200 OK\r\n\r\nResponse on #{port}\\'\",nofork" - create_remote_file(host, "/root/script-#{port}.sh", content) - shell(%(/usr/bin/screen -dmS script-#{port} sh /root/script-#{port}.sh)) - sleep 1 - shell(%(netstat -tnl|grep ':#{port}')) - end - end - end - - # FM-5470, this was added to reset failed count and work around puppet 3.x - if (fact('operatingsystem') == 'SLES' && fact('operatingsystemmajrelease') == '12') || (fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') == '7') - c.after :each do - # not all tests have a haproxy service, so the systemctl call can fail, - # but we don't care as we only need to reset when it does. - shell('systemctl reset-failed haproxy.service || true') - 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? + options[:verify_host_key] = Net::SSH::Verifiers::Null.new unless node_config.dig('ssh', 'host-key-check').nil? + 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 + 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" + + opts = { + user: user, + password: pass, + endpoint: endpoint, + operation_timeout: 300, + } + + winrm = WinRM::Connection.new opts + Specinfra.configuration.winrm = winrm end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb new file mode 100644 index 00000000..5f579276 --- /dev/null +++ b/spec/spec_helper_acceptance_local.rb @@ -0,0 +1,49 @@ +UNSUPPORTED_PLATFORMS = ['RedHat', 'Suse', 'windows', 'AIX', 'Solaris'].freeze +MAX_RETRY_COUNT = 12 +RETRY_WAIT = 10 +ERROR_MATCHER = %r{(no valid OpenPGP data found|keyserver timed out|keyserver receive failed)} + +# This method allows a block to be passed in and if an exception is raised +# that matches the 'error_matcher' matcher, the block will wait a set number +# of seconds before retrying. +# Params: +# - max_retry_count - Max number of retries +# - retry_wait_interval_secs - Number of seconds to wait before retry +# - error_matcher - Matcher which the exception raised must match to allow retry +# Example Usage: +# retry_on_error_matching(3, 5, /OpenGPG Error/) do +# apply_manifest(pp, :catch_failures => true) +# end +def retry_on_error_matching(max_retry_count = MAX_RETRY_COUNT, retry_wait_interval_secs = RETRY_WAIT, error_matcher = ERROR_MATCHER) + try = 0 + begin + puts "retry_on_error_matching: try #{try}" unless try.zero? + try += 1 + yield + rescue StandardError => e + raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher) + sleep retry_wait_interval_secs + retry + end +end + +RSpec.configure do |c| + c.before :suite do + if os[:family] == 'redhat' + run_shell('puppet module install stahnma/epel') + run_shell("puppet apply -e 'include epel'") + end + ['5556', '5557'].each do |port| + pp = <<-PP + package { 'socat': ensure => present, } + package { 'screen': ensure => present, } + package { 'net-tools': ensure => present, } + PP + apply_manifest(pp) + bolt_upload_file("spec/support/script-#{port}.sh", "/root/script-#{port}.sh") + run_shell(%(screen -dmS script-#{port} sh /root/script-#{port}.sh)) + sleep 1 + run_shell(%(netstat -tnl|grep ':#{port}')) + end + end +end diff --git a/spec/support/script-5556.sh b/spec/support/script-5556.sh new file mode 100644 index 00000000..46b8766e --- /dev/null +++ b/spec/support/script-5556.sh @@ -0,0 +1,3 @@ +socat -v tcp-l:5556,reuseaddr,fork system:"printf \'HTTP/1.1 200 OK + +Response on 5556\'",nofork diff --git a/spec/support/script-5557.sh b/spec/support/script-5557.sh new file mode 100644 index 00000000..52114d1f --- /dev/null +++ b/spec/support/script-5557.sh @@ -0,0 +1,3 @@ +socat -v tcp-l:5557,reuseaddr,fork system:"printf \'HTTP/1.1 200 OK + +Response on 5557\'",nofork