Skip to content

Commit a617202

Browse files
authored
Merge pull request #682 from bastelfreak/helper2
Cleanup and fix acceptance test helper
2 parents 87e09e3 + c82c9e1 commit a617202

File tree

8 files changed

+19
-6
lines changed

8 files changed

+19
-6
lines changed

spec/acceptance/zabbix_application_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class { 'zabbix':
3838
# setup zabbix. Apache module isn't idempotent and requires a second run
3939
it 'works with no error on the first apply' do
4040
# Cleanup old database
41-
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"')
41+
cleanup_zabbix
4242

4343
apply_manifest(pp1, catch_failures: true)
4444
end

spec/acceptance/zabbix_host_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class { 'zabbix':
3131
# setup zabbix. Apache module isn't idempotent and requires a second run
3232
it 'works with no error on the first apply' do
3333
# Cleanup old database
34-
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"')
34+
cleanup_zabbix
3535

3636
apply_manifest(pp1, catch_failures: true)
3737
end

spec/acceptance/zabbix_hostgroup_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class { 'zabbix':
3636
shell('yum clean metadata') if fact('os.family') == 'RedHat'
3737

3838
# Cleanup old database
39-
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"')
39+
cleanup_zabbix
4040

4141
apply_manifest(pp, catch_failures: true)
4242
end

spec/acceptance/zabbix_proxy_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class { 'zabbix':
4242
shell('yum clean metadata') if fact('os.family') == 'RedHat'
4343

4444
# Cleanup old database
45-
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"')
45+
cleanup_zabbix
4646

4747
apply_manifest(pp, catch_failures: true)
4848
end

spec/acceptance/zabbix_template_host_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class { 'zabbix':
4747
shell("echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?><zabbix_export><version>3.0</version><date>2018-12-13T15:00:46Z</date><groups><group><name>Templates/Applications</name></group></groups><templates><template><template>TestTemplate1</template><name>TestTemplate1</name><description/><groups><group><name>Templates/Applications</name></group></groups><applications/><items/><discovery_rules/><macros/><templates/><screens/></template></templates></zabbix_export>' > /root/TestTemplate1.xml")
4848

4949
# Cleanup old database
50-
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"')
50+
cleanup_zabbix
5151

5252
apply_manifest(pp, catch_failures: true)
5353
end

spec/acceptance/zabbix_template_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class { 'zabbix':
3333
shell("echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?><zabbix_export><version>3.0</version><date>2018-12-13T15:00:46Z</date><groups><group><name>Templates/Applications</name></group></groups><templates><template><template>TestTemplate1</template><name>TestTemplate1</name><description/><groups><group><name>Templates/Applications</name></group></groups><applications/><items/><discovery_rules/><macros/><templates/><screens/></template></templates></zabbix_export>' > /root/TestTemplate1.xml")
3434

3535
# Cleanup old database
36-
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"')
36+
cleanup_zabbix
3737

3838
apply_manifest(pp, catch_failures: true)
3939
end

spec/spec_helper_acceptance.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
end
1818
end
1919
end
20+
21+
Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def cleanup_zabbix
2+
cleanup_script = <<-SHELL
3+
/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped
4+
/opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged
5+
rm -f /etc/zabbix/.*done
6+
if id postgres > /dev/null 2>&1; then
7+
su - postgres -c "psql -c 'drop database if exists zabbix_server;'"
8+
fi
9+
SHELL
10+
shell(cleanup_script)
11+
end

0 commit comments

Comments
 (0)