Skip to content

Commit

Permalink
Refactor acceptance testing
Browse files Browse the repository at this point in the history
This uses hiera for common parameters. It also does some common things
in the acceptance helper to reduce duplication.
  • Loading branch information
ekohl committed Mar 6, 2020
1 parent 101dc54 commit 4fe64cc
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 633 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gem 'puppet-blacksmith', '>= 4.1.0', {"groups"=>["development"]}
gem 'beaker', '>= 4.2.0', {"groups"=>["system_tests"]}
gem 'beaker-docker', {"groups"=>["system_tests"]}
gem 'beaker-hostgenerator', '>= 1.1.10', {"groups"=>["system_tests"]}
gem 'beaker-hiera', {"git"=>"https://github.com/ekohl/beaker-hiera", "branch"=>"fix", "groups"=>["system_tests"]}
gem 'beaker-puppet', {"groups"=>["system_tests"]}
gem 'beaker-vagrant', {"groups"=>["system_tests"]}
gem 'beaker-rspec', {"groups"=>["system_tests"]}
Expand Down
101 changes: 4 additions & 97 deletions spec/acceptance/foreman_basic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,93 +1,13 @@
require 'spec_helper_acceptance'

describe 'Scenario: install foreman' do
apache_service_name = ['debian', 'ubuntu'].include?(os[:family]) ? 'apache2' : 'httpd'

before(:context) do
case fact('osfamily')
when 'RedHat'
on default, 'yum -y remove foreman* tfm-* mod_passenger && rm -rf /etc/yum.repos.d/foreman*.repo'
when 'Debian'
on default, 'apt-get purge -y foreman*', { :acceptable_exit_codes => [0, 100] }
on default, 'apt-get purge -y ruby-hammer-cli-*', { :acceptable_exit_codes => [0, 100] }
on default, 'rm -rf /etc/apt/sources.list.d/foreman*'
end

on default, "systemctl stop #{apache_service_name}", { :acceptable_exit_codes => [0, 5] }
end

let(:pp) do
<<-EOS
# Workarounds
## Ensure repos are present before installing
Yumrepo <| |> -> Package <| |>
## We want passenger from EPEL
class { '::apache::mod::passenger':
manage_repo => false,
}
if $facts['os']['family'] == 'RedHat' and $facts['os']['name'] != 'Fedora' {
class { 'redis::globals':
scl => 'rh-redis5',
}
}
$directory = '/etc/foreman'
$certificate = "${directory}/certificate.pem"
$key = "${directory}/key.pem"
exec { 'Create certificate directory':
command => "mkdir -p ${directory}",
path => ['/bin', '/usr/bin'],
creates => $directory,
} ->
exec { 'Generate certificate':
command => "openssl req -nodes -x509 -newkey rsa:2048 -subj '/CN=${facts['fqdn']}' -keyout '${key}' -out '${certificate}' -days 365",
path => ['/bin', '/usr/bin'],
creates => $certificate,
umask => '0022',
} ->
file { [$key, $certificate]:
owner => 'root',
group => 'root',
mode => '0640',
} ->
class { '::foreman':
repo => 'nightly',
user_groups => [],
initial_admin_username => 'admin',
initial_admin_password => 'changeme',
server_ssl_ca => $certificate,
server_ssl_chain => $certificate,
server_ssl_cert => $certificate,
server_ssl_key => $key,
server_ssl_crl => '',
}
EOS
end

it_behaves_like 'a idempotent resource'

describe service(apache_service_name) do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
<<-PUPPET
include foreman
PUPPET
end

describe service('dynflow-sidekiq@orchestrator') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('dynflow-sidekiq@worker') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('foreman') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
include_examples 'foreman application'

