spec_helper_acceptance.rb 3.1 KB

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