Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the size of prepare_host in acceptance tests #917

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions spec/setup_acceptance_node.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
case $facts['os']['name'] {
'Debian': {
# On Debian it seems that make is searching for mkdir in /usr/bin/ but mkdir
# does not exist. Symlink it from /bin/mkdir to make it work.
file { '/usr/bin/mkdir':
ensure => link,
target => '/bin/mkdir',
}
}
'Ubuntu': {
# The Ubuntu 18.04+ docker image has a dpkg config that won't install docs, to keep used space low
# zabbix packages their SQL file as doc, we need that for bootstrapping the database
file { '/etc/dpkg/dpkg.cfg.d/excludes':
ensure => absent,
}
}
default: {}
}

case $facts['os']['family'] {
'RedHat': {
if $facts['os']['release']['major'] == '7' {
# The CentOS docker image has a yum config that won't install docs, to keep used space low
# zabbix packages their SQL file as doc, we need that for bootstrapping the database
augeas { 'remove tsflags=nodocs from yum.conf':
changes => [
'rm /files/etc/yum.conf/main/tsflags',
],
}
}
}
default: {}
}
66 changes: 25 additions & 41 deletions spec/support/acceptance/prepare_host.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,33 @@
# frozen_string_literal: true

def prepare_host
if fact('os.family') == 'RedHat'
shell('rm -rf /etc/yum.repos.d/Zabbix*.repo; rm -rf /var/cache/yum/x86_64/*/Zabbix*; yum clean all --verbose')
# The CentOS docker image has a yum config that won't install docs, to keep used space low
# zabbix packages their SQL file as doc, we need that for bootstrapping the database
shell('sed -i "/nodocs/d" /etc/yum.conf') if fact('os.release.major').to_i == 7
end
shell('yum clean all --verbose; rm -rf /etc/yum.repos.d/Zabbix*.repo') if fact('os.family') == 'RedHat'

# The Ubuntu 18.04+ docker image has a dpkg config that won't install docs, to keep used space low
# zabbix packages their SQL file as doc, we need that for bootstrapping the database
shell('rm -f /etc/dpkg/dpkg.cfg.d/excludes') if fact('os.distro.id') == 'Ubuntu'
apply_manifest <<~PUPPET
$services = $facts['os']['family'] ? {
'RedHat' => ['zabbix-server', 'httpd'],
'Debian' => ['zabbix-server', 'apache2'],
default => [],
}
service { $services:
ensure => stopped
}

# On Debian it seems that make is searching for mkdir in /usr/bin/ but mkdir
# 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'
$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
}
PUPPET

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 = <<-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
/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

apply_manifest(cleanup_puppet)
shell(cleanup_script)
end