newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / acceptance / remote_access_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'remote-access', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4   before do
5     skip "These tests require the spec/acceptance/nodesets/centos-64-x64-2-hosts nodeset"
6   end
7
8   describe "configuring multi-node postgresql" do
9
10     # Get the database's IP to connect to from the database
11     let(:database_ip_address) do
12       hosts_as('database').inject({}) do |memo,host|
13         fact_on host, "ipaddress_eth1"
14       end
15     end
16
17     hosts_as('database').each do |host|
18       it "should be able to configure a host as database on #{host}" do
19         pp = <<-EOS
20         # Stop firewall so we can easily connect
21         service {'iptables':
22           ensure => 'stopped',
23         }
24
25         class { 'postgresql::server':
26           ip_mask_allow_all_users => '0.0.0.0/0',
27           listen_addresses        => '*',
28         }
29
30         postgresql::server::db { 'puppet':
31           user     => 'puppet',
32           password => postgresql_password('puppet', 'puppet'),
33         }
34
35         postgresql::server::pg_hba_rule { 'allow full yolo access password':
36           type        => 'host',
37           database    => 'all',
38           user        => 'all',
39           address     => '0.0.0.0/0',
40           auth_method => 'password',
41           order       => '002',
42         }
43         EOS
44         apply_manifest_on(host, pp, :catch_failures => true)
45       end
46     end
47
48     hosts_as('client').each do |host|
49       it "should be able to configure a host as client on #{host} and then access database" do
50         pp = <<-EOS
51         class { 'postgresql::client':}
52
53         $connection_settings = {
54                                      'PGUSER'     => "puppet",
55                                      'PGPASSWORD' => "puppet",
56                                      'PGHOST'     => "#{database_ip_address}",
57                                      'PGPORT'     => "5432",
58                                      'PGDATABASE' => "puppet",
59                                   }
60
61         postgresql_psql { 'run using connection_settings':
62           command             => 'select 1',
63           psql_user           => 'root',
64           psql_group          => 'root',
65           connect_settings    => $connection_settings,
66         }
67         EOS
68         apply_manifest_on(host, pp, :catch_failures => true)
69       end
70     end
71   end
72 end