From 815688533f7ef888a39dd7642dfeffddf79d93da Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 7 Feb 2024 22:21:42 +0100 Subject: [PATCH] spec_helper_acceptance.rb: Switch to Vox Pupuli defaults --- spec/acceptance/class_spec.rb | 236 ++++++++++++++++----------------- spec/spec_helper_acceptance.rb | 56 ++------ 2 files changed, 127 insertions(+), 165 deletions(-) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index d2fc45ab..118a42ae 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -2,130 +2,130 @@ describe 'icingaweb2 class:' do describe 'icingaweb2 with defaults' do - let(:pp) do - <<-MANIFEST - case $facts['os']['family'] { - 'redhat': { - if $facts['os']['name'] == 'centos' and Integer($facts['os']['release']['major']) < 8 { - package { 'centos-release-scl': } - - $php_globals = { - php_version => 'rh-php71', - rhscl_mode => 'rhscl', + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-MANIFEST + case $facts['os']['family'] { + 'redhat': { + if $facts['os']['name'] == 'centos' and Integer($facts['os']['release']['major']) < 8 { + package { 'centos-release-scl': } + + $php_globals = { + php_version => 'rh-php71', + rhscl_mode => 'rhscl', + } + } else { + $php_globals = {} } - } else { - $php_globals = {} - } - $php_extensions = { - mbstring => { ini_prefix => '20-' }, - json => { ini_prefix => '20-' }, - ldap => { ini_prefix => '20-' }, - gd => { ini_prefix => '20-' }, - xml => { ini_prefix => '20-' }, - intl => { ini_prefix => '20-' }, - mysqlnd => { ini_prefix => '20-' }, - pgsql => { ini_prefix => '20-' }, - } - $web_conf_user = 'apache' - } # RedHat - - 'debian': { - $php_globals = {} - $php_extensions = { - mbstring => {}, - json => {}, - ldap => {}, - gd => {}, - xml => {}, - intl => {}, - mysql => {}, - pgsql => {}, + $php_extensions = { + mbstring => { ini_prefix => '20-' }, + json => { ini_prefix => '20-' }, + ldap => { ini_prefix => '20-' }, + gd => { ini_prefix => '20-' }, + xml => { ini_prefix => '20-' }, + intl => { ini_prefix => '20-' }, + mysqlnd => { ini_prefix => '20-' }, + pgsql => { ini_prefix => '20-' }, + } + $web_conf_user = 'apache' + } # RedHat + + 'debian': { + $php_globals = {} + $php_extensions = { + mbstring => {}, + json => {}, + ldap => {}, + gd => {}, + xml => {}, + intl => {}, + mysql => {}, + pgsql => {}, + } + $web_conf_user = 'www-data' + } # Debian + + default: { + fail("'Your operatingsystem ${::operatingsystem} is not supported.'") } - $web_conf_user = 'www-data' - } # Debian + } - default: { - fail("'Your operatingsystem ${::operatingsystem} is not supported.'") + # + # PHP + # + class { '::php::globals': + * => $php_globals, + } + + class { '::php': + ensure => installed, + manage_repos => false, + apache_config => false, + fpm => true, + extensions => $php_extensions, + dev => false, + composer => false, + pear => false, + phpunit => false, + require => Class['::php::globals'], } - } - - # - # PHP - # - class { '::php::globals': - * => $php_globals, - } - - class { '::php': - ensure => installed, - manage_repos => false, - apache_config => false, - fpm => true, - extensions => $php_extensions, - dev => false, - composer => false, - pear => false, - phpunit => false, - require => Class['::php::globals'], - } - - # - # Apache - # - class { '::apache': - default_mods => false, - default_vhost => false, - mpm_module => 'worker', - } - - apache::listen { '80': } - - include ::apache::mod::alias - include ::apache::mod::status - include ::apache::mod::dir - include ::apache::mod::env - include ::apache::mod::rewrite - include ::apache::mod::proxy - include ::apache::mod::proxy_fcgi - - apache::custom_config { 'icingaweb2': - ensure => present, - source => 'puppet:///modules/icingaweb2/examples/apache2/for-mod_proxy_fcgi.conf', - verify_config => false, - priority => false, - } - - # - # Icinga Web 2 - # - include ::mysql::server - - mysql::db { 'icingaweb2': - user => 'icingaweb2', - password => 'icingaweb2', - host => 'localhost', - grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER', 'REFERENCES'], - before => Class['icingaweb2'], - } - - Package['icingaweb2'] - -> Class['apache'] - - class { 'icingaweb2': - manage_repos => true, - conf_user => $web_conf_user, - db_type => 'mysql', - db_host => 'localhost', - db_port => 3306, - db_username => 'icingaweb2', - db_password => 'icingaweb2', - import_schema => true, - } - MANIFEST - end - it_behaves_like 'a idempotent resource' + # + # Apache + # + class { '::apache': + default_mods => false, + default_vhost => false, + mpm_module => 'worker', + } + + apache::listen { '80': } + + include ::apache::mod::alias + include ::apache::mod::status + include ::apache::mod::dir + include ::apache::mod::env + include ::apache::mod::rewrite + include ::apache::mod::proxy + include ::apache::mod::proxy_fcgi + + apache::custom_config { 'icingaweb2': + ensure => present, + source => 'puppet:///modules/icingaweb2/examples/apache2/for-mod_proxy_fcgi.conf', + verify_config => false, + priority => false, + } + + # + # Icinga Web 2 + # + include ::mysql::server + + mysql::db { 'icingaweb2': + user => 'icingaweb2', + password => 'icingaweb2', + host => 'localhost', + grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE VIEW', 'CREATE', 'INDEX', 'EXECUTE', 'ALTER', 'REFERENCES'], + before => Class['icingaweb2'], + } + + Package['icingaweb2'] + -> Class['apache'] + + class { 'icingaweb2': + manage_repos => true, + conf_user => $web_conf_user, + db_type => 'mysql', + db_host => 'localhost', + db_port => 3306, + db_username => 'icingaweb2', + db_password => 'icingaweb2', + import_schema => true, + } + MANIFEST + end + end describe package('icingaweb2') do it { is_expected.to be_installed } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 48e63b9f..4c1291aa 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,50 +1,12 @@ -require 'beaker-rspec' -require 'beaker/puppet_install_helper' +# frozen_string_literal: true -# Install Puppet on all hosts -install_puppet_agent_on(hosts, puppet_collection: 'puppet5') +require 'voxpupuli/acceptance/spec_helper_acceptance' -RSpec.configure do |c| - module_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) - - c.formatter = :documentation - - c.before :suite do - # Install module to all hosts - hosts.each do |host| - install_dev_puppet_module_on(host, source: module_root, module_name: 'icingaweb2', - target_module_path: '/etc/puppetlabs/code/modules') - - # Install dependencies - on(host, puppet('module', 'install', 'puppetlabs-stdlib')) - on(host, puppet('module', 'install', 'puppetlabs-concat')) - on(host, puppet('module', 'install', 'puppetlabs-vcsrepo')) - - # Install additional modules - on(host, puppet('module', 'install', 'puppetlabs-mysql')) - on(host, puppet('module', 'install', 'puppetlabs-postgresql')) - on(host, puppet('module', 'install', 'puppetlabs-apache')) - on(host, puppet('module', 'install', 'puppet-php')) - - if fact('osfamily') == 'Debian' - on(host, puppet('module', 'install', 'puppetlabs-apt')) - end - - if fact('osfamily') == 'Suse' - on(host, puppet('module', 'install', 'puppet-zypprepo')) - end - - # Add more setup code as needed - end - 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) - end +configure_beaker do |host| + install_puppet_module_via_pmt_on(host, 'puppetlabs-mysql') + install_puppet_module_via_pmt_on(host, 'puppetlabs-postgresql') + install_puppet_module_via_pmt_on(host, 'puppetlabs-apache') + install_puppet_module_via_pmt_on(host, 'puppet-php') + install_puppet_module_via_pmt_on(host, 'puppetlabs-apt') + install_puppet_module_via_pmt_on(host, 'puppet-zypprepo') end