Skip to content

Commit

Permalink
Merge pull request #892 from voxpupuli/faster-cleanup
Browse files Browse the repository at this point in the history
don't call puppet multiple times in prepare host for acceptance
  • Loading branch information
evgeni authored Oct 4, 2023
2 parents 671263e + b13fe2f commit 085c715
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions spec/support/acceptance/prepare_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,36 @@ def prepare_host
# does not exist. Symlink it from /bin/mkdir to make it work.
shell('ln -sf /bin/mkdir /usr/bin/mkdir') if fact('os.distro.id') == 'Debian'

cleanup_script_debian = <<-SHELL
/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped
/opt/puppetlabs/bin/puppet resource service apache2 ensure=stopped
/opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-web-pgsql ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-frontend-php ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-sql-scripts ensure=purged
/opt/puppetlabs/puppet/bin/gem uninstall zabbixapi -a
rm -f /etc/zabbix/.*done
if id postgres > /dev/null 2>&1; then
su - postgres -c "psql -c 'drop database if exists zabbix_server;'"
fi
cleanup_puppet = <<-SHELL
$services = $facts['os']['family'] ? {
'RedHat' => ['zabbix-server', 'httpd'],
'Debian' => ['zabbix-server', 'apache2'],
default => [],
}
service { $services:
ensure => stopped
}
$packages = $facts['os']['family'] ? {
'RedHat' => ['zabbix-server-pgsql', 'zabbix-server-pgsql-scl', 'zabbix-web', 'zabbix-web-pgsql', 'zabbix-web-pgsql-scl', 'zabbix-frontend-php', 'zabbix-sql-scripts'],
'Debian' => ['zabbix-server-pgsql', 'zabbix-web-pgsql', 'zabbix-frontend-php', 'zabbix-sql-scripts'],
default => [],
}
package { $packages:
ensure => purged
}
SHELL

cleanup_script_redhat = <<-SHELL
/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped
/opt/puppetlabs/bin/puppet resource service httpd ensure=stopped
/opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql-scl ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-web ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-web-pgsql ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-web-pgsql-scl ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-frontend-php ensure=purged
/opt/puppetlabs/bin/puppet resource package zabbix-sql-scripts ensure=purged
cleanup_script = <<-SHELL
/opt/puppetlabs/puppet/bin/gem uninstall zabbixapi -a
rm -f /etc/zabbix/.*done
if id postgres > /dev/null 2>&1; then
su - postgres -c "psql -c 'drop database if exists zabbix_server;'"
fi
SHELL

shell(cleanup_script_debian) if fact('os.family') == 'Debian'
shell(cleanup_script_redhat) if fact('os.family') == 'RedHat'
apply_manifest(cleanup_puppet)
shell(cleanup_script)

install_deps = <<-SHELL
$compile_packages = $facts['os']['family'] ? {
Expand Down

0 comments on commit 085c715

Please sign in to comment.