newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / spec_helper_acceptance.rb
1 require 'beaker-rspec/spec_helper'
2 require 'beaker-rspec/helpers/serverspec'
3 require 'beaker/puppet_install_helper'
4 require 'beaker/module_install_helper'
5
6 run_puppet_install_helper
7 install_ca_certs unless ENV['PUPPET_INSTALL_TYPE'] =~ /pe/i
8 install_module_on(hosts)
9 install_module_dependencies_on(hosts)
10
11 UNSUPPORTED_PLATFORMS = ['AIX','windows','Solaris','Suse']
12
13 class String
14   # Provide ability to remove indentation from strings, for the purpose of
15   # left justifying heredoc blocks.
16   def unindent
17     gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
18   end
19 end
20
21 def shellescape(str)
22   str = str.to_s
23
24   # An empty argument will be skipped, so return empty quotes.
25   return "''" if str.empty?
26
27   str = str.dup
28
29   # Treat multibyte characters as is.  It is caller's responsibility
30   # to encode the string in the right encoding for the shell
31   # environment.
32   str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
33
34   # A LF cannot be escaped with a backslash because a backslash + LF
35   # combo is regarded as line continuation and simply ignored.
36   str.gsub!(/\n/, "'\n'")
37
38   return str
39 end
40
41 def psql(psql_cmd, user = 'postgres', exit_codes = [0,1], &block)
42   psql = "psql #{psql_cmd}"
43   shell("su #{shellescape(user)} -c #{shellescape(psql)}", :acceptable_exit_codes => exit_codes, &block)
44 end
45
46 RSpec.configure do |c|
47   # Readable test descriptions
48   c.formatter = :documentation
49
50   # Configure all nodes in nodeset
51   c.before :suite do
52     # Set up selinux if appropriate.
53     if fact('osfamily') == 'RedHat' && fact('selinux') == 'true'
54       pp = <<-EOS
55         if $::osfamily == 'RedHat' and $::selinux == 'true' {
56           $semanage_package = $::operatingsystemmajrelease ? {
57             '5'     => 'policycoreutils',
58             default => 'policycoreutils-python',
59           }
60
61           package { $semanage_package: ensure => installed }
62           exec { 'set_postgres':
63             command     => 'semanage port -a -t postgresql_port_t -p tcp 5433',
64             path        => '/bin:/usr/bin/:/sbin:/usr/sbin',
65             subscribe   => Package[$semanage_package],
66           }
67         }
68       EOS
69
70       apply_manifest_on(agents, pp, :catch_failures => false)
71     end
72
73     # net-tools required for netstat utility being used by be_listening
74     if fact('osfamily') == 'RedHat' && fact('operatingsystemmajrelease') == '7'
75       pp = <<-EOS
76         package { 'net-tools': ensure => installed }
77       EOS
78
79       apply_manifest_on(agents, pp, :catch_failures => false)
80     end
81
82     hosts.each do |host|
83       on host, "/bin/touch #{host['puppetpath']}/hiera.yaml"
84       on host, 'chmod 755 /root'
85       if fact_on(host, 'osfamily') == 'Debian'
86         on host, "echo \"en_US ISO-8859-1\nen_NG.UTF-8 UTF-8\nen_US.UTF-8 UTF-8\n\" > /etc/locale.gen"
87         on host, '/usr/sbin/locale-gen'
88         on host, '/usr/sbin/update-locale'
89       end
90     end
91   end
92 end