Skip to content

Commit 9b75b75

Browse files
authored
Merge pull request #917 from ekohl/use-setup_acceptance_node
Reduce the size of prepare_host in acceptance tests
2 parents e9b96c8 + df27042 commit 9b75b75

File tree

2 files changed

+58
-41
lines changed

2 files changed

+58
-41
lines changed

spec/setup_acceptance_node.pp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
case $facts['os']['name'] {
2+
'Debian': {
3+
# On Debian it seems that make is searching for mkdir in /usr/bin/ but mkdir
4+
# does not exist. Symlink it from /bin/mkdir to make it work.
5+
file { '/usr/bin/mkdir':
6+
ensure => link,
7+
target => '/bin/mkdir',
8+
}
9+
}
10+
'Ubuntu': {
11+
# The Ubuntu 18.04+ docker image has a dpkg config that won't install docs, to keep used space low
12+
# zabbix packages their SQL file as doc, we need that for bootstrapping the database
13+
file { '/etc/dpkg/dpkg.cfg.d/excludes':
14+
ensure => absent,
15+
}
16+
}
17+
default: {}
18+
}
19+
20+
case $facts['os']['family'] {
21+
'RedHat': {
22+
if $facts['os']['release']['major'] == '7' {
23+
# The CentOS docker image has a yum config that won't install docs, to keep used space low
24+
# zabbix packages their SQL file as doc, we need that for bootstrapping the database
25+
augeas { 'remove tsflags=nodocs from yum.conf':
26+
changes => [
27+
'rm /files/etc/yum.conf/main/tsflags',
28+
],
29+
}
30+
}
31+
}
32+
default: {}
33+
}
Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,33 @@
11
# frozen_string_literal: true
22

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

11-
# The Ubuntu 18.04+ docker image has a dpkg config that won't install docs, to keep used space low
12-
# zabbix packages their SQL file as doc, we need that for bootstrapping the database
13-
shell('rm -f /etc/dpkg/dpkg.cfg.d/excludes') if fact('os.distro.id') == 'Ubuntu'
6+
apply_manifest <<~PUPPET
7+
$services = $facts['os']['family'] ? {
8+
'RedHat' => ['zabbix-server', 'httpd'],
9+
'Debian' => ['zabbix-server', 'apache2'],
10+
default => [],
11+
}
12+
service { $services:
13+
ensure => stopped
14+
}
1415
15-
# On Debian it seems that make is searching for mkdir in /usr/bin/ but mkdir
16-
# does not exist. Symlink it from /bin/mkdir to make it work.
17-
shell('ln -sf /bin/mkdir /usr/bin/mkdir') if fact('os.distro.id') == 'Debian'
16+
$packages = $facts['os']['family'] ? {
17+
'RedHat' => ['zabbix-server-pgsql', 'zabbix-server-pgsql-scl', 'zabbix-web', 'zabbix-web-pgsql', 'zabbix-web-pgsql-scl', 'zabbix-frontend-php', 'zabbix-sql-scripts'],
18+
'Debian' => ['zabbix-server-pgsql', 'zabbix-web-pgsql', 'zabbix-frontend-php', 'zabbix-sql-scripts'],
19+
default => [],
20+
}
21+
package { $packages:
22+
ensure => purged
23+
}
24+
PUPPET
1825

19-
cleanup_puppet = <<-SHELL
20-
$services = $facts['os']['family'] ? {
21-
'RedHat' => ['zabbix-server', 'httpd'],
22-
'Debian' => ['zabbix-server', 'apache2'],
23-
default => [],
24-
}
25-
service { $services:
26-
ensure => stopped
27-
}
28-
29-
$packages = $facts['os']['family'] ? {
30-
'RedHat' => ['zabbix-server-pgsql', 'zabbix-server-pgsql-scl', 'zabbix-web', 'zabbix-web-pgsql', 'zabbix-web-pgsql-scl', 'zabbix-frontend-php', 'zabbix-sql-scripts'],
31-
'Debian' => ['zabbix-server-pgsql', 'zabbix-web-pgsql', 'zabbix-frontend-php', 'zabbix-sql-scripts'],
32-
default => [],
33-
}
34-
package { $packages:
35-
ensure => purged
36-
}
37-
SHELL
38-
39-
cleanup_script = <<-SHELL
40-
/opt/puppetlabs/puppet/bin/gem uninstall zabbixapi -a
41-
rm -f /etc/zabbix/.*done
42-
if id postgres > /dev/null 2>&1; then
43-
su - postgres -c "psql -c 'drop database if exists zabbix_server;'"
44-
fi
26+
shell <<~SHELL
27+
/opt/puppetlabs/puppet/bin/gem uninstall zabbixapi -a
28+
rm -f /etc/zabbix/.*done
29+
if id postgres > /dev/null 2>&1; then
30+
su - postgres -c "psql -c 'drop database if exists zabbix_server;'"
31+
fi
4532
SHELL
46-
47-
apply_manifest(cleanup_puppet)
48-
shell(cleanup_script)
4933
end

0 commit comments

Comments
 (0)