Skip to content

Commit e5f68d3

Browse files
committed
Use postgres for local connections in all DBs
1 parent 0674a3c commit e5f68d3

6 files changed

Lines changed: 66 additions & 1 deletion

File tree

definitions/features/candlepin_database.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def load_configuration
4747
'driver_class' => full_config['jpa.config.hibernate.connection.driver_class'],
4848
'url' => url,
4949
}
50+
51+
# Build connection string for pg_dump (only used for local databases)
52+
@configuration['connection_string'] = "postgres:///#{@configuration['database']}"
5053
end
5154

5255
def extend_with_db_options

definitions/features/foreman_database.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def load_configuration
4343

4444
@configuration = config['production']
4545
@configuration['host'] ||= 'localhost'
46+
47+
# Build connection string for pg_dump (only used for local databases)
48+
@configuration['connection_string'] = "postgres:///#{@configuration['database']}"
4649
@configuration
4750
end
4851
end

definitions/features/pulpcore_database.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def load_configuration
4141
@configuration['database'] = db_config['NAME']
4242
@configuration['username'] = db_config['USER']
4343
@configuration['password'] = db_config['PASSWORD']
44+
45+
# Build connection string for pg_dump (only used for local databases)
46+
@configuration['connection_string'] = "postgres:///#{db_config['NAME']}"
4447
@configuration
4548
end
49+
50+
4651
end

test/definitions/features/candlepin_database_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,21 @@ def stub_without_ssl_config(&block)
3636
refute_includes url, 'sslrootcert=/usr/share/foreman/root.crt'
3737
end
3838
end
39+
40+
it 'Sets connection_string for local database backups with SSL' do
41+
stub_with_ssl_config do
42+
config = subject.configuration
43+
assert_equal 'candlepin1db', config['database']
44+
assert_equal 'postgres:///candlepin1db', config['connection_string']
45+
end
46+
end
47+
48+
it 'Sets connection_string for local database backups without SSL' do
49+
stub_without_ssl_config do
50+
config = subject.configuration
51+
assert_equal 'candlepin', config['database']
52+
assert_equal 'postgres:///candlepin', config['connection_string']
53+
end
54+
end
3955
end
4056
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'test_helper'
2+
3+
describe Features::ForemanDatabase do
4+
include DefinitionsTestHelper
5+
6+
subject { Features::ForemanDatabase.new }
7+
8+
describe '.configuration' do
9+
it 'returns hash with DB config and connection_string' do
10+
database_yml_content = {
11+
'production' => {
12+
'adapter' => 'postgresql',
13+
'host' => 'localhost',
14+
'port' => 5432,
15+
'database' => 'foreman',
16+
'username' => 'foreman',
17+
'password' => 'password'
18+
}
19+
}
20+
21+
File.expects(:exist?).with('/etc/foreman/database.yml').returns(true)
22+
File.expects(:read).with('/etc/foreman/database.yml').returns('mocked_yaml_content')
23+
YAML.expects(:load).with('mocked_yaml_content').returns(database_yml_content)
24+
25+
expected = {
26+
'adapter' => 'postgresql',
27+
'host' => 'localhost',
28+
'port' => 5432,
29+
'database' => 'foreman',
30+
'username' => 'foreman',
31+
'password' => 'password',
32+
'connection_string' => 'postgres:///foreman'
33+
}
34+
assert_equal expected, subject.configuration
35+
end
36+
end
37+
end

test/definitions/features/pulpcore_database_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
JSON
1616
subject.expects(:execute!).with(expected_command, merge_stderr: false).returns(manager_return)
1717
expected = { "adapter" => "postgresql", "host" => "remotedb", "port" => "5432",
18-
"database" => "pulpcore", "username" => "pulp", "password" => "password" }
18+
"database" => "pulpcore", "username" => "pulp", "password" => "password",
19+
"connection_string" => "postgres:///pulpcore" }
1920
assert_equal expected, subject.configuration
2021
end
2122
end

0 commit comments

Comments
 (0)