Skip to content
Snippets Groups Projects
Commit 9886fcdf authored by Ian Baum's avatar Ian Baum
Browse files

Update postgresql_user resource to allow different helpers

Geo uses it's own subclass of BasePgHelper
* Default to PgHelper, but allow user to provide a helper
* Remove protected status from service_name and service_cmd methods
parent d66a7ab0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -126,6 +126,7 @@ database_name = node['gitlab']['geo-secondary']['db_database']
 
if node['gitlab']['geo-postgresql']['enable']
postgresql_user gitlab_sql_user do
helper pg_helper
action :create
end
 
Loading
Loading
Loading
Loading
@@ -97,8 +97,6 @@ class BasePgHelper
EOF
end
 
protected
def service_name
raise NotImplementedError
end
Loading
Loading
Loading
Loading
@@ -2,8 +2,6 @@ require_relative 'base_pg_helper'
 
# Helper class to interact with bundled Geo PostgreSQL instance
class GeoPgHelper < BasePgHelper
protected
# internal name for the service (node['gitlab'][service_name])
def service_name
'geo-postgresql'
Loading
Loading
Loading
Loading
@@ -2,8 +2,6 @@ require_relative 'base_pg_helper'
 
# Helper class to interact with bundled PostgreSQL instance
class PgHelper < BasePgHelper
protected
# internal name for the service (node['gitlab'][service_name])
def service_name
'postgresql'
Loading
Loading
Loading
Loading
@@ -2,10 +2,10 @@ resource_name :postgresql_user
 
property :username, String, name_property: true
property :password, String
property :helper, default: PgHelper.new(node)
 
action :create do
account_helper = AccountHelper.new(node)
pg_helper = PgHelper.new(node)
 
query = if password.nil?
"CREATE USER #{username};"
Loading
Loading
@@ -13,10 +13,10 @@ action :create do
"CREATE USER #{username} PASSWORD '#{password}';"
end
execute "create #{username} postgresql user" do
command %(/opt/gitlab/bin/gitlab-psql -d template1 -c "#{query}")
command %(/opt/gitlab/bin/#{helper.service_cmd} -d template1 -c "#{query}")
user account_helper.postgresql_user
# Added retries to give the service time to start on slower systems
retries 20
not_if { !pg_helper.is_running? || pg_helper.user_exists?(username) }
not_if { !helper.is_running? || helper.user_exists?(username) }
end
end
Loading
Loading
@@ -32,6 +32,10 @@ describe 'geo postgresql 9.2' do
expect(chef_run).to include_recipe('gitlab::postgresql-bin')
end
 
it 'creates the gitlab_geo role in the geo-postgresql database' do
expect(chef_run).to create_postgresql_user('gitlab_geo')
end
it 'correctly sets the shared_preload_libraries default setting' do
expect(chef_run.node['gitlab']['geo-postgresql']['shared_preload_libraries']).to be_nil
 
Loading
Loading
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