# HG changeset patch # User Douglas Barbosa Alexandre <dbalexandre@gmail.com> # Date 1652081261 0 # Mon May 09 07:27:41 2022 +0000 # Node ID 21e4f26d02b0c781e95a192050b063db616c44da # Parent e146c458914bac44fcaf07a58a7b328eeb3dede3 Remove Geo database settings only if some services are enabled Changelog: fixed diff --git a/files/gitlab-cookbooks/gitlab-ee/recipes/geo-secondary_disable.rb b/files/gitlab-cookbooks/gitlab-ee/recipes/geo-secondary_disable.rb --- a/files/gitlab-cookbooks/gitlab-ee/recipes/geo-secondary_disable.rb +++ b/files/gitlab-cookbooks/gitlab-ee/recipes/geo-secondary_disable.rb @@ -43,4 +43,5 @@ dependent_services.each do |svc| notifies :restart, omnibus_helper.restart_service_resource(svc) if omnibus_helper.should_notify?(svc) end + only_if { node['gitlab']['gitlab-rails']['enable'] } end diff --git a/spec/chef/cookbooks/gitlab-ee/recipes/geo-secondary_disable_spec.rb b/spec/chef/cookbooks/gitlab-ee/recipes/geo-secondary_disable_spec.rb --- a/spec/chef/cookbooks/gitlab-ee/recipes/geo-secondary_disable_spec.rb +++ b/spec/chef/cookbooks/gitlab-ee/recipes/geo-secondary_disable_spec.rb @@ -24,26 +24,64 @@ end context 'database.yml' do - it 'renders database.yml without geo database' do - expect(database_yml[:production].keys).not_to include(:geo) + shared_examples 'removes Geo database settings' do + it 'renders database.yml without geo database' do + expect(database_yml[:production].keys).not_to include(:geo) + end + + context 'with geo database specified' do + before do + stub_gitlab_rb( + gitlab_rails: { + databases: { + geo: { + enable: true, + db_connect_timeout: 50 + } + } + } + ) + end + + it 'renders database.yml without geo database' do + expect(database_yml[:production].keys).not_to include(:geo) + end + end end - context 'with geo database specified' do + context 'when gitlab_rails is enabled' do before do stub_gitlab_rb( gitlab_rails: { - databases: { - geo: { - enable: true, - db_connect_timeout: 50 - } - } + enable: true } ) end - it 'renders database.yml without geo database' do - expect(database_yml[:production].keys).not_to include(:geo) + include_examples "removes Geo database settings" + end + + context 'when geo-logcursor is enabled' do + before do + stub_gitlab_rb( + geo_logcursor: { + enable: true + } + ) + end + + include_examples "removes Geo database settings" + end + + context 'when gitlab_rails and geo-logcursor are disabled' do + before do + stub_gitlab_rb(geo_postgresql: { enable: true }, + gitlab_rails: { enable: false }, + geo_logcursor: { enable: false }) + end + + it 'does not render the database.yml file' do + expect(chef_run).not_to create_templatesymlink('Removes the geo database settings from database.yml and create a symlink to Rails root') end end end