From dea01e68458585ce0b6d1e898433a2de5176117d Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Sat, 5 Dec 2020 18:09:01 +0100 Subject: [PATCH] Restructure acceptance tests This restructures the tests into focused files. By defining an order, there is less need to purge Foreman on every test which greatly speeds up execution. --- spec/acceptance/foreman_basic_spec.rb | 23 ---- spec/acceptance/foreman_cli_plugins_spec.rb | 43 ------ spec/acceptance/foreman_cli_spec.rb | 76 +++++++++-- spec/acceptance/foreman_journald_spec.rb | 33 ----- spec/acceptance/foreman_prometheus_spec.rb | 23 ---- spec/acceptance/foreman_rex_cockpit_spec.rb | 20 --- spec/acceptance/foreman_spec.rb | 138 ++++++++++++++++++++ spec/acceptance/foreman_statsd_spec.rb | 23 ---- spec/support/acceptance/examples.rb | 36 ----- 9 files changed, 201 insertions(+), 214 deletions(-) delete mode 100644 spec/acceptance/foreman_basic_spec.rb delete mode 100644 spec/acceptance/foreman_cli_plugins_spec.rb delete mode 100644 spec/acceptance/foreman_journald_spec.rb delete mode 100644 spec/acceptance/foreman_prometheus_spec.rb delete mode 100644 spec/acceptance/foreman_rex_cockpit_spec.rb create mode 100644 spec/acceptance/foreman_spec.rb delete mode 100644 spec/acceptance/foreman_statsd_spec.rb delete mode 100644 spec/support/acceptance/examples.rb diff --git a/spec/acceptance/foreman_basic_spec.rb b/spec/acceptance/foreman_basic_spec.rb deleted file mode 100644 index a42b6b859..000000000 --- a/spec/acceptance/foreman_basic_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'Scenario: install foreman' do - before(:context) { purge_foreman } - - let(:pp) do - <<-PUPPET - include foreman - PUPPET - end - - it_behaves_like 'a idempotent resource' - - it_behaves_like 'the foreman application' - - describe package('foreman-journald') do - it { is_expected.not_to be_installed } - end - - describe package('foreman-telemetry') do - it { is_expected.not_to be_installed } - end -end diff --git a/spec/acceptance/foreman_cli_plugins_spec.rb b/spec/acceptance/foreman_cli_plugins_spec.rb deleted file mode 100644 index 09b5ce040..000000000 --- a/spec/acceptance/foreman_cli_plugins_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'Scenario: install foreman-cli + plugins without foreman' do - before(:context) { purge_foreman } - - let(:pp) do - <<-PUPPET - class { 'foreman::cli': - foreman_url => 'https://foreman.example.com', - username => 'admin', - password => 'changeme', - } - - if $facts['os']['family'] == 'RedHat' { - include foreman::cli::ansible - include foreman::cli::azure - } - include foreman::cli::discovery - include foreman::cli::remote_execution - include foreman::cli::tasks - include foreman::cli::templates - PUPPET - end - - it_behaves_like 'a idempotent resource' - - it_behaves_like 'hammer' - - ['discovery', 'remote_execution', 'tasks', 'templates'].each do |plugin| - package_name = case fact('os.family') - when 'RedHat' - fact('os.release.major') == '7' ? "tfm-rubygem-hammer_cli_foreman_#{plugin}" : "rubygem-hammer_cli_foreman_#{plugin}" - when 'Debian' - "ruby-hammer-cli-foreman-#{plugin.tr('_', '-')}" - else - plugin - end - - describe package(package_name) do - it { is_expected.to be_installed } - end - end -end diff --git a/spec/acceptance/foreman_cli_spec.rb b/spec/acceptance/foreman_cli_spec.rb index ba9ff8a3b..c27987c48 100644 --- a/spec/acceptance/foreman_cli_spec.rb +++ b/spec/acceptance/foreman_cli_spec.rb @@ -1,19 +1,69 @@ require 'spec_helper_acceptance' -describe 'Scenario: install foreman-cli without foreman' do - before(:context) { purge_foreman } - - let(:pp) do - <<-PUPPET - class { 'foreman::cli': - foreman_url => 'https://foreman.example.com', - username => 'admin', - password => 'changeme', - } - PUPPET +describe 'foreman-cli', order: defined do + shared_examples 'hammer' do + describe command('hammer --version') do + its(:stdout) { is_expected.to match(/^hammer/) } + end end - it_behaves_like 'a idempotent resource' + context 'without Foreman' do + before(:context) { purge_foreman } - it_behaves_like 'hammer' + context 'without plugins' do + let(:pp) do + <<-PUPPET + class { 'foreman::cli': + foreman_url => 'https://foreman.example.com', + username => 'admin', + password => 'changeme', + } + PUPPET + end + + it_behaves_like 'a idempotent resource' + + it_behaves_like 'hammer' + end + + context 'with plugins' do + let(:pp) do + <<-PUPPET + class { 'foreman::cli': + foreman_url => 'https://foreman.example.com', + username => 'admin', + password => 'changeme', + } + + if $facts['os']['family'] == 'RedHat' { + include foreman::cli::ansible + include foreman::cli::azure + } + include foreman::cli::discovery + include foreman::cli::remote_execution + include foreman::cli::tasks + include foreman::cli::templates + PUPPET + end + + it_behaves_like 'a idempotent resource' + + it_behaves_like 'hammer' + + ['discovery', 'remote_execution', 'tasks', 'templates'].each do |plugin| + package_name = case fact('os.family') + when 'RedHat' + fact('os.release.major') == '7' ? "tfm-rubygem-hammer_cli_foreman_#{plugin}" : "rubygem-hammer_cli_foreman_#{plugin}" + when 'Debian' + "ruby-hammer-cli-foreman-#{plugin.tr('_', '-')}" + else + plugin + end + + describe package(package_name) do + it { is_expected.to be_installed } + end + end + end + end end diff --git a/spec/acceptance/foreman_journald_spec.rb b/spec/acceptance/foreman_journald_spec.rb deleted file mode 100644 index cd6bb1c18..000000000 --- a/spec/acceptance/foreman_journald_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'Scenario: install foreman with journald' do - before(:context) { purge_foreman } - - let(:pp) do - <<-PUPPET - class { 'foreman': - logging_type => 'journald', - } - PUPPET - end - - it_behaves_like 'a idempotent resource' - - it_behaves_like 'the foreman application' - - describe package('foreman-journald') do - it { is_expected.to be_installed } - end - - # Logging to the journal is broken on Docker 18+ and EL7 but works in Vagrant - # VMs (and EL7's Docker version) - broken_journald_logging = ENV['BEAKER_HYPERVISOR'] == 'docker' && os[:family] == 'redhat' && os[:release] =~ /^7\./ - - describe command('journalctl -u foreman'), unless: broken_journald_logging do - its(:stdout) { is_expected.to match(%r{Redirected to https://#{host_inventory['fqdn']}/users/login}) } - end - - describe command('journalctl -u dynflow-sidekiq@orchestrator'), unless: broken_journald_logging do - its(:stdout) { is_expected.to match(%r{Everything ready for world: }) } - end -end diff --git a/spec/acceptance/foreman_prometheus_spec.rb b/spec/acceptance/foreman_prometheus_spec.rb deleted file mode 100644 index 6ae6351e6..000000000 --- a/spec/acceptance/foreman_prometheus_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'Scenario: install foreman with prometheus' do - before(:context) { purge_foreman } - - let(:pp) do - <<-PUPPET - class { 'foreman': - telemetry_prometheus_enabled => true, - } - PUPPET - end - - it_behaves_like 'a idempotent resource' - - it_behaves_like 'the foreman application' - - describe package('foreman-telemetry') do - it { is_expected.to be_installed } - end - - # TODO: actually verify prometheus functionality -end diff --git a/spec/acceptance/foreman_rex_cockpit_spec.rb b/spec/acceptance/foreman_rex_cockpit_spec.rb deleted file mode 100644 index 307f63d7e..000000000 --- a/spec/acceptance/foreman_rex_cockpit_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'Scenario: install foreman with rex cockpit', if: os[:family] == 'centos' do - before(:context) { purge_foreman } - - let(:pp) do - <<-PUPPET - include foreman - include foreman::plugin::remote_execution::cockpit - PUPPET - end - - it_behaves_like 'a idempotent resource' - - it_behaves_like 'the foreman application' - - describe port(19090) do - it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } - end -end diff --git a/spec/acceptance/foreman_spec.rb b/spec/acceptance/foreman_spec.rb new file mode 100644 index 000000000..a7940960a --- /dev/null +++ b/spec/acceptance/foreman_spec.rb @@ -0,0 +1,138 @@ +require 'spec_helper_acceptance' + +describe 'foreman', order: :defined do + shared_examples 'the foreman application' do + [ + ['debian', 'ubuntu'].include?(os[:family]) ? 'apache2' : 'httpd', + 'dynflow-sidekiq@orchestrator', + 'dynflow-sidekiq@worker', + 'foreman', + ].each do |service_name| + describe service(service_name) do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + end + + describe port(80) do + it { is_expected.to be_listening } + end + + describe port(443) do + it { is_expected.to be_listening } + end + + describe file('/run/foreman.sock') do + it { should be_socket } + end + + describe command("curl -s --cacert /etc/foreman-certs/certificate.pem https://#{host_inventory['fqdn']} -w '\%{redirect_url}' -o /dev/null") do + its(:stdout) { is_expected.to eq("https://#{host_inventory['fqdn']}/users/login") } + its(:exit_status) { is_expected.to eq 0 } + end + end + + before(:context) { purge_foreman } + + context 'without plugins' do + let(:pp) do + <<-PUPPET + include foreman + PUPPET + end + + it_behaves_like 'a idempotent resource' + it_behaves_like 'the foreman application' + + describe package('foreman-journald') do + it { is_expected.not_to be_installed } + end + + describe package('foreman-telemetry') do + it { is_expected.not_to be_installed } + end + end + + context 'with journald' do + let(:pp) do + <<-PUPPET + class { 'foreman': + logging_type => 'journald', + } + PUPPET + end + + it_behaves_like 'a idempotent resource' + it_behaves_like 'the foreman application' + + describe package('foreman-journald') do + it { is_expected.to be_installed } + end + + # Logging to the journal is broken on Docker 18+ and EL7 but works in Vagrant + # VMs (and EL7's Docker version) + broken_journald_logging = ENV['BEAKER_HYPERVISOR'] == 'docker' && os[:family] == 'redhat' && os[:release] =~ /^7\./ + + describe command('journalctl -u foreman'), unless: broken_journald_logging do + its(:stdout) { is_expected.to match(%r{Redirected to https://#{host_inventory['fqdn']}/users/login}) } + end + + describe command('journalctl -u dynflow-sidekiq@orchestrator'), unless: broken_journald_logging do + its(:stdout) { is_expected.to match(%r{Everything ready for world: }) } + end + end + + context 'with prometheus' do + let(:pp) do + <<-PUPPET + class { 'foreman': + telemetry_prometheus_enabled => true, + } + PUPPET + end + + it_behaves_like 'a idempotent resource' + it_behaves_like 'the foreman application' + + describe package('foreman-telemetry') do + it { is_expected.to be_installed } + end + + # TODO: actually verify prometheus functionality + end + + context 'with statsd' do + let(:pp) do + <<-PUPPET + class { 'foreman': + telemetry_statsd_enabled => true, + } + PUPPET + end + + it_behaves_like 'a idempotent resource' + it_behaves_like 'the foreman application' + + describe package('foreman-telemetry') do + it { is_expected.to be_installed } + end + + # TODO: actually verify statsd functionality + end + + context 'with rex cockpit', if: os[:family] == 'centos' do + let(:pp) do + <<-PUPPET + include foreman + include foreman::plugin::remote_execution::cockpit + PUPPET + end + + it_behaves_like 'a idempotent resource' + it_behaves_like 'the foreman application' + + describe port(19090) do + it { is_expected.to be_listening.on('127.0.0.1').with('tcp') } + end + end +end diff --git a/spec/acceptance/foreman_statsd_spec.rb b/spec/acceptance/foreman_statsd_spec.rb deleted file mode 100644 index 7c85f14df..000000000 --- a/spec/acceptance/foreman_statsd_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'Scenario: install foreman with statsd' do - before(:context) { purge_foreman } - - let(:pp) do - <<-PUPPET - class { 'foreman': - telemetry_statsd_enabled => true, - } - PUPPET - end - - it_behaves_like 'a idempotent resource' - - it_behaves_like 'the foreman application' - - describe package('foreman-telemetry') do - it { is_expected.to be_installed } - end - - # TODO: actually verify statsd functionality -end diff --git a/spec/support/acceptance/examples.rb b/spec/support/acceptance/examples.rb deleted file mode 100644 index 7d4b26f30..000000000 --- a/spec/support/acceptance/examples.rb +++ /dev/null @@ -1,36 +0,0 @@ -shared_examples 'the foreman application' do - [ - ['debian', 'ubuntu'].include?(os[:family]) ? 'apache2' : 'httpd', - 'dynflow-sidekiq@orchestrator', - 'dynflow-sidekiq@worker', - 'foreman', - ].each do |service_name| - describe service(service_name) do - it { is_expected.to be_enabled } - it { is_expected.to be_running } - end - end - - describe port(80) do - it { is_expected.to be_listening } - end - - describe port(443) do - it { is_expected.to be_listening } - end - - describe file('/run/foreman.sock') do - it { should be_socket } - end - - describe command("curl -s --cacert /etc/foreman-certs/certificate.pem https://#{host_inventory['fqdn']} -w '\%{redirect_url}' -o /dev/null") do - its(:stdout) { is_expected.to eq("https://#{host_inventory['fqdn']}/users/login") } - its(:exit_status) { is_expected.to eq 0 } - end -end - -shared_examples 'hammer' do - describe command('hammer --version') do - its(:stdout) { is_expected.to match(/^hammer/) } - end -end