From 1eae4919c195bef8bfb53c2a8c9241dcfea38343 Mon Sep 17 00:00:00 2001 From: tphoney Date: Fri, 26 Jul 2019 11:23:10 +0100 Subject: [PATCH] (FM-8214) converted to use litmus Fix itk_spec running unnecessarily on el5 more acceptance test setup. Simplify vhost_spec tests --- .fixtures.yml | 5 +- .sync.yml | 11 +- .travis.yml | 55 +- Gemfile | 5 - distelli-manifest.yml | 25 + metadata.json | 2 +- provision.yaml | 13 + spec/acceptance/apache_parameters_spec.rb | 127 +- spec/acceptance/apache_ssl_spec.rb | 27 +- spec/acceptance/class_spec.rb | 37 +- spec/acceptance/custom_config_spec.rb | 15 +- spec/acceptance/default_mods_spec.rb | 41 +- spec/acceptance/init_task_spec.rb | 7 +- spec/acceptance/itk_spec.rb | 24 +- spec/acceptance/mod_php_spec.rb | 27 +- spec/acceptance/nodesets/centos-7-x64.yml | 10 - spec/acceptance/nodesets/debian-8-x64.yml | 10 - spec/acceptance/nodesets/default.yml | 10 - 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/nodesets/suse.yml | 25 - spec/acceptance/prefork_worker_spec.rb | 67 +- spec/acceptance/service_spec.rb | 5 +- spec/acceptance/version.rb | 93 -- spec/acceptance/vhost_spec.rb | 1220 +++++------------ spec/acceptance/vhosts_spec.rb | 7 +- spec/spec_helper_acceptance.rb | 155 +-- spec/spec_helper_acceptance_local.rb | 139 ++ 29 files changed, 769 insertions(+), 1428 deletions(-) create mode 100644 distelli-manifest.yml create mode 100644 provision.yaml mode change 100755 => 100644 spec/acceptance/apache_parameters_spec.rb 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 delete mode 100644 spec/acceptance/nodesets/suse.yml delete mode 100644 spec/acceptance/version.rb create mode 100644 spec/spec_helper_acceptance_local.rb diff --git a/.fixtures.yml b/.fixtures.yml index c65734b30c..4fe91b89c8 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,8 +1,11 @@ fixtures: repositories: - stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" concat: "git://github.com/puppetlabs/puppetlabs-concat.git" + facts: 'git://github.com/puppetlabs/puppetlabs-facts.git' portage: "git://github.com/gentoo/puppet-portage.git" + provision: 'git://github.com/puppetlabs/provision.git' + puppet_agent: 'git://github.com/puppetlabs/puppetlabs-puppet_agent.git' + stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" yumrepo_core: repo: "git://github.com/puppetlabs/puppetlabs-yumrepo_core.git" puppet_version: '>= 6.0.0' diff --git a/.sync.yml b/.sync.yml index 7c941ee542..4040796c25 100644 --- a/.sync.yml +++ b/.sync.yml @@ -19,15 +19,6 @@ - release 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' @@ -48,4 +39,4 @@ appveyor.yml: spec/spec_helper.rb: mock_with: ':rspec' - coverage_report: true \ No newline at end of file + coverage_report: true diff --git a/.travis.yml b/.travis.yml index c29b111623..3c5c304c65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,6 @@ script: bundler_args: --without system_tests rvm: - 2.5.3 -env: - global: - - PARALLEL_TEST_PROCESSORS=16 stages: - static - spec @@ -27,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 + env: PLATFORMS=deb_puppet5 rvm: 2.5.3 - script: bundle exec rake beaker + 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 + env: PLATFORMS=deb_puppet6 rvm: 2.5.3 - script: bundle exec rake beaker + 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=el7_puppet5 + rvm: 2.5.3 + before_script: + - bundle exec rake 'litmus:provision_list[travis_el7]' + - 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=el7_puppet6 + rvm: 2.5.3 + before_script: + - bundle exec rake 'litmus:provision_list[travis_el7]' + - 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 60f245f4c8..0e94796156 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,6 @@ end ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments minor_version = ruby_version_segments[0..1].join('.') - 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 +28,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 0000000000..520a54bfd1 --- /dev/null +++ b/distelli-manifest.yml @@ -0,0 +1,25 @@ +team-modules/puppetlabs-apache: + 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 966a17398b..24977cc5ae 100644 --- a/metadata.json +++ b/metadata.json @@ -80,6 +80,6 @@ ], "description": "Module for Apache configuration", "pdk-version": "1.11.1", - "template-url": "https://github.com/puppetlabs/pdk-templates#master", + "template-url": "https://github.com/puppetlabs/pdk-templates/#master", "template-ref": "heads/master-0-gb096033" } diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 0000000000..a309065b6a --- /dev/null +++ b/provision.yaml @@ -0,0 +1,13 @@ +--- +default: + provisioner: docker + images: ['waffleimage/debian8'] +travis_deb: + provisioner: docker + images: ['waffleimage/debian8', 'waffleimage/debian9', 'waffleimage/ubuntu14.04', 'waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04'] +travis_el7: + provisioner: docker + images: ['waffleimage/centos7', 'waffleimage/oraclelinux7', 'waffleimage/scientificlinux7'] +release_checks: + provisioner: vmpooler + images: ['redhat-5-x86_64', 'redhat-6-x86_64', 'redhat-7-x86_64', 'centos-5-x86_64', 'centos-6-x86_64', 'centos-7-x86_64', 'oracle-6-x86_64', 'oracle-7-x86_64', 'scientific-6-x86_64', 'scientific-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'ubuntu-1404-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'sles-11-x86_64', 'sles-12-x86_64', 'sles-15-x86_64'] diff --git a/spec/acceptance/apache_parameters_spec.rb b/spec/acceptance/apache_parameters_spec.rb old mode 100755 new mode 100644 index 98c7dd2ee4..8c862eb179 --- a/spec/acceptance/apache_parameters_spec.rb +++ b/spec/acceptance/apache_parameters_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - +apache_hash = apache_settings_hash describe 'apache parameters' do # Currently this test only does something on FreeBSD. describe 'default_confd_files => false' do @@ -9,8 +8,8 @@ apply_manifest(pp, catch_failures: true) end - if host_inventory['facter']['os']['family'] == 'FreeBSD' - describe file("#{$confd_dir}/no-accf.conf.erb") do + if os[:family] == 'freebsd' + describe file("#{apache_hash['confd_dir']}/no-accf.conf.erb") do it { is_expected.not_to be_file } end end @@ -21,8 +20,8 @@ apply_manifest(pp, catch_failures: true) end - if host_inventory['facter']['os']['family'] == 'FreeBSD' - describe file("#{$confd_dir}/no-accf.conf.erb") do + if os[:family] == 'freebsd' + describe file("#{apache_hash['confd_dir']}/no-accf.conf.erb") do it { is_expected.to be_file } end end @@ -34,7 +33,7 @@ apply_manifest(pp, catch_failures: true) end - describe file($ports_file) do + describe file(apache_hash['ports_file']) do it { is_expected.to be_file } it { is_expected.to contain 'Listen 10.1.1.1' } end @@ -52,15 +51,9 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe service($service_name) do + describe service(apache_hash['service_name']) do it { is_expected.to be_running } - if host_inventory['facter']['os']['name'] == 'debian' && os[:release][0] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'sles' && os[:release][0..1] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + it { is_expected.to be_enabled } end end @@ -75,15 +68,9 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe service($service_name) do + describe service(apache_hash['service_name']) do it { is_expected.not_to be_running } - if host_inventory['facter']['os']['name'] == 'debian' && os[:release][0] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'sles' && os[:release][0..1] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.not_to be_enabled } - end + it { is_expected.not_to be_enabled } end end @@ -99,19 +86,13 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe service($service_name) do + describe service(apache_hash['service_name']) do it { is_expected.not_to be_running } - if host_inventory['facter']['os']['name'] == 'debian' && os[:release][0] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'sles' && os[:release][0..1] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.not_to be_enabled } - end + it { is_expected.not_to be_enabled } end end - if host_inventory['facter']['os']['family'] == 'Debian' + if os[:family] == 'debian' describe 'conf_enabled => /etc/apache2/conf-enabled' do pp = <<-MANIFEST class { 'apache': @@ -120,7 +101,7 @@ class { 'apache': } MANIFEST it 'applies cleanly' do - shell('touch /etc/apache2/conf-enabled/test.conf') + run_shell('touch /etc/apache2/conf-enabled/test.conf') apply_manifest(pp, catch_failures: true) end @@ -141,44 +122,44 @@ class { 'apache': class { 'apache': purge_configs => false, purge_vhost_dir => false, - vhost_dir => "#{$confd_dir}.vhosts" + vhost_dir => "#{apache_hash['confd_dir']}.vhosts" } MANIFEST it 'applies cleanly' do - shell("touch #{$confd_dir}/test.conf") - shell("mkdir -p #{$confd_dir}.vhosts && touch #{$confd_dir}.vhosts/test.conf") + run_shell("touch #{apache_hash['confd_dir']}/test.conf") + run_shell("mkdir -p #{apache_hash['confd_dir']}.vhosts && touch #{apache_hash['confd_dir']}.vhosts/test.conf") apply_manifest(pp, catch_failures: true) end # Ensure the files didn't disappear. - describe file("#{$confd_dir}/test.conf") do + describe file("#{apache_hash['confd_dir']}/test.conf") do it { is_expected.to be_file } end - describe file("#{$confd_dir}.vhosts/test.conf") do + describe file("#{apache_hash['confd_dir']}.vhosts/test.conf") do it { is_expected.to be_file } end end - if host_inventory['facter']['os']['family'] != 'Debian' + if os[:family] != 'debian' describe 'purge parameters => true' do pp = <<-MANIFEST class { 'apache': purge_configs => true, purge_vhost_dir => true, - vhost_dir => "#{$confd_dir}.vhosts" + vhost_dir => "#{apache_hash['confd_dir']}.vhosts" } MANIFEST it 'applies cleanly' do - shell("touch #{$confd_dir}/test.conf") - shell("mkdir -p #{$confd_dir}.vhosts && touch #{$confd_dir}.vhosts/test.conf") + run_shell("touch #{apache_hash['confd_dir']}/test.conf") + run_shell("mkdir -p #{apache_hash['confd_dir']}.vhosts && touch #{apache_hash['confd_dir']}.vhosts/test.conf") apply_manifest(pp, catch_failures: true) end # File should be gone - describe file("#{$confd_dir}/test.conf") do + describe file("#{apache_hash['confd_dir']}/test.conf") do it { is_expected.not_to be_file } end - describe file("#{$confd_dir}.vhosts/test.conf") do + describe file("#{apache_hash['confd_dir']}.vhosts/test.conf") do it { is_expected.not_to be_file } end end @@ -190,7 +171,7 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe file($vhost) do + describe file(apache_hash['vhost']) do it { is_expected.to be_file } it { is_expected.to contain 'ServerAdmin test@example.com' } end @@ -204,7 +185,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'EnableSendfile On' } end @@ -216,7 +197,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'Sendfile Off' } end @@ -230,7 +211,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'Alias /error/' } end @@ -244,7 +225,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'Timeout 1234' } end @@ -261,7 +242,7 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped } end end - describe file("#{$mod_dir}/mime.conf") do + describe file("#{apache_hash['mod_dir']}/mime.conf") do it { is_expected.to be_file } it { is_expected.to contain 'AddLanguage eo .eo' } end @@ -271,7 +252,7 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped } # Actually >= 2.4.24, but the minor version is not provided # https://bugs.launchpad.net/ubuntu/+source/apache2/2.4.7-1ubuntu4.15 # basically versions of the ubuntu or sles apache package cause issue - if $apache_version >= '2.4' && host_inventory['facter']['os']['name'] !~ %r{Ubuntu|SLES} + if apache_hash['version'] >= '2.4' && os[:family] !~ %r{ubuntu|sles} describe 'setup' do it 'applies cleanly' do pp = "class { 'apache': http_protocol_options => 'Unsafe RegisteredMethods Require1.0'}" @@ -279,7 +260,7 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped } end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'HttpProtocolOptions Unsafe RegisteredMethods Require1.0' } end @@ -294,7 +275,7 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped } end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'ServerRoot "/tmp/root"' } end @@ -308,13 +289,13 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped } end end - if $apache_version == '2.4' - describe file($conf_file) do + if apache_hash['version'] == '2.4' + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'IncludeOptional "/tmp/root/*.conf"' } end else - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'Include "/tmp/root/*.conf"' } end @@ -325,13 +306,13 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped } describe 'setup' do it 'applies cleanly' do pp = "class { 'apache': conf_template => 'another/test.conf.erb', service_ensure => stopped }" - shell("mkdir -p #{default['distmoduledir']}/another/templates") - shell("echo 'testcontent' >> #{default['distmoduledir']}/another/templates/test.conf.erb") + run_shell('mkdir -p /etc/puppetlabs/code/environments/production/modules/another/templates') + run_shell("echo 'testcontent' >> /etc/puppetlabs/code/environments/production/modules/another/templates/test.conf.erb") apply_manifest(pp, catch_failures: true) end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'testcontent' } end @@ -345,7 +326,7 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped } end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'ServerName "test.server"' } end @@ -391,7 +372,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common' } it { is_expected.to contain 'LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined' } @@ -406,7 +387,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'KeepAlive Off' } it { is_expected.to contain 'KeepAliveTimeout 30' } @@ -422,7 +403,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'LimitRequestFieldSize 16830' } end @@ -436,7 +417,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'LimitRequestFields 120' } end @@ -472,7 +453,7 @@ class { 'apache': logroot => '/apache_spec' } end end - describe file("/apache_spec/#{$error_log}") do + describe file("/apache_spec/#{apache_hash['error_log']}") do it { is_expected.to be_file } end end @@ -506,7 +487,7 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'ServerTokens Minor' } end @@ -523,7 +504,7 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'ServerSignature testsig' } end @@ -537,7 +518,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'HostnameLookups On' } end @@ -549,7 +530,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'HostnameLookups Off' } end @@ -561,7 +542,7 @@ class { 'apache': end end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'HostnameLookups Double' } end @@ -577,7 +558,7 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'TraceEnable Off' } end @@ -593,7 +574,7 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe file($conf_file) do + describe file(apache_hash['conf_file']) do it { is_expected.to be_file } it { is_expected.to contain 'FileETag None' } end @@ -609,7 +590,7 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe package($package_name) do + describe package(apache_hash['package_name']) do it { is_expected.to be_installed } end end diff --git a/spec/acceptance/apache_ssl_spec.rb b/spec/acceptance/apache_ssl_spec.rb index 63a44e7ea8..669f54a0af 100644 --- a/spec/acceptance/apache_ssl_spec.rb +++ b/spec/acceptance/apache_ssl_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - +apache_hash = apache_settings_hash describe 'apache ssl' do describe 'ssl parameters' do pp = <<-MANIFEST @@ -17,11 +16,10 @@ class { 'apache': } MANIFEST it 'runs without error' do - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + idempotent_apply(pp) end - describe file("#{$vhost_dir}/15-default-ssl.conf") do + describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do it { is_expected.to be_file } it { is_expected.to contain 'SSLCertificateFile "/tmp/ssl_cert"' } it { is_expected.to contain 'SSLCertificateKeyFile "/tmp/ssl_key"' } @@ -29,7 +27,7 @@ class { 'apache': it { is_expected.not_to contain 'SSLCACertificateFile "/tmp/ssl_ca"' } it { is_expected.not_to contain 'SSLCARevocationPath "/tmp/ssl_crl_path"' } it { is_expected.not_to contain 'SSLCARevocationFile "/tmp/ssl_crl"' } - if $apache_version == '2.4' + if apache_hash['version'] == '2.4' it { is_expected.not_to contain 'SSLCARevocationCheck "chain"' } else it { is_expected.not_to contain 'SSLCARevocationCheck' } @@ -65,11 +63,10 @@ class { 'apache': } MANIFEST it 'runs without error' do - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + idempotent_apply(pp) end - describe file("#{$vhost_dir}/25-test_ssl.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test_ssl.conf") do it { is_expected.to be_file } it { is_expected.to contain 'SSLCertificateFile "/tmp/ssl_cert"' } it { is_expected.to contain 'SSLCertificateKeyFile "/tmp/ssl_key"' } @@ -85,7 +82,7 @@ class { 'apache': it { is_expected.to contain 'SSLVerifyClient test' } it { is_expected.to contain 'SSLVerifyDepth test' } it { is_expected.to contain 'SSLOptions test test1' } - if $apache_version == '2.4' + if apache_hash['version'] == '2.4' it { is_expected.to contain 'SSLCARevocationCheck "chain"' } else it { is_expected.not_to contain 'SSLCARevocationCheck' } @@ -109,11 +106,10 @@ class { 'apache': } MANIFEST it 'runs without error' do - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + idempotent_apply(pp) end - describe file("#{$vhost_dir}/25-test_ssl_ca_only.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test_ssl_ca_only.conf") do it { is_expected.to be_file } it { is_expected.to contain 'SSLCertificateFile "/tmp/ssl_cert"' } it { is_expected.to contain 'SSLCertificateKeyFile "/tmp/ssl_key"' } @@ -138,11 +134,10 @@ class { 'apache': } MANIFEST it 'runs without error' do - apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) + idempotent_apply(pp) end - describe file("#{$vhost_dir}/25-test_ssl_certs_dir_only.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test_ssl_certs_dir_only.conf") do it { is_expected.to be_file } it { is_expected.to contain 'SSLCertificateFile "/tmp/ssl_cert"' } it { is_expected.to contain 'SSLCertificateKeyFile "/tmp/ssl_key"' } diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index d86a8dfdf5..d983599cd8 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - +apache_hash = apache_settings_hash describe 'apache class' do context 'default parameters' do let(:pp) { "class { 'apache': }" } - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end describe 'apache_version fact' do let(:result) do @@ -17,22 +18,16 @@ end it { - expect(result.output).to match(%r{apache_version = >#{$apache_version}.*<}) + expect(result.stdout).to match(%r{apache_version = >#{apache_hash['version']}.*<}) } end - describe package($package_name) do + describe package(apache_hash['package_name']) do it { is_expected.to be_installed } end - describe service($service_name) do - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end @@ -42,7 +37,6 @@ end context 'custom site/mod dir parameters' do - # Using puppet_apply as a helper let(:pp) do <<-MANIFEST if $::osfamily == 'RedHat' and "$::selinux" == "true" { @@ -76,17 +70,12 @@ class { 'apache': MANIFEST end - # Run it twice and test for idempotency - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end - describe service($service_name) do - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end end diff --git a/spec/acceptance/custom_config_spec.rb b/spec/acceptance/custom_config_spec.rb index 799fdc1646..52b58fe136 100644 --- a/spec/acceptance/custom_config_spec.rb +++ b/spec/acceptance/custom_config_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - +apache_hash = apache_settings_hash describe 'apache::custom_config define' do context 'invalid config' do pp = <<-MANIFEST @@ -13,7 +12,7 @@ class { 'apache': } apply_manifest(pp, expect_failures: true) end - describe file("#{$confd_dir}/25-acceptance_test.conf") do + describe file("#{apache_hash['confd_dir']}/25-acceptance_test.conf") do it { expect(file).not_to exist } end end @@ -29,7 +28,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$confd_dir}/25-acceptance_test.conf") do + describe file("#{apache_hash['confd_dir']}/25-acceptance_test.conf") do it { is_expected.to contain '# just a comment' } end end @@ -46,7 +45,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$confd_dir}/custom_filename") do + describe file("#{apache_hash['confd_dir']}/custom_filename") do it { is_expected.to contain '# just another comment' } end end @@ -63,7 +62,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$confd_dir}/prefix_test.conf") do + describe file("#{apache_hash['confd_dir']}/prefix_test.conf") do it { is_expected.to be_file } end end @@ -78,13 +77,13 @@ class { 'apache': } # Try to wedge the apache::custom_config call between when httpd.conf is written and # ports.conf is written. This should trigger a dependency cycle - File["#{$conf_file}"] -> Apache::Custom_config['ordering_test'] -> Concat["#{$ports_file}"] + File["#{apache_hash['conf_file']}"] -> Apache::Custom_config['ordering_test'] -> Concat["#{apache_hash['ports_file']}"] MANIFEST it 'applies in the right order' do expect(apply_manifest(pp, expect_failures: true).stderr).to match(%r{Found 1 dependency cycle}i) end - describe file("#{$confd_dir}/25-ordering_test.conf") do + describe file("#{apache_hash['confd_dir']}/25-ordering_test.conf") do it { is_expected.not_to be_file } end end diff --git a/spec/acceptance/default_mods_spec.rb b/spec/acceptance/default_mods_spec.rb index e14dca7fef..eeef5586d3 100644 --- a/spec/acceptance/default_mods_spec.rb +++ b/spec/acceptance/default_mods_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - +apache_hash = apache_settings_hash describe 'apache::default_mods class' do describe 'no default mods' do # Using puppet_apply as a helper @@ -12,14 +11,16 @@ class { 'apache': MANIFEST end - # Run it twice and test for idempotency - it_behaves_like 'a idempotent resource' - describe service($service_name) do + it 'behaves idempotently' do + idempotent_apply(pp) + end + + describe service(apache_hash['service_name']) do it { is_expected.to be_running } end end - unless host_inventory['facter']['os']['name'] == 'SLES' && os[:release].to_i >= 12 + unless os[:family] == 'sles' && os[:release].to_i >= 12 describe 'no default mods and failing' do before :all do pp = <<-PP @@ -34,14 +35,14 @@ class { 'apache': default_mods => false, } apache::vhost { 'defaults.example.com': - docroot => '#{$doc_root}/defaults', + docroot => '#{apache_hash['doc_root']}/defaults', aliases => { alias => '/css', - path => '#{$doc_root}/css', + path => '#{apache_hash['doc_root']}/css', }, directories => [ { - 'path' => "#{$doc_root}/admin", + 'path' => "#{apache_hash['doc_root']}/admin", 'auth_basic_fake' => 'demo demopass', } ], @@ -53,7 +54,7 @@ class { 'apache': end end - describe service($service_name) do + describe service(apache_hash['service_name']) do it { is_expected.not_to be_running } end end @@ -72,19 +73,21 @@ class { 'apache': ], } apache::vhost { 'defaults.example.com': - docroot => '#{$doc_root}/defaults', + docroot => '#{apache_hash['doc_root']}/defaults', aliases => { alias => '/css', - path => '#{$doc_root}/css', + path => '#{apache_hash['doc_root']}/css', }, setenv => 'TEST1 one', } MANIFEST end - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end - describe service($service_name) do + describe service(apache_hash['service_name']) do it { is_expected.to be_running } end end @@ -99,13 +102,15 @@ class { 'apache': default_mods => false } MANIFEST end - # Run it twice and test for idempotency - it_behaves_like 'a idempotent resource' - describe service($service_name) do + it 'behaves idempotently' do + idempotent_apply(pp) + end + + describe service(apache_hash['service_name']) do it { is_expected.to be_running } end - describe file("#{$mod_dir}/zz_auth_basic.load") do + describe file("#{apache_hash['mod_dir']}/zz_auth_basic.load") do it { is_expected.to be_file } end end diff --git a/spec/acceptance/init_task_spec.rb b/spec/acceptance/init_task_spec.rb index 4c074e1dc4..3405c62d4c 100644 --- a/spec/acceptance/init_task_spec.rb +++ b/spec/acceptance/init_task_spec.rb @@ -1,7 +1,6 @@ -# run a test task require 'spec_helper_acceptance' -describe 'apache tasks', if: puppet_version =~ %r{(5\.\d+\.\d+)} && host_inventory['facter']['os']['name'] != 'SLES' do +describe 'apache tasks' do describe 'reload' do pp = <<-MANIFEST class { 'apache': @@ -12,8 +11,8 @@ class { 'apache': it 'execute reload' do apply_manifest(pp, catch_failures: true) - result = run_task(task_name: 'apache', params: 'action=reload') - expect_multiple_regexes(result: result, regexes: [%r{reload successful}, %r{Job completed. 1/1 nodes succeeded|Ran on 1 node}]) + result = run_bolt_task('apache', 'action' => 'reload') + expect(result.stdout).to contain(%(reload successful)) end end end diff --git a/spec/acceptance/itk_spec.rb b/spec/acceptance/itk_spec.rb index 4376b00d0a..fc3089cc5a 100644 --- a/spec/acceptance/itk_spec.rb +++ b/spec/acceptance/itk_spec.rb @@ -1,22 +1,21 @@ require 'spec_helper_acceptance' -case host_inventory['facter']['os']['family'] -when 'Debian' +case os[:family] +when 'debian', 'ubuntu' service_name = 'apache2' variant = :prefork -when 'RedHat' - unless host_inventory['facter']['os']['release']['major'] == '5' +when 'redhat' + unless os[:release] =~ %r{^5} variant = (os[:release].to_i >= 7) ? :prefork : :itk_only service_name = 'httpd' end -when 'FreeBSD' +when 'freebsd' service_name = 'apache24' variant = :prefork end describe 'apache::mod::itk class', if: service_name do describe 'running puppet code' do - # Using puppet_apply as a helper let(:pp) do case variant when :prefork @@ -35,18 +34,13 @@ class { 'apache': end end - # Run it twice and test for idempotency - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end end describe service(service_name) do it { is_expected.to be_running } - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + it { is_expected.to be_enabled } end end diff --git a/spec/acceptance/mod_php_spec.rb b/spec/acceptance/mod_php_spec.rb index e05290b9a1..df3d9e8e60 100644 --- a/spec/acceptance/mod_php_spec.rb +++ b/spec/acceptance/mod_php_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - -unless host_inventory['facter']['os']['name'] == 'SLES' && os[:release].to_i >= 12 +apache_hash = apache_settings_hash +unless os[:family] == 'sles' && os[:release].to_i >= 12 describe 'apache::mod::php class' do context 'default php config' do pp = <<-MANIFEST @@ -11,10 +10,10 @@ class { 'apache': class { 'apache::mod::php': } apache::vhost { 'php.example.com': port => '80', - docroot => '#{$doc_root}/php', + docroot => '#{apache_hash['doc_root']}/php', } host { 'php.example.com': ip => '127.0.0.1', } - file { '#{$doc_root}/php/index.php': + file { '#{apache_hash['doc_root']}/php/index.php': ensure => file, content => "\\n", } @@ -23,17 +22,17 @@ class { 'apache::mod::php': } apply_manifest(pp, catch_failures: true) end - if (host_inventory['facter']['os']['name'] == 'Ubuntu' && host_inventory['facter']['os']['release']['full'] == '16.04') || - (host_inventory['facter']['os']['name'] == 'Debian' && os[:release].to_i == 9) - describe file("#{$mod_dir}/php7.0.conf") do + if (os[:family] == 'ubuntu' && os[:release] == '16.04') || + (os[:family] == 'debian' && os[:release] =~ %r{9}) + describe file("#{apache_hash['mod_dir']}/php7.0.conf") do it { is_expected.to contain 'DirectoryIndex index.php' } end - elsif host_inventory['facter']['os']['name'] == 'Ubuntu' && host_inventory['facter']['os']['release']['full'] == '18.04' - describe file("#{$mod_dir}/php7.2.conf") do + elsif os[:family] == 'ubuntu' && os[:release] == '18.04' + describe file("#{apache_hash['mod_dir']}/php7.2.conf") do it { is_expected.to contain 'DirectoryIndex index.php' } end else - describe file("#{$mod_dir}/php5.conf") do + describe file("#{apache_hash['mod_dir']}/php5.conf") do it { is_expected.to contain 'DirectoryIndex index.php' } end end @@ -50,14 +49,14 @@ class { 'apache::mod::php': apache::vhost { 'php.example.com': port => '80', - docroot => '#{$doc_root}/php', + docroot => '#{apache_hash['doc_root']}/php', php_values => { 'include_path' => '.:/usr/share/pear:/usr/bin/php', }, php_flags => { 'display_errors' => 'on', }, php_admin_values => { 'open_basedir' => '/var/www/php/:/usr/share/pear/', }, php_admin_flags => { 'engine' => 'on', }, } host { 'php.example.com': ip => '127.0.0.1', } - file { '#{$doc_root}/php/index.php5': + file { '#{apache_hash['doc_root']}/php/index.php5': ensure => file, content => "\\n", } @@ -66,7 +65,7 @@ class { 'apache::mod::php': apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-php.example.com.conf") do + describe file("#{apache_hash['vhost_dir']}/25-php.example.com.conf") do it { is_expected.to contain ' php_flag display_errors on' } it { is_expected.to contain ' php_value include_path ".:/usr/share/pear:/usr/bin/php"' } it { is_expected.to contain ' php_admin_flag engine on' } diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml deleted file mode 100644 index 5eebdefbfa..0000000000 --- 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 fef6e63ca5..0000000000 --- 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 dba339c46a..0000000000 --- a/spec/acceptance/nodesets/default.yml +++ /dev/null @@ -1,10 +0,0 @@ -HOSTS: - ubuntu-1404-x64: - roles: - - agent - - default - platform: ubuntu-14.04-amd64 - hypervisor: vagrant - box: puppetlabs/ubuntu-14.04-64-nocm -CONFIG: - type: foss diff --git a/spec/acceptance/nodesets/docker/centos-7.yml b/spec/acceptance/nodesets/docker/centos-7.yml deleted file mode 100644 index a3333aac53..0000000000 --- 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 df5c31944f..0000000000 --- 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 b1efa58390..0000000000 --- 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/nodesets/suse.yml b/spec/acceptance/nodesets/suse.yml deleted file mode 100644 index ac04926992..0000000000 --- a/spec/acceptance/nodesets/suse.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -HOSTS: - sles-11-x86_64-agent: - roles: - - agent - - default - platform: sles-11-x86_64 - template: sles-11-x86_64 - hypervisor: virtualbox - redhat-7-x86_64-master: - roles: - - master - - dashboard - - database - - agent - platform: el-7-x86_64 - template: redhat-7-x86_64 - hypervisor: virtualbox -CONFIG: - nfs_server: none - consoleport: 443 - datastore: instance0 - folder: Delivery/Quality Assurance/Enterprise/Dynamic - resourcepool: delivery/Quality Assurance/Enterprise/Dynamic - pooling_api: http://vcloud.delivery.puppetlabs.net/ diff --git a/spec/acceptance/prefork_worker_spec.rb b/spec/acceptance/prefork_worker_spec.rb index 6ff8651661..703448a65c 100644 --- a/spec/acceptance/prefork_worker_spec.rb +++ b/spec/acceptance/prefork_worker_spec.rb @@ -1,40 +1,29 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - -describe 'prefork_worker_spec.rb' do - case host_inventory['facter']['os']['family'] - when 'FreeBSD' - describe 'apache::mod::event class' do - describe 'running puppet code' do - # Using puppet_apply as a helper - pp = <<-MANIFEEST +apache_hash = apache_settings_hash +describe 'prefork_worker_spec.rb', unless: (os[:family] =~ %r{sles}) do + describe 'apache::mod::event class' do + describe 'running puppet code' do + let(:pp) do + <<-MANIFEEST class { 'apache': mpm_module => 'event', } MANIFEEST - it 'works with no errors' do - # Run it twice and test for idempotency - apply_manifest(pp, catch_failures: true) - expect(apply_manifest(pp, catch_failures: true).exit_code).to be_zero - end end - describe service($service_name) do - it { is_expected.to be_running } - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + it 'behaves idempotently' do + idempotent_apply(pp) end end + + describe service(apache_hash['service_name']) do + it { is_expected.to be_running } + it { is_expected.to be_enabled } + end end describe 'apache::mod::worker class' do describe 'running puppet code' do - # Using puppet_apply as a helper let(:pp) do <<-MANIFEEST class { 'apache': @@ -43,19 +32,14 @@ class { 'apache': MANIFEEST end - # Run it twice and test for idempotency - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end end - describe service($service_name) do + describe service(apache_hash['service_name']) do it { is_expected.to be_running } - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + it { is_expected.to be_enabled } end end @@ -70,19 +54,14 @@ class { 'apache': MANIFEEST end - # Run it twice and test for idempotency - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end end - describe service($service_name) do + describe service(apache_hash['service_name']) do it { is_expected.to be_running } - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + it { is_expected.to be_enabled } end end end diff --git a/spec/acceptance/service_spec.rb b/spec/acceptance/service_spec.rb index ee6aa0b2a1..bcb204c520 100644 --- a/spec/acceptance/service_spec.rb +++ b/spec/acceptance/service_spec.rb @@ -12,7 +12,8 @@ class { 'apache': } MANIFEST end - # Run it twice and test for idempotency - it_behaves_like 'a idempotent resource' + it 'behaves idempotently' do + idempotent_apply(pp) + end end end diff --git a/spec/acceptance/version.rb b/spec/acceptance/version.rb deleted file mode 100644 index 6aefcec6e2..0000000000 --- a/spec/acceptance/version.rb +++ /dev/null @@ -1,93 +0,0 @@ -@osfamily = fact('osfamily') -@operatingsystem = fact('operatingsystem') -@operatingsystemrelease = fact('operatingsystemrelease').to_f - -case @osfamily -when 'RedHat' - $confd_dir = '/etc/httpd/conf.d' - $conf_file = '/etc/httpd/conf/httpd.conf' - $ports_file = '/etc/httpd/conf/ports.conf' - $vhost_dir = '/etc/httpd/conf.d' - $vhost = '/etc/httpd/conf.d/15-default.conf' - $run_dir = '/var/run/httpd' - $doc_root = '/var/www' - $service_name = 'httpd' - $package_name = 'httpd' - $error_log = 'error_log' - $suphp_handler = 'php5-script' - $suphp_configpath = 'undef' - - if (@operatingsystem == 'Fedora' && @operatingsystemrelease >= 18) || (@operatingsystem != 'Fedora' && @operatingsystemrelease >= 7) - $apache_version = '2.4' - $mod_dir = '/etc/httpd/conf.modules.d' - else - $apache_version = '2.2' - $mod_dir = '/etc/httpd/conf.d' - end -when 'Debian' - $confd_dir = '/etc/apache2/conf.d' - $mod_dir = '/etc/apache2/mods-available' - $conf_file = '/etc/apache2/apache2.conf' - $ports_file = '/etc/apache2/ports.conf' - $vhost = '/etc/apache2/sites-available/15-default.conf' - $vhost_dir = '/etc/apache2/sites-enabled' - $run_dir = '/var/run/apache2' - $doc_root = '/var/www' - $service_name = 'apache2' - $package_name = 'apache2' - $error_log = 'error.log' - $suphp_handler = 'x-httpd-php' - $suphp_configpath = '/etc/php5/apache2' - $apache_version = if @operatingsystem == 'Ubuntu' && @operatingsystemrelease >= 13.10 - '2.4' - elsif @operatingsystem == 'Debian' && @operatingsystemrelease >= 8.0 - '2.4' - else - '2.2' - end -when 'FreeBSD' - $confd_dir = '/usr/local/etc/apache24/Includes' - $mod_dir = '/usr/local/etc/apache24/Modules' - $conf_file = '/usr/local/etc/apache24/httpd.conf' - $ports_file = '/usr/local/etc/apache24/Includes/ports.conf' - $vhost = '/usr/local/etc/apache24/Vhosts/15-default.conf' - $vhost_dir = '/usr/local/etc/apache24/Vhosts' - $run_dir = '/var/run/apache24' - $doc_root = '/var/www' - $service_name = 'apache24' - $package_name = 'apache24' - $error_log = 'http-error.log' - $apache_version = '2.2' -when 'Gentoo' - $confd_dir = '/etc/apache2/conf.d' - $mod_dir = '/etc/apache2/modules.d' - $conf_file = '/etc/apache2/httpd.conf' - $ports_file = '/etc/apache2/ports.conf' - $vhost = '/etc/apache2/vhosts.d/15-default.conf' - $vhost_dir = '/etc/apache2/vhosts.d' - $run_dir = '/var/run/apache2' - $doc_root = '/var/www' - $service_name = 'apache2' - $package_name = 'www-servers/apache' - $error_log = 'http-error.log' - $apache_version = '2.4' -when 'Suse' - $confd_dir = '/etc/apache2/conf.d' - $mod_dir = '/etc/apache2/mods-available' - $conf_file = '/etc/apache2/httpd.conf' - $ports_file = '/etc/apache2/ports.conf' - $vhost = '/etc/apache2/sites-available/15-default.conf' - $vhost_dir = '/etc/apache2/sites-available' - $run_dir = '/var/run/apache2' - $doc_root = '/srv/www' - $service_name = 'apache2' - $package_name = 'apache2' - $error_log = 'error.log' - $apache_version = if @operatingsystemrelease < 12 - '2.2' - else - '2.4' - end -else - $apache_version = '0' -end diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index 434c59df43..b95400fce9 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - +apache_hash = apache_settings_hash describe 'apache::vhost define' do context 'no default vhosts' do pp = <<-MANIFEST @@ -24,11 +23,11 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/15-default.conf") do + describe file("#{apache_hash['vhost_dir']}/15-default.conf") do it { is_expected.not_to be_file } end - describe file("#{$vhost_dir}/15-default-ssl.conf") do + describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do it { is_expected.not_to be_file } end end @@ -41,36 +40,36 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/15-default.conf") do + describe file("#{apache_hash['vhost_dir']}/15-default.conf") do it { is_expected.to contain '' } end - describe file("#{$vhost_dir}/15-default-ssl.conf") do + describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do it { is_expected.not_to be_file } end end context 'default vhost with ssl' do pp = <<-MANIFEST - file { '#{$run_dir}': + file { '#{apache_hash['run_dir']}': ensure => 'directory', recurse => true, } class { 'apache': default_ssl_vhost => true, - require => File['#{$run_dir}'], + require => File['#{apache_hash['run_dir']}'], } MANIFEST it 'creates default vhost configs' do apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/15-default.conf") do + describe file("#{apache_hash['vhost_dir']}/15-default.conf") do it { is_expected.to contain '' } end - describe file("#{$vhost_dir}/15-default-ssl.conf") do + describe file("#{apache_hash['vhost_dir']}/15-default-ssl.conf") do it { is_expected.to contain '' } it { is_expected.to contain 'SSLEngine on' } end @@ -94,7 +93,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-first.example.com.conf") do + describe file("#{apache_hash['vhost_dir']}/25-first.example.com.conf") do it { is_expected.to contain '' } it { is_expected.to contain 'ServerName first.example.com' } end @@ -117,7 +116,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-proxy.example.com.conf") do + describe file("#{apache_hash['vhost_dir']}/25-proxy.example.com.conf") do it { is_expected.to contain '' } it { is_expected.to contain 'ServerName proxy.example.com' } it { is_expected.to contain 'ProxyPass' } @@ -133,7 +132,7 @@ class { 'apache': } class { 'apache': } apache::vhost { 'proxy.example.com': port => '80', - docroot => '#{$docroot}/proxy', + docroot => '#{apache_hash['doc_root']}/proxy', proxy_pass_match => [ { 'path' => '/foo', 'url' => 'http://backend-foo/'}, ], @@ -145,7 +144,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-proxy.example.com.conf") do + describe file("#{apache_hash['vhost_dir']}/25-proxy.example.com.conf") do it { is_expected.to contain '' } it { is_expected.to contain 'ServerName proxy.example.com' } it { is_expected.to contain 'ProxyPassMatch /foo http://backend-foo/' } @@ -156,173 +155,6 @@ class { 'apache': } end end - context 'new vhost on port 80' do - pp = <<-MANIFEST - class { 'apache': } - apache::vhost { 'first.example.com': - port => '80', - docroot => '/var/www/first', - } - host { 'first.example.com': ip => '127.0.0.1', } - file { '/var/www/first/index.html': - ensure => file, - content => "Hello from first\\n", - } - apache::vhost { 'second.example.com': - port => '80', - docroot => '/var/www/second', - } - host { 'second.example.com': ip => '127.0.0.1', } - file { '/var/www/second/index.html': - ensure => file, - content => "Hello from second\\n", - } - MANIFEST - it 'configures two apache vhosts' do - apply_manifest(pp, catch_failures: true) - end - - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end - it { is_expected.to be_running } - end - - it 'answers to first.example.com' do - shell('/usr/bin/curl first.example.com:80', acceptable_exit_codes: 0) do |r| - expect(r.stdout).to eq("Hello from first\n") - end - end - - it 'answers to second.example.com' do - shell('/usr/bin/curl second.example.com:80', acceptable_exit_codes: 0) do |r| - expect(r.stdout).to eq("Hello from second\n") - end - end - end - - context 'new vhost with multiple IP addresses on port 80' do - pp = <<-MANIFEST - class { 'apache': - default_vhost => false, - } - apache::vhost { 'example.com': - port => '80', - ip => ['127.0.0.1','127.0.0.2'], - ip_based => true, - docroot => '/var/www/html', - } - host { 'host1.example.com': ip => '127.0.0.1', } - host { 'host2.example.com': ip => '127.0.0.2', } - file { '/var/www/html/index.html': - ensure => file, - content => "Hello from vhost\\n", - } - MANIFEST - it 'configures one apache vhost with 2 ip addresses' do - apply_manifest(pp, catch_failures: true) - end - - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end - it { is_expected.to be_running } - end - - describe file("#{$vhost_dir}/25-example.com.conf") do - it { is_expected.to contain '' } - it { is_expected.to contain 'ServerName example.com' } - end - - describe file($ports_file) do - it { is_expected.to be_file } - it { is_expected.to contain 'Listen 127.0.0.1:80' } - it { is_expected.to contain 'Listen 127.0.0.2:80' } - it { is_expected.not_to contain 'NameVirtualHost 127.0.0.1:80' } - it { is_expected.not_to contain 'NameVirtualHost 127.0.0.2:80' } - end - - it 'answers to host1.example.com' do - shell('/usr/bin/curl host1.example.com:80', acceptable_exit_codes: 0) do |r| - expect(r.stdout).to eq("Hello from vhost\n") - end - end - - it 'answers to host2.example.com' do - shell('/usr/bin/curl host2.example.com:80', acceptable_exit_codes: 0) do |r| - expect(r.stdout).to eq("Hello from vhost\n") - end - end - end - - context 'new vhost with multiple ports on 1 IP address' do - pp = <<-MANIFEST - class { 'apache': - default_vhost => false, - } - apache::vhost { 'example.com': - port => ['80','8080'], - ip => '127.0.0.1', - ip_based => true, - docroot => '/var/www/html', - } - host { 'host1.example.com': ip => '127.0.0.1', } - file { '/var/www/html/index.html': - ensure => file, - content => "Hello from vhost\\n", - } - MANIFEST - it 'configures one apache vhost with 2 ports' do - apply_manifest(pp, catch_failures: true) - end - - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end - it { is_expected.to be_running } - end - - describe file("#{$vhost_dir}/25-example.com.conf") do - it { is_expected.to contain '' } - it { is_expected.to contain 'ServerName example.com' } - end - - describe file($ports_file) do - it { is_expected.to be_file } - it { is_expected.to contain 'Listen 127.0.0.1:80' } - it { is_expected.to contain 'Listen 127.0.0.1:8080' } - it { is_expected.not_to contain 'NameVirtualHost 127.0.0.1:80' } - it { is_expected.not_to contain 'NameVirtualHost 127.0.0.1:8080' } - end - - it 'answers to host1.example.com port 80' do - shell('/usr/bin/curl host1.example.com:80', acceptable_exit_codes: 0) do |r| - expect(r.stdout).to eq("Hello from vhost\n") - end - end - - it 'answers to host1.example.com port 8080' do - shell('/usr/bin/curl host1.example.com:8080', acceptable_exit_codes: 0) do |r| - expect(r.stdout).to eq("Hello from vhost\n") - end - end - end - context 'new vhost with multiple IP addresses on multiple ports' do pp = <<-MANIFEST class { 'apache': @@ -345,23 +177,17 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end - describe file("#{$vhost_dir}/25-example.com.conf") do + describe file("#{apache_hash['vhost_dir']}/25-example.com.conf") do it { is_expected.to contain '' } it { is_expected.to contain 'ServerName example.com' } end - describe file($ports_file) do + describe file(apache_hash['ports_file']) do it { is_expected.to be_file } it { is_expected.to contain 'Listen 127.0.0.1:80' } it { is_expected.to contain 'Listen 127.0.0.1:8080' } @@ -374,25 +200,25 @@ class { 'apache': end it 'answers to host1.example.com port 80' do - shell('/usr/bin/curl host1.example.com:80', acceptable_exit_codes: 0) do |r| + run_shell('/usr/bin/curl host1.example.com:80', acceptable_exit_codes: 0) do |r| expect(r.stdout).to eq("Hello from vhost\n") end end it 'answers to host1.example.com port 8080' do - shell('/usr/bin/curl host1.example.com:8080', acceptable_exit_codes: 0) do |r| + run_shell('/usr/bin/curl host1.example.com:8080', acceptable_exit_codes: 0) do |r| expect(r.stdout).to eq("Hello from vhost\n") end end it 'answers to host2.example.com port 80' do - shell('/usr/bin/curl host2.example.com:80', acceptable_exit_codes: 0) do |r| + run_shell('/usr/bin/curl host2.example.com:80', acceptable_exit_codes: 0) do |r| expect(r.stdout).to eq("Hello from vhost\n") end end it 'answers to host2.example.com port 8080' do - shell('/usr/bin/curl host2.example.com:8080', acceptable_exit_codes: 0) do |r| + run_shell('/usr/bin/curl host2.example.com:8080', acceptable_exit_codes: 0) do |r| expect(r.stdout).to eq("Hello from vhost\n") end end @@ -419,85 +245,78 @@ class { 'apache': apply_manifest(pp, catch_failures: true) end - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end - describe file("#{$vhost_dir}/25-example.com.conf") do + describe file("#{apache_hash['vhost_dir']}/25-example.com.conf") do it { is_expected.to contain '' } it { is_expected.to contain 'ServerName example.com' } end - describe file($ports_file) do + describe file(apache_hash['ports_file']) do it { is_expected.to be_file } it { is_expected.to contain 'Listen [::1]:80' } it { is_expected.not_to contain 'NameVirtualHost [::1]:80' } end it 'answers to ipv6.example.com' do - shell('/usr/bin/curl ipv6.example.com:80', acceptable_exit_codes: 0) do |r| + run_shell('/usr/bin/curl ipv6.example.com:80', acceptable_exit_codes: 0) do |r| expect(r.stdout).to eq("Hello from vhost\n") end end end context 'apache_directories' do - describe 'readme example, adapted' do - pp = <<-MANIFEST - class { 'apache': } + let(:pp) do + <<-MANIFEST + class { 'apache': } - if versioncmp($apache_version, '2.4') >= 0 { - $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'require' => 'all denied', } - } else { - $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'deny' => 'from all', } - } + if versioncmp('#{apache_hash['version']}', '2.4') >= 0 { + $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'require' => 'all denied', } + } else { + $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'deny' => 'from all', } + } - $_directories = [ - { 'path' => '/var/www/files', }, - $_files_match_directory, - ] + $_directories = [ + { 'path' => '/var/www/files', }, + $_files_match_directory, + ] - apache::vhost { 'files.example.net': - docroot => '/var/www/files', - directories => $_directories, - } - file { '/var/www/files/index.html': - ensure => file, - content => "Hello World\\n", - } - file { '/var/www/files/index.html.bak': - ensure => file, - content => "Hello World\\n", - } - host { 'files.example.net': ip => '127.0.0.1', } - MANIFEST + apache::vhost { 'files.example.net': + docroot => '/var/www/files', + directories => $_directories, + } + file { '/var/www/files/index.html': + ensure => file, + content => "Hello World\\n", + } + file { '/var/www/files/index.html.bak': + ensure => file, + content => "Hello World\\n", + } + host { 'files.example.net': ip => '127.0.0.1', } + MANIFEST + end + + describe 'readme example, adapted' do it 'configures a vhost with Files' do apply_manifest(pp, catch_failures: true) end - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end it 'answers to files.example.net #stdout' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/index.html').stdout).to eq("Hello World\n") + expect(run_shell('/usr/bin/curl -sSf files.example.net:80/index.html').stdout).to eq("Hello World\n") end it 'answers to files.example.net #stderr' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/index.html.bak', acceptable_exit_codes: 22).stderr).to match(%r{curl: \(22\) The requested URL returned error: 403}) + result = run_shell('/usr/bin/curl -sSf files.example.net:80/index.html.bak', expect_failures: true) + expect(result.stderr).to match(%r{curl: \(22\) The requested URL returned error: 403}) + expect(result.exit_code).to eq 22 end end @@ -548,28 +367,24 @@ class { 'apache': } apply_manifest(pp_one, catch_failures: true) end - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end it 'answers to files.example.net #stdout' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/').stdout).to eq("Hello World\n") + expect(run_shell('/usr/bin/curl -sSf files.example.net:80/').stdout).to eq("Hello World\n") end it 'answers to files.example.net #stdout foo' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/foo/').stdout).to eq("Hello Foo\n") + expect(run_shell('/usr/bin/curl -sSf files.example.net:80/foo/').stdout).to eq("Hello Foo\n") end it 'answers to files.example.net #stderr' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/private.html', acceptable_exit_codes: 22).stderr).to match(%r{curl: \(22\) The requested URL returned error: 403}) + result = run_shell('/usr/bin/curl -sSf files.example.net:80/private.html', expect_failures: true) + expect(result.stderr).to match(%r{curl: \(22\) The requested URL returned error: 403}) + expect(result.exit_code).to eq 22 end it 'answers to files.example.net #stdout bar' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/bar/bar.html').stdout).to eq("Hello Bar\n") + expect(run_shell('/usr/bin/curl -sSf files.example.net:80/bar/bar.html').stdout).to eq("Hello Bar\n") end end @@ -594,26 +409,20 @@ class { 'apache': } apply_manifest(pp_two, catch_failures: true) end - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end it 'answers to files.example.net #stdout' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/index.html').stdout).to eq("Hello World\n") + expect(run_shell('/usr/bin/curl -sSf files.example.net:80/index.html').stdout).to eq("Hello World\n") end it 'answers to files.example.net #stdout regex' do - expect(shell('/usr/bin/curl -sSf files.example.net:80/server-status?auto').stdout).to match(%r{Scoreboard: }) + expect(run_shell('/usr/bin/curl -sSf files.example.net:80/server-status?auto').stdout).to match(%r{Scoreboard: }) end end - describe 'Satisfy and Auth directive', unless: $apache_version == '2.4' do + describe 'Satisfy and Auth directive', unless: apache_hash['version'] == '2.4' do pp_two = <<-MANIFEST class { 'apache': } host { 'files.example.net': ip => '127.0.0.1', } @@ -676,63 +485,21 @@ class { 'apache': } apply_manifest(pp_two, catch_failures: true) end - describe service($service_name) do - if fact('operatingsystem') == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif fact('operatingsystem') == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } it 'answers to files.example.net' do - shell('/usr/bin/curl -sSf files.example.net:80/foo/index.html', acceptable_exit_codes: 22).stderr.should match(%r{curl: \(22\) The requested URL returned error: 401}) - shell('/usr/bin/curl -sSf -u login:password files.example.net:80/foo/index.html').stdout.should eq("Hello World\n") - shell('/usr/bin/curl -sSf files.example.net:80/bar/index.html').stdout.should eq("Hello World\n") - shell('/usr/bin/curl -sSf -u login:password files.example.net:80/bar/index.html').stdout.should eq("Hello World\n") - shell('/usr/bin/curl -sSf files.example.net:80/baz/index.html', acceptable_exit_codes: 22).stderr.should match(%r{curl: \(22\) The requested URL returned error: 401}) - shell('/usr/bin/curl -sSf -u login:password files.example.net:80/baz/index.html').stdout.should eq("Hello World\n") - end - end - end - end - - unless host_inventory['facter']['os']['distro'].nil? - case host_inventory['facter']['os']['distro']['codename'] - when 'precise', 'wheezy' - context 'vhost FallbackResource example' do - pp = <<-MANIFEST - class { 'apache': } - apache::vhost { 'fallback.example.net': - docroot => '/var/www/fallback', - fallbackresource => '/index.html' - } - file { '/var/www/fallback/index.html': - ensure => file, - content => "Hello World\\n", - } - host { 'fallback.example.net': ip => '127.0.0.1', } - MANIFEST - it 'configures a vhost with FallbackResource' do - apply_manifest(pp, catch_failures: true) - end - - describe service($service_name) do - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end - it { is_expected.to be_running } - end - - it 'answers to fallback.example.net' do - shell('/usr/bin/curl fallback.example.net:80/Does/Not/Exist') do |r| - expect(r.stdout).to eq("Hello World\n") - end + result = run_shell('/usr/bin/curl -sSf files.example.net:80/foo/index.html', expect_failures: true) + expect(result.stderr).to match(%r{curl: \(22\) The requested URL returned error: 401}) + expect(result.exit_code).to eq 22 + expect(run_shell('/usr/bin/curl -sSf -u login:password files.example.net:80/foo/index.html').stdout).to eq("Hello World\n") + expect(run_shell('/usr/bin/curl -sSf files.example.net:80/bar/index.html').stdout).to eq("Hello World\n") + expect(run_shell('/usr/bin/curl -sSf -u login:password files.example.net:80/bar/index.html').stdout).to eq("Hello World\n") + result = run_shell('/usr/bin/curl -sSf files.example.net:80/baz/index.html', expect_failures: true) + expect(result.stderr).to match(%r{curl: \(22\) The requested URL returned error: 401}) + expect(result.exit_code).to eq 22 + expect(run_shell('/usr/bin/curl -sSf -u login:password files.example.net:80/baz/index.html').stdout).to eq("Hello World\n") end end end @@ -759,25 +526,19 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe service($service_name) do - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end it 'answers to a.virt.example.com' do - shell('/usr/bin/curl a.virt.example.com:80', acceptable_exit_codes: 0) do |r| + run_shell('/usr/bin/curl a.virt.example.com:80', acceptable_exit_codes: 0) do |r| expect(r.stdout).to eq("Hello from a.virt\n") end end it 'answers to b.virt.example.com' do - shell('/usr/bin/curl b.virt.example.com:80', acceptable_exit_codes: 0) do |r| + run_shell('/usr/bin/curl b.virt.example.com:80', acceptable_exit_codes: 0) do |r| expect(r.stdout).to eq("Hello from b.virt\n") end end @@ -811,24 +572,18 @@ class { 'apache': default_vhost => false, } ), catch_failures: true) end - describe service($service_name) do - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end it 'gets a response from the back end #stdout' do - shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| + run_shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| expect(r.stdout).to eq("Hello from localhost\n") end end it 'gets a response from the back end #exit_code' do - shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| + run_shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| expect(r.exit_code).to eq(0) end end @@ -862,24 +617,18 @@ class { 'apache': default_vhost => false, } ), catch_failures: true) end - describe service($service_name) do - if host_inventory['facter']['os']['name'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' - pending 'Should be enabled - Bug 760616 on Debian 8' - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pending 'Should be enabled - MODULES-8379 `be_enabled` check does not currently work for apache2 on SLES 15' - else - it { is_expected.to be_enabled } - end + describe service(apache_hash['service_name']) do + it { is_expected.to be_enabled } it { is_expected.to be_running } end it 'gets a response from the back end #stdout' do - shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| + run_shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| expect(r.stdout).to eq("Hello from localhost\n") end end it 'gets a response from the back end #exit_code' do - shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| + run_shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| expect(r.exit_code).to eq(0) end end @@ -899,11 +648,11 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file($ports_file) do + describe file(apache_hash['ports_file']) do it { is_expected.to be_file } it { is_expected.not_to contain 'NameVirtualHost test.server' } end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'ServerName test.server' } end @@ -923,11 +672,11 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file($ports_file) do + describe file(apache_hash['ports_file']) do it { is_expected.to be_file } it { is_expected.not_to contain 'NameVirtualHost test.server' } end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.not_to contain 'ServerName' } end @@ -949,7 +698,7 @@ class { 'apache': default_vhost => false } apply_manifest(pp, catch_failures: true) end - describe file($ports_file) do + describe file(apache_hash['ports_file']) do it { is_expected.to be_file } it { is_expected.not_to contain 'Listen 80' } it { is_expected.to contain 'Listen 81' } @@ -994,77 +743,209 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file($ports_file) do + describe file(apache_hash['ports_file']) do it { is_expected.to be_file } - if fact('osfamily') == 'RedHat' && host_inventory['facter']['os']['release']['major'] == '7' || - fact('osfamily') == 'Debian' || - host_inventory['facter']['os']['name'] == 'SLES' && fact('operatingsystemrelease') >= '12' - it { is_expected.not_to contain 'NameVirtualHost test.server' } - else - it { is_expected.to contain 'NameVirtualHost test.server' } - end end - describe file("#{$vhost_dir}/10-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/10-test.server.conf") do it { is_expected.to be_file } end end - describe 'options' do + describe 'parameter tests' do pp = <<-MANIFEST class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - options => ['Indexes','FollowSymLinks', 'ExecCGI'], + host { 'test.itk': ip => '127.0.0.1' } + apache::vhost { 'test.itk': + docroot => '/tmp', + itk => { user => 'nobody', group => 'nobody' } } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'Options Indexes FollowSymLinks ExecCGI' } - end - end - - describe 'override' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': + host { 'test.custom_fragment': ip => '127.0.0.1' } + apache::vhost { 'test.custom_fragment': + docroot => '/tmp', + custom_fragment => inline_template('#weird test string'), + } + apache::vhost { 'test.without_priority_prefix': + priority => false, + docroot => '/tmp' + } + apache::vhost { 'test.ssl_protool': + docroot => '/tmp', + ssl => true, + ssl_protocol => ['All', '-SSLv2'], + } + apache::vhost { 'test.block': + docroot => '/tmp', + block => 'scm', + } + apache::vhost { 'test.setenv_setenvif': + docroot => '/tmp', + setenv => ['TEST /test'], + setenvif => ['Request_URI "\.gif$" object_is_image=gif'] + } + apache::vhost { 'test.rewrite': + docroot => '/tmp', + rewrites => [ + { comment => 'test', + rewrite_cond => '%{HTTP_USER_AGENT} ^Lynx/ [OR]', + rewrite_rule => ['^index\.html$ welcome.html'], + rewrite_map => ['lc int:tolower'], + } + ], + } + apache::vhost { 'test.request_headers': + docroot => '/tmp', + request_headers => ['append MirrorID "mirror 12"'], + } + apache::vhost { 'test.redirect': + docroot => '/tmp', + redirect_source => ['/images'], + redirect_dest => ['http://test.server/'], + redirect_status => ['permanent'], + } + apache::vhost { 'test.no_proxy_uris': + docroot => '/tmp', + proxy_dest => 'http://test2', + no_proxy_uris => [ 'http://test2/test' ], + } + apache::vhost { 'test.proxy': docroot => '/tmp', - override => ['All'], + proxy_dest => 'test2', } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'AllowOverride All' } - end - end - - describe 'logroot' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': + apache::vhost { 'test.scriptaliases': docroot => '/tmp', - logroot => '/tmp', + scriptaliases => [{ alias => '/myscript', path => '/usr/share/myscript', }], } - MANIFEST + apache::vhost { 'test.aliases': + docroot => '/tmp', + aliases => [ + { alias => '/image' , path => '/ftp/pub/image' } , + { scriptalias => '/myscript' , path => '/usr/share/myscript' } + ], + } + apache::vhost { 'test.access_logs': + docroot => '/tmp', + logroot => '/tmp', + access_logs => [ + {'file' => 'log1'}, + {'file' => 'log2', 'env' => 'admin' }, + {'file' => '/var/tmp/log3', 'format' => '%h %l'}, + {'syslog' => 'syslog' } + ] + } + apache::vhost { 'test.access_log_env_var': + docroot => '/tmp', + logroot => '/tmp', + access_log_syslog => 'syslog', + access_log_env_var => 'admin', + } + apache::vhost { 'test.access_log_format': + docroot => '/tmp', + logroot => '/tmp', + access_log_syslog => 'syslog', + access_log_format => '%h %l', + } + apache::vhost { 'test.logroot': + docroot => '/tmp', + logroot => '/tmp', + } + apache::vhost { 'test.override': + docroot => '/tmp', + override => ['All'], + } + apache::vhost { 'test.options': + docroot => '/tmp', + options => ['Indexes','FollowSymLinks', 'ExecCGI'], + } + MANIFEST it 'applies cleanly' do apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.itk.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'AssignUserId nobody nobody' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.custom_fragment.conf") do + it { is_expected.to be_file } + it { is_expected.to contain '#weird test string' } + end + describe file("#{apache_hash['vhost_dir']}/test.without_priority_prefix.conf") do + it { is_expected.to be_file } + end + describe file("#{apache_hash['vhost_dir']}/25-test.ssl_protool.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'SSLProtocol *All -SSLv2' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.block.conf") do + it { is_expected.to be_file } + it { is_expected.to contain '' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.setenv_setenvif.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'SetEnv TEST /test' } + it { is_expected.to contain 'SetEnvIf Request_URI "\.gif$" object_is_image=gif' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.rewrite.conf") do + it { is_expected.to be_file } + it { is_expected.to contain '#test' } + it { is_expected.to contain 'RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [OR]' } + it { is_expected.to contain 'RewriteRule ^index.html$ welcome.html' } + it { is_expected.to contain 'RewriteMap lc int:tolower' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.request_headers.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'append MirrorID "mirror 12"' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.redirect.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'Redirect permanent /images http://test.server/' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.no_proxy_uris.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'ProxyPass http://test2/test !' } + it { is_expected.to contain 'ProxyPass / http://test2/' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.proxy.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'ProxyPass / test2/' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.scriptaliases.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.aliases.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'Alias /image "/ftp/pub/image"' } + it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.access_logs.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'CustomLog "/tmp/log1" combined' } + it { is_expected.to contain 'CustomLog "/tmp/log2" combined env=admin' } + it { is_expected.to contain 'CustomLog "/var/tmp/log3" "%h %l"' } + it { is_expected.to contain 'CustomLog "syslog" combined' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.access_log_env_var.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'CustomLog "syslog" combined env=admin' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.access_log_format.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'CustomLog "syslog" "%h %l"' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.logroot.conf") do it { is_expected.to be_file } it { is_expected.to contain ' CustomLog "/tmp' } end + describe file("#{apache_hash['vhost_dir']}/25-test.override.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'AllowOverride All' } + end + describe file("#{apache_hash['vhost_dir']}/25-test.options.conf") do + it { is_expected.to be_file } + it { is_expected.to contain 'Options Indexes FollowSymLinks ExecCGI' } + end end ['access', 'error'].each do |logtype| @@ -1089,7 +970,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.not_to contain " #{logname} \"/tmp" } end @@ -1109,7 +990,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain " #{logname} \"|/bin/sh" } end @@ -1129,144 +1010,13 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain " #{logname} \"syslog\"" } end end end - describe 'access_log_format' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - logroot => '/tmp', - access_log_syslog => 'syslog', - access_log_format => '%h %l', - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'CustomLog "syslog" "%h %l"' } - end - end - - describe 'access_log_env_var' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - logroot => '/tmp', - access_log_syslog => 'syslog', - access_log_env_var => 'admin', - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'CustomLog "syslog" combined env=admin' } - end - end - - describe 'multiple access_logs' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - logroot => '/tmp', - access_logs => [ - {'file' => 'log1'}, - {'file' => 'log2', 'env' => 'admin' }, - {'file' => '/var/tmp/log3', 'format' => '%h %l'}, - {'syslog' => 'syslog' } - ] - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'CustomLog "/tmp/log1" combined' } - it { is_expected.to contain 'CustomLog "/tmp/log2" combined env=admin' } - it { is_expected.to contain 'CustomLog "/var/tmp/log3" "%h %l"' } - it { is_expected.to contain 'CustomLog "syslog" combined' } - end - end - - describe 'aliases' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - aliases => [ - { alias => '/image' , path => '/ftp/pub/image' } , - { scriptalias => '/myscript' , path => '/usr/share/myscript' } - ], - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'Alias /image "/ftp/pub/image"' } - it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' } - end - end - - describe 'scriptaliases' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - scriptaliases => [{ alias => '/myscript', path => '/usr/share/myscript', }], - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' } - end - end - - describe 'proxy' do - pp = <<-MANIFEST - class { 'apache': service_ensure => stopped, } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - proxy_dest => 'test2', - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'ProxyPass / test2/' } - end - end - describe 'actions' do pp = <<-MANIFEST class { 'apache': } @@ -1277,11 +1027,11 @@ class { 'apache': } } MANIFEST it 'applies cleanly' do - pp += "\nclass { 'apache::mod::actions': }" if fact('osfamily') == 'Debian' || fact('osfamily') == 'Suse' + pp += "\nclass { 'apache::mod::actions': }" if os[:family] =~ %r{debian|suse} apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'Action php-fastcgi /cgi-bin virtual' } end @@ -1293,128 +1043,20 @@ class { 'apache': service_ensure => stopped, } host { 'test.server': ip => '127.0.0.1' } apache::vhost { 'test.server': docroot => '/tmp', - suphp_addhandler => '#{$suphp_handler}', + suphp_addhandler => '#{apache_hash['suphp_handler']}', suphp_engine => 'on', - suphp_configpath => '#{$suphp_configpath}', + suphp_configpath => '#{apache_hash['suphp_configpath']}', } MANIFEST it 'applies cleanly' do apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } - it { is_expected.to contain "suPHP_AddHandler #{$suphp_handler}" } + it { is_expected.to contain "suPHP_AddHandler #{apache_hash['suphp_handler']}" } it { is_expected.to contain 'suPHP_Engine on' } - it { is_expected.to contain "suPHP_ConfigPath \"#{$suphp_configpath}\"" } - end - end - - describe 'rack_base_uris' do - unless fact('osfamily') == 'RedHat' || host_inventory['facter']['os']['name'] == 'SLES' - test = -> do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - rack_base_uris => ['/test'], - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - test.call - end - end - end - - describe 'no_proxy_uris' do - pp = <<-MANIFEST - class { 'apache': service_ensure => stopped, } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - proxy_dest => 'http://test2', - no_proxy_uris => [ 'http://test2/test' ], - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'ProxyPass http://test2/test !' } - it { is_expected.to contain 'ProxyPass / http://test2/' } - end - end - - describe 'redirect' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - redirect_source => ['/images'], - redirect_dest => ['http://test.server/'], - redirect_status => ['permanent'], - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'Redirect permanent /images http://test.server/' } - end - end - - describe 'request_headers' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - request_headers => ['append MirrorID "mirror 12"'], - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'append MirrorID "mirror 12"' } - end - end - - describe 'rewrite rules' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - rewrites => [ - { comment => 'test', - rewrite_cond => '%{HTTP_USER_AGENT} ^Lynx/ [OR]', - rewrite_rule => ['^index\.html$ welcome.html'], - rewrite_map => ['lc int:tolower'], - } - ], - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain '#test' } - it { is_expected.to contain 'RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [OR]' } - it { is_expected.to contain 'RewriteRule ^index.html$ welcome.html' } - it { is_expected.to contain 'RewriteMap lc int:tolower' } + it { is_expected.to contain "suPHP_ConfigPath \"#{apache_hash['suphp_configpath']}\"" } end end @@ -1448,7 +1090,7 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain '#Permalink Rewrites' } it { is_expected.to contain 'RewriteEngine On' } @@ -1460,207 +1102,39 @@ class { 'apache': } end end - describe 'setenv/setenvif' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - setenv => ['TEST /test'], - setenvif => ['Request_URI "\.gif$" object_is_image=gif'] - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'SetEnv TEST /test' } - it { is_expected.to contain 'SetEnvIf Request_URI "\.gif$" object_is_image=gif' } - end - end - - describe 'block' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - block => 'scm', - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain '' } - end - end - describe 'wsgi' do - unless host_inventory['facter']['os']['distro'].nil? - context 'on lucid', if: host_inventory['facter']['os']['distro']['codename'] == 'lucid' do - pp = <<-MANIFEST - class { 'apache': } - class { 'apache::mod::wsgi': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - wsgi_application_group => '%{GLOBAL}', - wsgi_daemon_process => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} }, - wsgi_daemon_process_options => {processes => '2'}, - wsgi_process_group => 'nobody', - wsgi_script_aliases => { '/test' => '/test1' }, - wsgi_script_aliases_match => { '/test/([^/*])' => '/test1' }, - wsgi_pass_authorization => 'On', - } - MANIFEST - it 'import_script applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - end - - context 'on everything but lucid', unless: (host_inventory['facter']['os']['distro']['codename'] == 'lucid' || host_inventory['facter']['os']['name'] == 'SLES') do - pp = <<-MANIFEST - class { 'apache': } - class { 'apache::mod::wsgi': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - wsgi_application_group => '%{GLOBAL}', - wsgi_daemon_process => { 'wsgi' => { 'python-home' => '/usr' }, 'foo' => {} }, - wsgi_daemon_process_options => {processes => '2'}, - wsgi_import_script => '/test1', - wsgi_import_script_options => { application-group => '%{GLOBAL}', process-group => 'wsgi' }, - wsgi_process_group => 'nobody', - wsgi_script_aliases => { '/test' => '/test1' }, - wsgi_script_aliases_match => { '/test/([^/*])' => '/test1' }, - wsgi_pass_authorization => 'On', - wsgi_chunked_request => 'On', - } - MANIFEST - it 'import_script applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'WSGIApplicationGroup %{GLOBAL}' } - it { is_expected.to contain 'WSGIDaemonProcess foo' } - it { is_expected.to contain 'WSGIDaemonProcess wsgi python-home=/usr' } - it { is_expected.to contain 'WSGIImportScript /test1 application-group=%{GLOBAL} process-group=wsgi' } - it { is_expected.to contain 'WSGIProcessGroup nobody' } - it { is_expected.to contain 'WSGIScriptAlias /test "/test1"' } - it { is_expected.to contain 'WSGIPassAuthorization On' } - it { is_expected.to contain 'WSGIChunkedRequest On' } - end - end - end - end - - describe 'custom_fragment' do - pp = <<-MANIFEST - class { 'apache': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - custom_fragment => inline_template('#weird test string'), - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain '#weird test string' } - end - end - - describe 'itk' do - pp = <<-MANIFEST + context 'filter on OS', unless: (os[:family] =~ %r{sles|redhat}) do + pp = <<-MANIFEST class { 'apache': } + class { 'apache::mod::wsgi': } host { 'test.server': ip => '127.0.0.1' } apache::vhost { 'test.server': - docroot => '/tmp', - itk => { user => 'nobody', group => 'nobody' } + docroot => '/tmp', + wsgi_application_group => '%{GLOBAL}', + wsgi_daemon_process => { 'wsgi' => { 'python-home' => '/usr' }, 'foo' => {} }, + wsgi_daemon_process_options => {processes => '2'}, + wsgi_import_script => '/test1', + wsgi_import_script_options => { application-group => '%{GLOBAL}', process-group => 'wsgi' }, + wsgi_process_group => 'nobody', + wsgi_script_aliases => { '/test' => '/test1' }, + wsgi_script_aliases_match => { '/test/([^/*])' => '/test1' }, + wsgi_pass_authorization => 'On', + wsgi_chunked_request => 'On', } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'AssignUserId nobody nobody' } - end - end - - # Limit testing to Debian, since Centos does not have fastcgi package. - # In addition Debian 9/Ubuntu 18.04 no longer support this fastcgi - if fact('osfamily') == 'Debian' && !['9', '18.04'].include?(host_inventory['facter']['os']['release']['major']) - describe 'fastcgi' do - pp_one = <<-MANIFEST - $_os = $::operatingsystem - - if $_os == 'Ubuntu' { - $_location = "http://archive.ubuntu.com/ubuntu/" - $_security_location = "http://archive.ubuntu.com/ubuntu/" - $_release = $::lsbdistcodename - $_release_security = "${_release}-security" - $_repos = "main universe multiverse" - } else { - $_location = "http://httpredir.debian.org/debian/" - $_security_location = "http://security.debian.org/" - $_release = $::lsbdistcodename - $_release_security = "${_release}/updates" - $_repos = "main contrib non-free" - } - - include ::apt - apt::source { "${_os}_${_release}": - location => $_location, - release => $_release, - repos => $_repos, - } - - apt::source { "${_os}_${_release}-updates": - location => $_location, - release => "${_release}-updates", - repos => $_repos, - } - - apt::source { "${_os}_${_release}-security": - location => $_security_location, - release => $_release_security, - repos => $_repos, - } - MANIFEST - pp_two = <<-MANIFEST - class { 'apache': } - class { 'apache::mod::fastcgi': } - host { 'test.server': ip => '127.0.0.1' } - apache::vhost { 'test.server': - docroot => '/tmp', - fastcgi_server => 'localhost', - fastcgi_socket => '/tmp/fast/1234', - fastcgi_dir => '/tmp/fast', - } MANIFEST - it 'applies cleanly' do - # apt-get update may not run clean here. Should be OK. - apply_manifest(pp_one, catch_failures: false) - - apply_manifest(pp_two, catch_failures: true, acceptable_exit_codes: [0, 2]) + it 'import_script applies cleanly' do + apply_manifest(pp, catch_failures: true) end - - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } - it { is_expected.to contain 'FastCgiExternalServer localhost -socket /tmp/fast/1234' } - it { is_expected.to contain '' } + it { is_expected.to contain 'WSGIApplicationGroup %{GLOBAL}' } + it { is_expected.to contain 'WSGIDaemonProcess foo' } + it { is_expected.to contain 'WSGIDaemonProcess wsgi python-home=/usr' } + it { is_expected.to contain 'WSGIImportScript /test1 application-group=%{GLOBAL} process-group=wsgi' } + it { is_expected.to contain 'WSGIProcessGroup nobody' } + it { is_expected.to contain 'WSGIScriptAlias /test "/test1"' } + it { is_expected.to contain 'WSGIPassAuthorization On' } + it { is_expected.to contain 'WSGIChunkedRequest On' } end end end @@ -1698,59 +1172,13 @@ class { 'apache': } apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'Include "/apache_spec/include"' } end end - describe 'virtualhost without priority prefix' do - pp = <<-MANIFEST - class { 'apache': } - apache::vhost { 'test.server': - priority => false, - docroot => '/tmp' - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/test.server.conf") do - it { is_expected.to be_file } - end - end - - describe 'SSLProtocol directive' do - pp = <<-MANIFEST - class { 'apache': } - apache::vhost { 'test.server': - docroot => '/tmp', - ssl => true, - ssl_protocol => ['All', '-SSLv2'], - } - apache::vhost { 'test2.server': - docroot => '/tmp', - ssl => true, - ssl_protocol => 'All -SSLv2', - } - MANIFEST - it 'applies cleanly' do - apply_manifest(pp, catch_failures: true) - end - - describe file("#{$vhost_dir}/25-test.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'SSLProtocol *All -SSLv2' } - end - - describe file("#{$vhost_dir}/25-test2.server.conf") do - it { is_expected.to be_file } - it { is_expected.to contain 'SSLProtocol *All -SSLv2' } - end - end - - describe 'shibboleth parameters', if: (fact('osfamily') == 'Debian' && host_inventory['facter']['os']['release']['major'] != '7') do + describe 'shibboleth parameters', if: (os[:family] == 'debian' && os[:release] != '7') do # Debian 7 is too old for ShibCompatValidUser pp = <<-MANIFEST class { 'apache': } @@ -1764,7 +1192,7 @@ class { 'apache::mod::shib': } it 'applies cleanly' do apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-test.server.conf") do + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'ShibCompatValidUser On' } end diff --git a/spec/acceptance/vhosts_spec.rb b/spec/acceptance/vhosts_spec.rb index 9c49c5b173..3051700352 100644 --- a/spec/acceptance/vhosts_spec.rb +++ b/spec/acceptance/vhosts_spec.rb @@ -1,6 +1,5 @@ require 'spec_helper_acceptance' -require_relative './version.rb' - +apache_hash = apache_settings_hash describe 'apache::vhosts class' do context 'custom vhosts defined via class apache::vhosts' do pp = <<-MANIFEST @@ -21,11 +20,11 @@ class { 'apache::vhosts': apply_manifest(pp, catch_failures: true) end - describe file("#{$vhost_dir}/25-custom_vhost_1.conf") do + describe file("#{apache_hash['vhost_dir']}/25-custom_vhost_1.conf") do it { is_expected.to contain '' } end - describe file("#{$vhost_dir}/25-custom_vhost_2.conf") do + describe file("#{apache_hash['vhost_dir']}/25-custom_vhost_2.conf") do it { is_expected.to contain '' } end end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e98ad28ebb..745d46e1b0 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,102 +1,59 @@ -require 'beaker-pe' -require 'beaker-puppet' -require 'puppet' -require 'beaker-rspec/spec_helper' -require 'beaker-rspec/helpers/serverspec' -require 'beaker/puppet_install_helper' -require 'beaker/module_install_helper' -require 'beaker-task_helper' - -run_puppet_install_helper -configure_type_defaults_on(hosts) -install_bolt_on(hosts) unless pe_install? -install_module_on(hosts) -install_module_dependencies_on(hosts) - -RSpec.configure do |c| - c.filter_run focus: true - c.run_all_when_everything_filtered = true - # IPv6 is not enabled by default in the new travis-ci Trusty environment (see https://github.com/travis-ci/travis-ci/issues/8891 ) - if fact('network6_lo') != '::1' - c.filter_run_excluding ipv6: true - end - - # Readable test descriptions - c.formatter = :documentation - - # detect the situation where PUP-5016 is triggered and skip the idempotency tests in that case - # also note how fact('puppetversion') is not available because of PUP-4359 - if host_inventory['facter']['os']['family'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '8' && shell('puppet --version').stdout =~ %r{^4\.2} - c.filter_run_excluding skip_pup_5016: true - end - - # Configure all nodes in nodeset - c.before :suite do - run_puppet_access_login(user: 'admin') if pe_install? && (Gem::Version.new(puppet_version) >= Gem::Version.new('5.0.0')) - # net-tools required for netstat utility being used by be_listening - if (host_inventory['facter']['os']['family'] == 'RedHat' && host_inventory['facter']['os']['release']['major'] == '7') || - (host_inventory['facter']['os']['family'] == 'Debian' && host_inventory['facter']['os']['release']['major'] == '9') || - (host_inventory['facter']['os']['name'] == 'Ubuntu' && host_inventory['facter']['os']['release']['full'] == '18.04') - pp = <<-EOS - package { 'net-tools': ensure => installed } - EOS - - apply_manifest_on(agents, pp, catch_failures: false) - elsif host_inventory['facter']['os']['name'] == 'SLES' && host_inventory['facter']['os']['release']['major'] == '15' - pp = <<-EOS - package { 'net-tools-deprecated': ensure => installed } - EOS - - apply_manifest_on(agents, pp, catch_failures: false) - end - - if host_inventory['facter']['os']['family'] == 'Debian' - # Make sure snake-oil certs are installed. - shell 'apt-get install -y ssl-cert' - end - - # Install module and dependencies - hosts.each do |host| - # Required for mod_passenger tests. - if host_inventory['facter']['os']['family'] == 'RedHat' - on host, puppet('module', 'install', 'stahnma/epel') - on host, puppet('module', 'install', 'puppetlabs/inifile') - # We need epel installed, so we can get plugins, wsgi, mime ... - # The osmirror is required as epel no longer supports el5 - pp = <<-PUPPETCODE - 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", - } - } else { - class { 'epel': } - } - } - PUPPETCODE - - apply_manifest_on(host, pp, catch_failures: true) - end - - # Required for manifest to make mod_pagespeed repository available - if host_inventory['facter']['os']['family'] == 'Debian' - on host, puppet('module', 'install', 'puppetlabs-apt') - end - - # Make sure selinux is disabled so the tests work. - on host, puppet('apply', '-e', - %("exec { 'setenforce 0': path => '/bin:/sbin:/usr/bin:/usr/sbin', onlyif => 'which setenforce && getenforce | grep Enforcing', }")) - end +# 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 - -shared_examples 'a idempotent resource' do - it 'applies with no errors' do - apply_manifest(pp, catch_failures: true) - end - - it 'applies a second time without changes', :skip_pup_5016 do - apply_manifest(pp, catch_changes: true) +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 + 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" + + 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 0000000000..c97eebd63a --- /dev/null +++ b/spec/spec_helper_acceptance_local.rb @@ -0,0 +1,139 @@ +# frozen_string_literal: true + +RSpec.configure do |c| + # IPv6 is not enabled by default in the new travis-ci Trusty environment (see https://github.com/travis-ci/travis-ci/issues/8891 ) + if ENV['CI'] == 'true' + c.filter_run_excluding ipv6: true + end + c.before :suite do + run_shell('puppet module install stahnma/epel') + pp = <<-PUPPETCODE + # needed by tests + package { 'curl': + ensure => 'latest', + } + # needed for netstat, for serverspec checks + if $::osfamily == 'SLES' or $::osfamily == 'SUSE' { + package { 'net-tools-deprecated': + ensure => 'latest', + } + } + # needed for ss, for serverspec checks + if $::operatingsystem == 'Ubuntu' and $::operatingsystemmajrelease !~ /14.04|16.04/ { + package { 'iproute2': + ensure => 'latest', + } + } + if $::osfamily == 'RedHat' { + if $::operatingsystemmajrelease == '5' or $::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", + } + } else { + class { 'epel': } + } + } + PUPPETCODE + apply_manifest(pp) + + # Make sure selinux is disabled so the tests work. + run_shell('setenforce 0', expect_failures: true) if os[:family] =~ %r{redhat|oracle} + end +end + +def apache_settings_hash + osfamily = os[:family] + operatingsystemrelease = os[:release].to_f + apache = {} + case osfamily + when 'redhat', 'oracle' + apache['confd_dir'] = '/etc/httpd/conf.d' + apache['conf_file'] = '/etc/httpd/conf/httpd.conf' + apache['ports_file'] = '/etc/httpd/conf/ports.conf' + apache['vhost_dir'] = '/etc/httpd/conf.d' + apache['vhost'] = '/etc/httpd/conf.d/15-default.conf' + apache['run_dir'] = '/var/run/httpd' + apache['doc_root'] = '/var/www' + apache['service_name'] = 'httpd' + apache['package_name'] = 'httpd' + apache['error_log'] = 'error_log' + apache['suphp_handler'] = 'php5-script' + apache['suphp_configpath'] = 'undef' + + if operatingsystemrelease >= 7 + apache['version'] = '2.4' + apache['mod_dir'] = '/etc/httpd/conf.modules.d' + else + apache['version'] = '2.2' + apache['mod_dir'] = '/etc/httpd/conf.d' + end + when 'debian', 'ubuntu' + apache['confd_dir'] = '/etc/apache2/conf.d' + apache['mod_dir'] = '/etc/apache2/mods-available' + apache['conf_file'] = '/etc/apache2/apache2.conf' + apache['ports_file'] = '/etc/apache2/ports.conf' + apache['vhost'] = '/etc/apache2/sites-available/15-default.conf' + apache['vhost_dir'] = '/etc/apache2/sites-enabled' + apache['run_dir'] = '/var/run/apache2' + apache['doc_root'] = '/var/www' + apache['service_name'] = 'apache2' + apache['package_name'] = 'apache2' + apache['error_log'] = 'error.log' + apache['suphp_handler'] = 'x-httpd-php' + apache['suphp_configpath'] = '/etc/php5/apache2' + apache['version'] = if osfamily == 'ubuntu' && operatingsystemrelease >= 13.10 + '2.4' + elsif osfamily == 'debian' && operatingsystemrelease >= 8.0 + '2.4' + else + '2.2' + end + when 'freebsd' + apache['confd_dir'] = '/usr/local/etc/apache24/Includes' + apache['mod_dir'] = '/usr/local/etc/apache24/Modules' + apache['conf_file'] = '/usr/local/etc/apache24/httpd.conf' + apache['ports_file'] = '/usr/local/etc/apache24/Includes/ports.conf' + apache['vhost'] = '/usr/local/etc/apache24/Vhosts/15-default.conf' + apache['vhost_dir'] = '/usr/local/etc/apache24/Vhosts' + apache['run_dir'] = '/var/run/apache24' + apache['doc_root'] = '/var/www' + apache['service_name'] = 'apache24' + apache['package_name'] = 'apache24' + apache['error_log'] = 'http-error.log' + apache['version'] = '2.2' + when 'gentoo' + apache['confd_dir'] = '/etc/apache2/conf.d' + apache['mod_dir'] = '/etc/apache2/modules.d' + apache['conf_file'] = '/etc/apache2/httpd.conf' + apache['ports_file'] = '/etc/apache2/ports.conf' + apache['vhost'] = '/etc/apache2/vhosts.d/15-default.conf' + apache['vhost_dir'] = '/etc/apache2/vhosts.d' + apache['run_dir'] = '/var/run/apache2' + apache['doc_root'] = '/var/www' + apache['service_name'] = 'apache2' + apache['package_name'] = 'www-servers/apache' + apache['error_log'] = 'http-error.log' + apache['version'] = '2.4' + when 'suse', 'sles' + apache['confd_dir'] = '/etc/apache2/conf.d' + apache['mod_dir'] = '/etc/apache2/mods-available' + apache['conf_file'] = '/etc/apache2/httpd.conf' + apache['ports_file'] = '/etc/apache2/ports.conf' + apache['vhost'] = '/etc/apache2/sites-available/15-default.conf' + apache['vhost_dir'] = '/etc/apache2/sites-available' + apache['run_dir'] = '/var/run/apache2' + apache['doc_root'] = '/srv/www' + apache['service_name'] = 'apache2' + apache['package_name'] = 'apache2' + apache['error_log'] = 'error.log' + apache['version'] = if operatingsystemrelease < 12 + '2.2' + else + '2.4' + end + else + raise 'unable to figure out what apache version' + end + apache +end