diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index 07c882609bae9b1dcc59ba70bdfc2cd2baaaae57..33654bfb85650657542629c74a92f0b11b9c4862 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -1279,22 +1279,13 @@ production: &base # Default is '.gitlab_workhorse_secret' relative to Rails.root (i.e. root of the GitLab app). # secret_file: /home/git/gitlab/.gitlab_workhorse_secret - # This section to be removed when we merge https://gitlab.com/gitlab-org/gitlab-development-kit/-/merge_requests/4382 - topology_service: - # enabled: false - # address: topology-service.gitlab.example.com:443 - # ca_file: /home/git/gitlab/config/topology-service-ca.pem - # certificate_file: /home/git/gitlab/config/topology-service-cert.pem - # private_key_file: /home/git/gitlab/config/topology-service-key.pem - cell: + # enabled: false # id: null # name: null - # skip_sequence_alteration: false # To be removed with https://gitlab.com/gitlab-org/gitlab-development-kit/-/merge_requests/4382 # database: # skip_sequence_alteration: false - # topology_service: - # enabled: false + # topology_service_client: # address: topology-service.gitlab.example.com:443 # ca_file: /home/git/gitlab/config/topology-service-ca.pem # certificate_file: /home/git/gitlab/config/topology-service-cert.pem diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 1bd211f10dced67dde72d99e33927d2ab5e71821..aa62fb56cecd9774d25ab5edb24e804ded56639f 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -1072,16 +1072,17 @@ # Cells # Settings['cell'] ||= {} +Settings.cell['enabled'] ||= false # All Cells Features are disabled by default Settings.cell['id'] ||= nil Settings.cell['database'] ||= {} Settings.cell.database['skip_sequence_alteration'] ||= false -# This ternary operation expression to be removed when we merge https://gitlab.com/gitlab-org/gitlab-development-kit/-/merge_requests/4382 -Settings.cell['topology_service'] ||= Settings.respond_to?(:topology_service) ? Settings.topology_service || {} : {} -Settings.cell.topology_service['enabled'] ||= false -Settings.cell.topology_service['address'] ||= 'topology-service.gitlab.example.com:443' -Settings.cell.topology_service['ca_file'] ||= '/home/git/gitlab/config/topology-service-ca.pem' -Settings.cell.topology_service['certificate_file'] ||= '/home/git/gitlab/config/topology-service-cert.pem' -Settings.cell.topology_service['private_key_file'] ||= '/home/git/gitlab/config/topology-service-key.pem' + +# Topology Service Client Settings +Settings.cell['topology_service_client'] ||= Settings.respond_to?(:topology_service) ? Settings.topology_service || {} : {} +Settings.cell.topology_service_client['address'] ||= 'topology-service.gitlab.example.com:443' +Settings.cell.topology_service_client['ca_file'] ||= '/home/git/gitlab/config/topology-service-ca.pem' +Settings.cell.topology_service_client['certificate_file'] ||= '/home/git/gitlab/config/topology-service-cert.pem' +Settings.cell.topology_service_client['private_key_file'] ||= '/home/git/gitlab/config/topology-service-key.pem' # # GitLab KAS diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 18447093df161c56774e4526f1462d7e40d61796..425a1139899ca461e81ea77705d33165a01ad532 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -18,7 +18,9 @@ {} end -cell_id = Gitlab.config.cell.id +# If session_cookie_token_prefix is not set, we fall back to cell id +# only if the instance was enabled as a cell +cell_id = Gitlab.config.cell.id if Gitlab.config.cell.enabled session_cookie_token_prefix = if raw_config.fetch(:session_cookie_token_prefix, '').present? raw_config.fetch(:session_cookie_token_prefix) elsif cell_id.present? diff --git a/config/initializers/validate_cell_config.rb b/config/initializers/validate_cell_config.rb index dbba5904ad65b23882bae4c6090b3717dc7d42a9..9a43ecfe68de04c3810000891a8be1d65def9644 100644 --- a/config/initializers/validate_cell_config.rb +++ b/config/initializers/validate_cell_config.rb @@ -4,10 +4,13 @@ ValidationError = Class.new(StandardError) -if Gitlab.config.cell.id.present? && !Gitlab.config.cell.topology_service.enabled - raise ValidationError, "Topology Service is not configured, but Cell ID is set" -end +if Gitlab.config.cell.enabled + raise ValidationError, "Cell ID is not set to a valid positive integer" if Gitlab.config.cell.id.to_i < 1 -if Gitlab.config.cell.topology_service.enabled && Gitlab.config.cell.id.blank? - raise ValidationError, "Topology Service is enabled, but Cell ID is not set" + Settings.topology_service_settings.each do |setting| + setting_value = Gitlab.config.cell.topology_service_client.send(setting) + raise ValidationError, "Topology Service setting '#{setting}' is not set" if setting_value.blank? + end +elsif Gitlab.config.cell.id.present? + raise ValidationError, "Cell ID is set but Cell is not enabled" end diff --git a/config/settings.rb b/config/settings.rb index bd9eed593a33326480e950c52224f27706710af2..9368d9ca173e3ed5f59e020cb3661104c2afdd41 100644 --- a/config/settings.rb +++ b/config/settings.rb @@ -179,13 +179,8 @@ def build_sidekiq_routing_rules(rules) [[Gitlab::SidekiqConfig::WorkerMatcher::WILDCARD_MATCH, 'default']] end - # This method dictates whether the GitLab instance is part of a cells cluster - def topology_service_enabled? - cell.topology_service.enabled - end - - def skip_sequence_alteration? - cell.database.respond_to?(:skip_sequence_alteration) && cell.database.skip_sequence_alteration + def topology_service_settings + %w[address ca_file certificate_file private_key_file] end private diff --git a/doc/administration/cells.md b/doc/administration/cells.md index 4dd6e3163b0044e50ed8605160187de9d4f5c3ba..f7d42448fd7a1269547182a3766deb3a87a063b0 100644 --- a/doc/administration/cells.md +++ b/doc/administration/cells.md @@ -34,26 +34,26 @@ The cells related configuration in `config/gitlab.yml` is in this format: ```yaml cell: + enabled: true id: 1 database: skip_sequence_alteration: false - topology_service: - enabled: true + topology_service_client: address: topology-service.gitlab.example.com:443 ca_file: /home/git/gitlab/config/topology-service-ca.pem certificate_file: /home/git/gitlab/config/topology-service-cert.pem private_key_file: /home/git/gitlab/config/topology-service-key.pem ``` -| Configuration | Default value | Description | -| ------ |---------------|-------------------------------------------------------------------------------------------------------------------------------------| -| `cell.id` | `nil` | Unique integer identifier for the cell in a cluster. For use when the instance is part of a cell cluster. | -| `database.skip_sequence_alteration` | `false` | When `true`, skips database sequence alteration for the cell. Enable for the legacy cell (`cell-1`) before the monolith cell is available for use, being tracked in this epic: [Phase 6: Monolith Cell](https://gitlab.com/groups/gitlab-org/-/epics/14513). | -| `topology_service.enabled` | `false` | When `true`, enables the topology service client to connect to the topology service, which is required to be considered a cell. | -| `topology_service.address` | `nil` | Address and port of the topology service. | -| `topology_service.ca_file` | `nil` | Path to the CA certificate file for secure communication. | -| `topology_service.certificate_file` | `nil` | Path to the client certificate file. | -| `topology_service.private_key_file` | `nil` | Path to the private key file. | +| Configuration | Default value | Description | +|--------------------------------------------|-------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `cell.enabled` | `false` | To configure whether the instance is a Cell or not. `false` means all Cell features are disabled. `session_cookie_prefix_token` is not affected, and can be set separately. | +| `cell.id` | `nil` | Required to be a positive integer when `cell.enabled` is `true`. Otherwise, it must be `nil`. This is the unique integer identifier for the cell in a cluster. This ID is used inside the routable tokens. When `cell.id` is `nil`, the other attributes inside the routable tokens, like `organization_id` will still be used | +| `cell.database.skip_sequence_alteration` | `false` | When `true`, skips database sequence alteration for the cell. Enable for the legacy cell (`cell-1`) before the monolith cell is available for use, being tracked in this epic: [Phase 6: Monolith Cell](https://gitlab.com/groups/gitlab-org/-/epics/14513). | +| `cell.topology_service_client.address` | `"topology-service.gitlab.example.com:443"` | Required when `cell.enabled` is `true`. Address and port of the topology service server. | +| `cell.topology_service_client.ca_file` | `"/home/git/gitlab/config/topology-service-ca.pem"` | Required when `cell.enabled` is `true`. Path to the CA certificate file for secure communication. | +| `cell.topology_service_client.certificate_file` | `"/home/git/gitlab/config/topology-service-cert.pem"` | Required when `cell.enabled` is `true`. Path to the client certificate file. | +| `cell.topology_service_client.private_key_file` | `"/home/git/gitlab/config/topology-service-key.pem"` | Required when `cell.enabled` is `true`. Path to the private key file. | ## Related configuration diff --git a/lib/authn/token_field/generator/routable_token.rb b/lib/authn/token_field/generator/routable_token.rb index a3803163bb08cf06f92ec53bd9f1268692b294de..15d68a9d7f7c09ef25f760da51ec1b9fee7ce625 100644 --- a/lib/authn/token_field/generator/routable_token.rb +++ b/lib/authn/token_field/generator/routable_token.rb @@ -12,7 +12,7 @@ class RoutableToken MAXIMUM_SIZE_OF_ROUTING_PAYLOAD = 159 DEFAULT_ROUTING_PAYLOAD_HASH = { - c: ->(_) { Settings.cell[:id] } + c: ->(_) { Gitlab.config.cell.id } }.freeze PayloadTooLarge = Class.new(RuntimeError) diff --git a/lib/gitlab/topology_service_client/base_service.rb b/lib/gitlab/topology_service_client/base_service.rb index 2d7a5e130c93dbdd5b11a1d7a32d01db20162766..fefc168dbf03057627cc49558039d73e2b975640 100644 --- a/lib/gitlab/topology_service_client/base_service.rb +++ b/lib/gitlab/topology_service_client/base_service.rb @@ -28,11 +28,11 @@ def service_credentials end def topology_service_address - Gitlab.config.cell.topology_service.address + Gitlab.config.cell.topology_service_client.address end def enabled? - Gitlab.config.topology_service_enabled? + Gitlab.config.cell.enabled end end end diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 7089f95d91213d5d8d65e48abe288ece70716883..9f511e44c173f86d70ea9b553adcbb9df2ecf0d6 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -149,9 +149,9 @@ namespace :gitlab do end def alter_cell_sequences_range - return unless Gitlab.config.topology_service_enabled? + return unless Gitlab.config.cell.enabled - return puts "Skipping altering cell sequences range" if Gitlab.config.skip_sequence_alteration? + return puts "Skipping altering cell sequences range" if Gitlab.config.cell.database.skip_sequence_alteration sequence_range = Gitlab::TopologyServiceClient::CellService.new.cell_sequence_range diff --git a/lib/tasks/gitlab/db/alter_cell_sequences_range.rake b/lib/tasks/gitlab/db/alter_cell_sequences_range.rake index a187e0454ef4d17fd9f7adb0a4cacab04192c49d..36304a77af2b39d5bd810120dc7b56408fee4575 100644 --- a/lib/tasks/gitlab/db/alter_cell_sequences_range.rake +++ b/lib/tasks/gitlab/db/alter_cell_sequences_range.rake @@ -7,8 +7,8 @@ namespace :gitlab do task :alter_cell_sequences_range, [:minval, :maxval] => :environment do |_t, args| next unless Gitlab.com_except_jh? || Gitlab.dev_or_test_env? - # This is a safety check to ensure this rake does not alters the sequences for the Legacy Cell - next if Gitlab.config.skip_sequence_alteration? + # This is a safety check to ensure this rake does not alter the sequences for the Legacy Cell + next if Gitlab.config.cell.database.skip_sequence_alteration Gitlab::Database::EachDatabase.each_connection do |connection, _database_name| Gitlab::Database::AlterCellSequencesRange.new(args.minval&.to_i, args.maxval&.to_i, connection).execute diff --git a/spec/initializers/1_settings_spec.rb b/spec/initializers/1_settings_spec.rb index 2f7adb47eab1bcfb7f739e8603611eb86cb1737b..67a3db46b42c82fbb2ab75b0da9e7ceb7d3bbc51 100644 --- a/spec/initializers/1_settings_spec.rb +++ b/spec/initializers/1_settings_spec.rb @@ -54,4 +54,27 @@ it { expect(Settings.gitlab.log_decompressed_response_bytesize).to eq(10) } end end + + describe 'cell configuration' do + let(:config) do + { + address: 'test-topology-service-host:8080', + ca_file: '/test/topology-service-ca.pem', + certificate_file: '/test/topology-service-cert.pem', + private_key_file: '/test/topology-service-key.pem' + } + end + + context 'when legacy topology service config is provided' do + before do + stub_config({ cell: { enabled: true, id: 1 }, topology_service: config }) + load_settings + end + + it { expect(Settings.cell.topology_service_client.address).to eq(config[:address]) } + it { expect(Settings.cell.topology_service_client.ca_file).to eq(config[:ca_file]) } + it { expect(Settings.cell.topology_service_client.certificate_file).to eq(config[:certificate_file]) } + it { expect(Settings.cell.topology_service_client.private_key_file).to eq(config[:private_key_file]) } + end + end end diff --git a/spec/initializers/session_store_spec.rb b/spec/initializers/session_store_spec.rb index c95b130627b00da43cbbb42c32726a81452a92df..94455ef89e33f085c07fd26275483c09c46aa5b3 100644 --- a/spec/initializers/session_store_spec.rb +++ b/spec/initializers/session_store_spec.rb @@ -25,9 +25,9 @@ load_session_store end - context 'when cell.id is configured' do + context 'when cell is enabled' do before do - stub_config(cell: { id: 1 }) + stub_config(cell: { enabled: true, id: 1 }) end it 'initialized as a `redis_store` with session cookies prefix that includes cell id' do @@ -43,9 +43,9 @@ end end - context 'when cell.id is not configured' do + context 'when cell is disabled' do before do - stub_config(cell: { id: nil }) + stub_config(cell: { enabled: false }) end it 'initialized as a `redis_store` with empty session cookie prefix' do diff --git a/spec/initializers/validate_cell_config_spec.rb b/spec/initializers/validate_cell_config_spec.rb index b095c93c0e70c5d1bf57f8b606f3c54d7e3095a7..7942cb8f8df1cb17be652e66971ed377f1d47e55 100644 --- a/spec/initializers/validate_cell_config_spec.rb +++ b/spec/initializers/validate_cell_config_spec.rb @@ -6,6 +6,23 @@ include StubENV let(:rails_configuration) { Rails::Application::Configuration.new(Rails.root) } + let(:valid_topology_service_client_config) do + { + address: 'topology-service.gitlab.example.com:443', + ca_file: '/home/git/gitlab/config/topology-service-ca.pem', + certificate_file: '/home/git/gitlab/config/topology-service-cert.pem', + private_key_file: '/home/git/gitlab/config/topology-service-key.pem' + } + end + + let(:incomplete_topology_service_client_config) do + { + address: '', + ca_file: '/home/git/gitlab/config/topology-service-ca.pem', + certificate_file: '/home/git/gitlab/config/topology-service-cert.pem', + private_key_file: '/home/git/gitlab/config/topology-service-key.pem' + } + end subject(:validate_config) do load Rails.root.join('config/initializers/validate_cell_config.rb') @@ -18,6 +35,8 @@ shared_examples 'with SKIP_CELL_CONFIG_VALIDATION=true' do before do stub_env('SKIP_CELL_CONFIG_VALIDATION', 'true') + # Wrong Cell configuration, because cell.id is missing + stub_config(cell: { enabled: true, id: nil, topology_service_client: valid_topology_service_client_config }) end it 'does not raise exception' do @@ -25,9 +44,9 @@ end end - context 'when topology service is correctly configured' do + context 'when cell is correctly configured' do before do - stub_config(cell: { id: 1, topology_service: { enabled: true } }) + stub_config(cell: { id: 1, enabled: true, topology_service_client: valid_topology_service_client_config }) end it 'does not raise exception' do @@ -35,36 +54,60 @@ end end - context 'when topology service is not configured' do - before do - stub_config(cell: { id: nil, topology_service: { enabled: false } }) + context 'when cell is not configured' do + context 'when cell id is nil' do + before do + stub_config(cell: { enabled: false, id: nil }) + end + + it 'does not raise exception' do + expect { validate_config }.not_to raise_error + end end - it 'does not raise exception' do - expect { validate_config }.not_to raise_error + context 'when cell id is not nil' do + before do + stub_config(cell: { enabled: false, id: 3 }) + end + + it 'raises an exception' do + expect { validate_config }.to raise_error("Cell ID is set but Cell is not enabled") + end end end context 'when configuration is wrong' do - context 'when only cell.id is configured' do + context 'when cell is enabled by cell id is not set' do before do - stub_config(cell: { id: 1, topology_service: { enabled: false } }) + stub_config(cell: { enabled: true, id: nil, topology_service_client: valid_topology_service_client_config }) end - it 'does not raise exception' do - expect { validate_config }.to raise_error("Topology Service is not configured, but Cell ID is set") + it 'raises exception about missing cell id' do + expect { validate_config }.to raise_error("Cell ID is not set to a valid positive integer") end it_behaves_like 'with SKIP_CELL_CONFIG_VALIDATION=true' end - context 'when only topology service is enabled' do + context 'when cell is enabled by cell id is not valid' do before do - stub_config(cell: { id: nil, topology_service: { enabled: true } }) + stub_config(cell: { enabled: true, id: 0, topology_service_client: valid_topology_service_client_config }) end - it 'does not raise exception' do - expect { validate_config }.to raise_error("Topology Service is enabled, but Cell ID is not set") + it 'raises exception about missing cell id' do + expect { validate_config }.to raise_error("Cell ID is not set to a valid positive integer") + end + + it_behaves_like 'with SKIP_CELL_CONFIG_VALIDATION=true' + end + + context 'when cell is enabled' do + before do + stub_config(cell: { enabled: true, id: 1, topology_service_client: incomplete_topology_service_client_config }) + end + + it 'raises exception about missing topology service client config' do + expect { validate_config }.to raise_error("Topology Service setting 'address' is not set") end it_behaves_like 'with SKIP_CELL_CONFIG_VALIDATION=true' diff --git a/spec/lib/authn/token_field/generator/routable_token_spec.rb b/spec/lib/authn/token_field/generator/routable_token_spec.rb index b95aeeeb40bd0176eeacdeb6e99dd5087c427135..872dcb3200cc7b614e949ccff0839ea8e43c657d 100644 --- a/spec/lib/authn/token_field/generator/routable_token_spec.rb +++ b/spec/lib/authn/token_field/generator/routable_token_spec.rb @@ -48,14 +48,14 @@ describe '#generate_token' do let(:random_bytes) { 'a' * described_class::RANDOM_BYTES_LENGTH } - let(:cell_setting) { {} } + let(:cell_setting) { { enabled: false, id: nil } } subject(:token) { generator.generate_token } before do allow(described_class) .to receive(:random_bytes).with(described_class::RANDOM_BYTES_LENGTH).and_return(random_bytes) - allow(Settings).to receive(:cell).and_return(cell_setting) + stub_config({ cell: cell_setting }) end shared_examples 'a routable token' do @@ -67,8 +67,8 @@ end end - context 'when Settings.cells.id is present' do - let(:cell_setting) { { id: 100 } } + context 'when Settings.cells.id is present and cell is enabled' do + let(:cell_setting) { { enabled: true, id: 100 } } it 'generates a routable token' do expect(token) diff --git a/spec/lib/ci/job_token/jwt_spec.rb b/spec/lib/ci/job_token/jwt_spec.rb index 99319389fbd634bb3dbfec5b62abc8cfeeabd227..da82a9496595c366bda509111bda15d37cb303e4 100644 --- a/spec/lib/ci/job_token/jwt_spec.rb +++ b/spec/lib/ci/job_token/jwt_spec.rb @@ -63,7 +63,7 @@ subject(:decoded_token) { described_class.decode(encoded_token) } before do - allow(Gitlab.config.cell).to receive(:id).and_return(cell_id) + stub_config(cell: { enabled: true, id: cell_id }) end context 'with a valid token' do @@ -212,12 +212,24 @@ let(:encoded_token) { described_class.encode(job) } let(:decoded_token) { described_class.decode(encoded_token) } - before do - allow(Gitlab.config.cell).to receive(:id).and_return(cell_id) + context 'when cell is enabled' do + before do + stub_config(cell: { enabled: true, id: cell_id }) + end + + it 'encodes the cell_id in the JWT payload' do + expect(decoded_token.cell_id).to eq(cell_id) + end end - it 'encodes the cell_id in the JWT payload' do - expect(decoded_token.cell_id).to eq(cell_id) + context 'when cell is disabled' do + before do + stub_config(cell: { enabled: false, id: nil }) + end + + it 'cell_id should not be encoded' do + expect(decoded_token.cell_id).to be_nil + end end end diff --git a/spec/lib/gitlab/topology_service_client/base_service_spec.rb b/spec/lib/gitlab/topology_service_client/base_service_spec.rb index 13681aa0183b9980b365bfbbe98f8b9352546a51..998696c6a36e35d1dc32c00bb79b0bc9a273fa98 100644 --- a/spec/lib/gitlab/topology_service_client/base_service_spec.rb +++ b/spec/lib/gitlab/topology_service_client/base_service_spec.rb @@ -6,9 +6,9 @@ subject(:base_service) { described_class.new } describe '#initialize' do - context 'when topology service is disabled' do - it 'raises an error when topology service is not enabled' do - expect(Gitlab.config.cell.topology_service).to receive(:enabled).and_return(false) + context 'when cell is disabled' do + it 'raises an error when cell is not enabled' do + expect(Gitlab.config.cell).to receive(:enabled).and_return(false) expect { base_service }.to raise_error(NotImplementedError) end diff --git a/spec/lib/gitlab/topology_service_client/cell_service_spec.rb b/spec/lib/gitlab/topology_service_client/cell_service_spec.rb index eff9c6aabff7443c6b0d5243a463427b73a57cd6..a58a6a043ee177de18b19129835737c0c05f4c78 100644 --- a/spec/lib/gitlab/topology_service_client/cell_service_spec.rb +++ b/spec/lib/gitlab/topology_service_client/cell_service_spec.rb @@ -18,16 +18,16 @@ describe '#get_cell_info' do context 'when topology service is disabled' do it 'raises an error when topology service is not enabled' do - expect(Gitlab.config.cell.topology_service).to receive(:enabled).and_return(false) + expect(Gitlab.config.cell).to receive(:enabled).and_return(false) expect { cell_service }.to raise_error(NotImplementedError) end end - context 'when topology service is enabled' do + context 'when cell is enabled' do before do allow(Gitlab.config.cell).to receive(:id).twice.and_return(1) - allow(Gitlab.config.cell.topology_service).to receive(:enabled).once.and_return(true) + allow(Gitlab.config.cell).to receive(:enabled).and_return(true) end it 'returns the cell information' do @@ -55,10 +55,10 @@ end describe '#cell_sequence_range' do - context 'when topology service is enabled' do + context 'when cell is enabled' do before do allow(Gitlab.config.cell).to receive(:id).twice.and_return(1) - allow(Gitlab.config.cell.topology_service).to receive(:enabled).once.and_return(true) + allow(Gitlab.config.cell).to receive(:enabled).and_return(true) end context 'when a cell exists in topology service' do diff --git a/spec/models/personal_access_token_spec.rb b/spec/models/personal_access_token_spec.rb index 51913ca79416848d341ca626789afdd246423b63..326b5d0bb39a1b648863a232ee4b41f86f058ee2 100644 --- a/spec/models/personal_access_token_spec.rb +++ b/spec/models/personal_access_token_spec.rb @@ -706,7 +706,7 @@ .to receive(:random_bytes).with(Authn::TokenField::Generator::RoutableToken::RANDOM_BYTES_LENGTH) .and_return(random_bytes) allow(Devise).to receive(:friendly_token).and_return(devise_token) - allow(Settings).to receive(:cell).and_return({ id: 1 }) + stub_config(cell: { enabled: true, id: 1 }) end context 'when :routable_pat feature flag is disabled' do diff --git a/spec/support/shared_contexts/models/concerns/token_authenticatable_shared_context.rb b/spec/support/shared_contexts/models/concerns/token_authenticatable_shared_context.rb index 69d0f4e611c71b7b18e587ff29a60c1cc4439b8e..0af4238c1ba50ee9b7afb9ba784b1956596e1d88 100644 --- a/spec/support/shared_contexts/models/concerns/token_authenticatable_shared_context.rb +++ b/spec/support/shared_contexts/models/concerns/token_authenticatable_shared_context.rb @@ -9,6 +9,6 @@ .to receive(:random_bytes).with(Authn::TokenField::Generator::RoutableToken::RANDOM_BYTES_LENGTH) .and_return(random_bytes) allow(Devise).to receive(:friendly_token).and_return(devise_token) - allow(Settings).to receive(:cell).and_return({ id: 1 }) + stub_config(cell: { enabled: true, id: 1 }) end end diff --git a/spec/tasks/gitlab/db/alter_cell_sequences_range_rake_spec.rb b/spec/tasks/gitlab/db/alter_cell_sequences_range_rake_spec.rb index 2651879575810d829ca28f1c843ab0d3f3e5f267..fb367fceb20875f70f2a89ba1eed9668285f6174 100644 --- a/spec/tasks/gitlab/db/alter_cell_sequences_range_rake_spec.rb +++ b/spec/tasks/gitlab/db/alter_cell_sequences_range_rake_spec.rb @@ -37,16 +37,18 @@ context 'when run in non Gitlab.com/dev/test environment' do before do allow(Gitlab).to receive_messages(com_except_jh?: false, dev_or_test_env?: false) - allow(Settings).to receive(:skip_sequence_alteration?).and_return(false) + stub_config(cell: { enabled: true, database: { skip_sequence_alteration: false } }) end it_behaves_like 'does not alter cell sequences range' end - context 'when run for legacy cell' do + # This setting (skip_sequence_alteration) is meant for the Legacy cell + # All additional Cells are still considered .com + context 'when skipping database sequence alteration' do before do allow(Gitlab).to receive_messages(com_except_jh?: true, dev_or_test_env?: true) - allow(Settings).to receive(:skip_sequence_alteration?).and_return(true) + stub_config(cell: { enabled: true, database: { skip_sequence_alteration: true } }) end it_behaves_like 'does not alter cell sequences range' @@ -55,7 +57,7 @@ context 'when run in Gitlab.com but not jh instance' do before do allow(Gitlab).to receive(:com_except_jh?).and_return(true) - allow(Settings).to receive(:skip_sequence_alteration?).and_return(false) + stub_config(cell: { enabled: true, database: { skip_sequence_alteration: false } }) end it_behaves_like 'alters cell sequences range' @@ -64,7 +66,7 @@ context 'when run in dev or test env' do before do allow(Gitlab).to receive(:dev_or_test_env?).and_return(true) - allow(Settings).to receive(:skip_sequence_alteration?).and_return(false) + stub_config(cell: { enabled: true, database: { skip_sequence_alteration: false } }) end it_behaves_like 'alters cell sequences range' diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb index e024835819261419a990774e6af9c329b2eba68f..d4cddf45ac5e025e3c4e588f9c757a930705ce3a 100644 --- a/spec/tasks/gitlab/db_rake_spec.rb +++ b/spec/tasks/gitlab/db_rake_spec.rb @@ -150,13 +150,11 @@ end describe 'configure' do - let(:topology_service_enabled) { true } let(:configured_cell) { true } let(:skip_sequence_alteration) { false } before do - allow(Settings).to receive(:topology_service_enabled?).and_return(topology_service_enabled) - allow(Settings).to receive(:skip_sequence_alteration?).and_return(skip_sequence_alteration) + stub_config(cell: { enabled: true, id: 1, database: { skip_sequence_alteration: skip_sequence_alteration } }) end context 'with a single database' do