describe package('foreman-journald') do
it { is_expected.not_to be_installed }
Expand All @@ -96,17 +16,4 @@ class { '::foreman':
describe package('foreman-telemetry') do
it { is_expected.not_to be_installed }
end

describe port(80) do
it { is_expected.to be_listening }
end

describe port(443) do
it { is_expected.to be_listening }
end

describe command("curl -s --cacert /etc/foreman/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
42 changes: 10 additions & 32 deletions spec/acceptance/foreman_cli_plugins_spec.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
require 'spec_helper_acceptance'

describe 'Scenario: install foreman-cli + plugins without foreman' do
before(:context) do
case fact('osfamily')
when 'RedHat'
on default, 'yum -y remove foreman* tfm-* && rm -rf /etc/yum.repos.d/foreman*.repo'
when 'Debian'
on default, 'apt-get purge -y foreman*', { :acceptable_exit_codes => [0, 100] }
on default, 'apt-get purge -y ruby-hammer-cli-*', { :acceptable_exit_codes => [0, 100] }
on default, 'rm -rf /etc/apt/sources.list.d/foreman*'
end
end

let(:pp) do
configure = fact('osfamily') == 'RedHat' && fact('operatingsystem') != 'Fedora'
<<-EOS
class { '::foreman::repo':
repo => 'nightly',
gpgcheck => true,
configure_epel_repo => #{configure},
configure_scl_repo => #{configure},
} ->
class { '::foreman::cli':
<<-PUPPET
class { 'foreman::cli':
foreman_url => 'https://foreman.example.com',
username => 'admin',
password => 'changeme',
}
if $facts['osfamily'] == 'RedHat' {
include ::foreman::cli::ansible
include ::foreman::cli::azure
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
EOS
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'
include_examples 'hammer'

['discovery', 'remote_execution', 'tasks', 'templates'].each do |plugin|
package_name = case fact('osfamily')
Expand All @@ -54,8 +36,4 @@ class { '::foreman::cli':
it { is_expected.to be_installed }
end
end

describe command('hammer --version') do
its(:stdout) { is_expected.to match(/^hammer/) }
end
end
30 changes: 4 additions & 26 deletions spec/acceptance/foreman_cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
require 'spec_helper_acceptance'

describe 'Scenario: install foreman-cli without foreman' do
before(:context) do
case fact('osfamily')
when 'RedHat'
on default, 'yum -y remove foreman* tfm-* && rm -rf /etc/yum.repos.d/foreman*.repo'
when 'Debian'
on default, 'apt-get purge -y foreman*', { :acceptable_exit_codes => [0, 100] }
on default, 'apt-get purge -y ruby-hammer-cli-*', { :acceptable_exit_codes => [0, 100] }
on default, 'rm -rf /etc/apt/sources.list.d/foreman*'
end
end

let(:pp) do
configure = fact('osfamily') == 'RedHat' && fact('operatingsystem') != 'Fedora'
<<-EOS
class { '::foreman::repo':
repo => 'nightly',
gpgcheck => true,
configure_epel_repo => #{configure},
configure_scl_repo => #{configure},
} ->
class { '::foreman::cli':
<<-PUPPET
class { 'foreman::cli':
foreman_url => 'https://foreman.example.com',
username => 'admin',
password => 'changeme',
}
EOS
PUPPET
end

it_behaves_like 'a idempotent resource'

describe command('hammer --version') do
its(:stdout) { is_expected.to match(/^hammer/) }
end
include_examples 'hammer'
end
108 changes: 9 additions & 99 deletions spec/acceptance/foreman_journald_spec.rb
Original file line number Diff line number Diff line change
@@ -1,119 +1,29 @@
require 'spec_helper_acceptance'

describe 'Scenario: install foreman with journald' do
apache_service_name = ['debian', 'ubuntu'].include?(os[:family]) ? 'apache2' : 'httpd'

before(:context) do
case fact('osfamily')
when 'RedHat'
on default, 'yum -y remove foreman* tfm-* mod_passenger && rm -rf /etc/yum.repos.d/foreman*.repo'
when 'Debian'
on default, 'apt-get purge -y foreman*', { :acceptable_exit_codes => [0, 100] }
on default, 'apt-get purge -y ruby-hammer-cli-*', { :acceptable_exit_codes => [0, 100] }
on default, 'rm -rf /etc/apt/sources.list.d/foreman*'
end

on default, "systemctl stop #{apache_service_name}", { :acceptable_exit_codes => [0, 5] }
end

let(:pp) do
<<-EOS
# Workarounds
## Ensure repos are present before installing
Yumrepo <| |> -> Package <| |>
## We want passenger from EPEL
class { '::apache::mod::passenger':
manage_repo => false,
<<-PUPPET
class { 'foreman':
logging_type => 'journald',
}
if $facts['os']['family'] == 'RedHat' and $facts['os']['name'] != 'Fedora' {
class { 'redis::globals':
scl => 'rh-redis5',
}
}
$directory = '/etc/foreman'
$certificate = "${directory}/certificate.pem"
$key = "${directory}/key.pem"
exec { 'Create certificate directory':
command => "mkdir -p ${directory}",
path => ['/bin', '/usr/bin'],
creates => $directory,
} ->
exec { 'Generate certificate':
command => "openssl req -nodes -x509 -newkey rsa:2048 -subj '/CN=${facts['fqdn']}' -keyout '${key}' -out '${certificate}' -days 365",
path => ['/bin', '/usr/bin'],
creates => $certificate,
umask => '0022',
} ->
file { [$key, $certificate]:
owner => 'root',
group => 'root',
mode => '0640',
} ->
class { '::foreman':
repo => 'nightly',
user_groups => [],
initial_admin_username => 'admin',
initial_admin_password => 'changeme',
server_ssl_ca => $certificate,
server_ssl_chain => $certificate,
server_ssl_cert => $certificate,
server_ssl_key => $key,
server_ssl_crl => '',
logging_type => 'journald',
}
EOS
PUPPET
end

it_behaves_like 'a idempotent resource'

describe service(apache_service_name) do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('dynflow-sidekiq@orchestrator') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('dynflow-sidekiq@worker') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end

describe service('foreman') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
include_examples 'foreman application'

describe package('foreman-journald') do
it { is_expected.to be_installed }
end

describe port(80) do
it { is_expected.to be_listening }
end

describe port(443) do
it { is_expected.to be_listening }
end

describe command("curl -s --cacert /etc/foreman/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

# Logging to the journal is broken on Travis and EL7 but works in Vagrant VMs
# and regular docker containers
describe command('journalctl -u foreman'), unless: ENV['TRAVIS'] == 'true' && os[:family] == 'redhat' && os[:release] =~ /^7\./ do
broken_journald_logging = ENV['TRAVIS'] == 'true' && 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: ENV['TRAVIS'] == 'true' && os[:family] == 'redhat' && os[:release] =~ /^7\./ do
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
Loading

0 comments on commit 4fe64cc

Please sign in to comment.