From b13fe2f182a00ffca8795b101229a481ea485cff Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 4 Oct 2023 12:20:03 +0200 Subject: [PATCH] don't call puppet multiple times in prepare host for acceptance --- spec/support/acceptance/prepare_host.rb | 45 ++++++++++++------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/spec/support/acceptance/prepare_host.rb b/spec/support/acceptance/prepare_host.rb index 70ac31738..3ae1682b4 100644 --- a/spec/support/acceptance/prepare_host.rb +++ b/spec/support/acceptance/prepare_host.rb @@ -16,30 +16,27 @@ 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 @@ -47,8 +44,8 @@ def prepare_host 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'] ? {