Skip to content
Snippets Groups Projects
Commit 7c9e288b authored by DJ Mountney's avatar DJ Mountney Committed by Jarka Kadlecova
Browse files

Merge branch '2774-update_databases-assumes-a-populated-databases-json' into 'master'

Resolve "update_databases assumes a populated databases.json"

Closes #2774

See merge request !1924
# Conflicts:
#	CHANGELOG.md
parent 3e8e2472
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -25,10 +25,11 @@ omnibus-gitlab repository.
9.5.5
 
- Add more options to repmgr.conf template
- Update pgbouncer to use one style of logging
- Update pgbouncer to use one style of logging
- Set bootstrap_expect to default to 3 for consul servers
- Restart repmgrd after nodes are registered with a cluster
- Add --node option to gitlab-ctl repmgr standby unregister
- Fix bug where pgb-notify would fail when databases.json was empty
 
9.5.4
 
Loading
Loading
require 'chef/mixins'
require 'erb'
 
# For testing purposes, if the first path cannot be found load the second
Loading
Loading
@@ -9,7 +10,7 @@ end
 
module Pgbouncer
class Databases
attr_accessor :install_path, :databases, :options, :ini_file, :json_file, :template_file, :attributes, :userinfo
attr_accessor :install_path, :databases, :options, :ini_file, :json_file, :template_file, :attributes, :userinfo, :database
attr_reader :data_path
 
def initialize(options, install_path, base_data_path)
Loading
Loading
@@ -20,12 +21,22 @@ module Pgbouncer
@ini_file = options['databases_ini'] || attributes['gitlab']['pgbouncer']['databases_ini']
@json_file = options['databases_json'] || attributes['gitlab']['pgbouncer']['databases_json']
@template_file = "#{@install_path}/embedded/cookbooks/gitlab-ee/templates/default/databases.ini.erb"
@database = if attributes.key?('gitlab')
attributes['gitlab']['gitlab-rails']['db_database']
else
'gitlabhq_production'
end
@databases = update_databases(JSON.parse(File.read(@json_file)))
@userinfo = GitlabCtl::Util.userinfo(options['host_user']) if options['host_user']
end
 
def update_databases(original)
updated = {}
if original.empty?
original = {
database => {}
}
end
updated = Chef::Mixin::DeepMerge.merge(updated, original)
original.each do |db, settings|
updated[db] = ''
settings['host'] = options['newhost'] if options['newhost']
Loading
Loading
Loading
Loading
@@ -9,6 +9,9 @@ describe Pgbouncer::Databases do
{
normal: {
gitlab: {
'gitlab-rails': {
db_database: 'fake_database'
},
pgbouncer: {
databases_ini: '/fakedata/pgbouncer/databases.ini',
databases_json: '/fakedata/pgbouncer/databases.json'
Loading
Loading
@@ -81,4 +84,17 @@ describe Pgbouncer::Databases do
)
end
end
context 'with empty databases.json' do
before do
allow(File).to receive(:read).with('/fakedata/pgbouncer/databases.json').and_return({}.to_s)
@obj = Pgbouncer::Databases.new({}, '/fakeinstall', '/fakedata')
end
it 'should generate an databases.ini with sane defaults' do
expect(@obj.render).to eq(
"[databases]\n\nfake_database = \n\n"
)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment