This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
forked from puppetlabs/puppetlabs-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper_acceptance.rb
66 lines (60 loc) · 2.56 KB
/
spec_helper_acceptance.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'beaker-rspec'
require 'beaker/puppet_install_helper'
run_puppet_install_helper
RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Readable test descriptions
c.formatter = :documentation
# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
puppet_module_install(:source => proj_root, :module_name => 'haproxy')
hosts.each do |host|
on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install','puppetlabs-concat'), { :acceptable_exit_codes => [0,1] }
if fact('osfamily') == 'RedHat'
on host, puppet('module','install','stahnma/epel'), { :acceptable_exit_codes => [0,1] }
end
if fact('operatingsystem') == 'Debian'
on host, puppet('module','install','puppetlabs-apt'), { :acceptable_exit_codes => [0,1] }
apply_manifest(%{
include apt
include apt::backports
})
end
pp = <<-EOS
package { 'socat': ensure => present, }
package { 'screen': ensure => present, }
if $::osfamily == 'RedHat' {
class { 'epel': before => Package['socat'], }
service { 'iptables': ensure => stopped, }
exec { 'setenforce 0':
path => ['/bin','/usr/bin','/sbin','/usr/sbin'],
onlyif => 'which getenforce && getenforce | grep Enforcing',
}
if $::operatingsystemmajrelease == '7' {
# For `netstat` for serverspec
package { 'net-tools': ensure => present, }
}
}
EOS
apply_manifest(pp, :catch_failures => true)
['5556','5557'].each do |port|
content = "socat -v tcp-l:#{port},reuseaddr,fork system:\"printf \\'HTTP/1.1 200 OK\r\n\r\nResponse on #{port}\\'\",nofork"
create_remote_file(host, "/root/script-#{port}.sh", content)
shell(%{/usr/bin/screen -dmS script-#{port} sh /root/script-#{port}.sh})
sleep 1
shell(%{netstat -tnl|grep ':#{port}'})
end
end
end
# FM-5470, this was added to reset failed count and work around puppet 3.x
if ( (fact('operatingsystem') == 'SLES' and fact('operatingsystemmajrelease') == '12') or (fact('osfamily') == 'RedHat' and fact('operatingsystemmajrelease') == '7') )
c.after :each do
# not all tests have a haproxy service, so the systemctl call can fail,
# but we don't care as we only need to reset when it does.
shell('systemctl reset-failed haproxy.service || true')
end
end
end