2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.shared_examples 'moves repository to another storage' do |repository_type|
|
|
|
|
let(:project_repository_double) { double(:repository) }
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:original_project_repository_double) { double(:repository) }
|
2020-04-08 14:13:33 +05:30
|
|
|
let!(:project_repository_checksum) { project.repository.checksum }
|
|
|
|
|
|
|
|
let(:repository_double) { double(:repository) }
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:original_repository_double) { double(:repository) }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:repository_checksum) { repository.checksum }
|
|
|
|
|
|
|
|
before do
|
|
|
|
# Default stub for non-specified params
|
|
|
|
allow(Gitlab::Git::Repository).to receive(:new).and_call_original
|
|
|
|
|
|
|
|
allow(Gitlab::Git::Repository).to receive(:new)
|
|
|
|
.with('test_second_storage', project.repository.raw.relative_path, project.repository.gl_repository, project.repository.full_path)
|
|
|
|
.and_return(project_repository_double)
|
2020-10-24 23:57:45 +05:30
|
|
|
allow(Gitlab::Git::Repository).to receive(:new)
|
|
|
|
.with('default', project.repository.raw.relative_path, nil, nil)
|
|
|
|
.and_return(original_project_repository_double)
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
allow(Gitlab::Git::Repository).to receive(:new)
|
|
|
|
.with('test_second_storage', repository.raw.relative_path, repository.gl_repository, repository.full_path)
|
|
|
|
.and_return(repository_double)
|
2020-10-24 23:57:45 +05:30
|
|
|
allow(Gitlab::Git::Repository).to receive(:new)
|
|
|
|
.with('default', repository.raw.relative_path, nil, nil)
|
|
|
|
.and_return(original_repository_double)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the move succeeds', :clean_gitlab_redis_shared_state do
|
|
|
|
before do
|
2020-04-22 19:07:51 +05:30
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('default').and_call_original
|
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('test_second_storage').and_return(SecureRandom.uuid)
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
allow(project_repository_double).to receive(:replicate)
|
|
|
|
.with(project.repository.raw)
|
|
|
|
allow(project_repository_double).to receive(:checksum)
|
|
|
|
.and_return(project_repository_checksum)
|
|
|
|
|
|
|
|
allow(repository_double).to receive(:replicate)
|
|
|
|
.with(repository.raw)
|
|
|
|
allow(repository_double).to receive(:checksum)
|
|
|
|
.and_return(repository_checksum)
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(original_project_repository_double).to receive(:remove)
|
|
|
|
expect(original_repository_double).to receive(:remove)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it "moves the project and its #{repository_type} repository to the new storage and unmarks the repository as read-only" do
|
2020-04-08 14:13:33 +05:30
|
|
|
old_project_repository_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
|
|
|
project.repository.path_to_repo
|
|
|
|
end
|
|
|
|
|
|
|
|
old_repository_path = repository.full_path
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
result = subject.execute
|
2020-07-28 23:09:34 +05:30
|
|
|
project.reload
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(result).to be_success
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(project).not_to be_repository_read_only
|
|
|
|
expect(project.repository_storage).to eq('test_second_storage')
|
|
|
|
expect(gitlab_shell.repository_exists?('default', old_project_repository_path)).to be(false)
|
|
|
|
expect(gitlab_shell.repository_exists?('default', old_repository_path)).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
context ':repack_after_shard_migration feature flag disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(repack_after_shard_migration: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not enqueue a GC run' do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject.execute }
|
2021-03-11 19:13:27 +05:30
|
|
|
.not_to change(Projects::GitGarbageCollectWorker.jobs, :count)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context ':repack_after_shard_migration feature flag enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(repack_after_shard_migration: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not enqueue a GC run if housekeeping is disabled' do
|
|
|
|
stub_application_setting(housekeeping_enabled: false)
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject.execute }
|
2021-03-11 19:13:27 +05:30
|
|
|
.not_to change(Projects::GitGarbageCollectWorker.jobs, :count)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'enqueues a GC run' do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect { subject.execute }
|
2021-03-11 19:13:27 +05:30
|
|
|
.to change(Projects::GitGarbageCollectWorker.jobs, :count).by(1)
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'when the filesystems are the same' do
|
2021-03-11 19:13:27 +05:30
|
|
|
before do
|
|
|
|
expect(Gitlab::GitalyClient).to receive(:filesystem_id).twice.and_return(SecureRandom.uuid)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'updates the database without trying to move the repostory', :aggregate_failures do
|
2020-05-24 23:13:21 +05:30
|
|
|
result = subject.execute
|
2021-03-11 19:13:27 +05:30
|
|
|
project.reload
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(result).to be_success
|
|
|
|
expect(project).not_to be_repository_read_only
|
|
|
|
expect(project.repository_storage).to eq('test_second_storage')
|
|
|
|
expect(project.project_repository.shard_name).to eq('test_second_storage')
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the move of the #{repository_type} repository fails" do
|
|
|
|
it 'unmarks the repository as read-only without updating the repository storage' do
|
2020-04-22 19:07:51 +05:30
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('default').and_call_original
|
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('test_second_storage').and_return(SecureRandom.uuid)
|
2020-04-08 14:13:33 +05:30
|
|
|
allow(project_repository_double).to receive(:replicate)
|
|
|
|
.with(project.repository.raw)
|
|
|
|
allow(project_repository_double).to receive(:checksum)
|
|
|
|
.and_return(project_repository_checksum)
|
|
|
|
|
|
|
|
allow(repository_double).to receive(:replicate)
|
|
|
|
.with(repository.raw)
|
|
|
|
.and_raise(Gitlab::Git::CommandError)
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
result = subject.execute
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(result).to be_error
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(project).not_to be_repository_read_only
|
|
|
|
expect(project.repository_storage).to eq('default')
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(repository_storage_move).to be_failed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the cleanup of the #{repository_type} repository fails" do
|
|
|
|
it 'sets the correct state' do
|
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('default').and_call_original
|
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('test_second_storage').and_return(SecureRandom.uuid)
|
|
|
|
allow(project_repository_double).to receive(:replicate)
|
|
|
|
.with(project.repository.raw)
|
|
|
|
allow(project_repository_double).to receive(:checksum)
|
|
|
|
.and_return(project_repository_checksum)
|
|
|
|
allow(original_project_repository_double).to receive(:remove)
|
|
|
|
allow(repository_double).to receive(:replicate)
|
|
|
|
.with(repository.raw)
|
|
|
|
allow(repository_double).to receive(:checksum)
|
|
|
|
.and_return(repository_checksum)
|
|
|
|
|
|
|
|
expect(original_repository_double).to receive(:remove)
|
|
|
|
.and_raise(Gitlab::Git::CommandError)
|
|
|
|
|
|
|
|
result = subject.execute
|
|
|
|
|
|
|
|
expect(result).to be_error
|
|
|
|
expect(repository_storage_move).to be_cleanup_failed
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the checksum of the #{repository_type} repository does not match" do
|
|
|
|
it 'unmarks the repository as read-only without updating the repository storage' do
|
2020-04-22 19:07:51 +05:30
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('default').and_call_original
|
|
|
|
allow(Gitlab::GitalyClient).to receive(:filesystem_id).with('test_second_storage').and_return(SecureRandom.uuid)
|
2020-04-08 14:13:33 +05:30
|
|
|
allow(project_repository_double).to receive(:replicate)
|
|
|
|
.with(project.repository.raw)
|
|
|
|
allow(project_repository_double).to receive(:checksum)
|
|
|
|
.and_return(project_repository_checksum)
|
|
|
|
|
|
|
|
allow(repository_double).to receive(:replicate)
|
|
|
|
.with(repository.raw)
|
|
|
|
allow(repository_double).to receive(:checksum)
|
|
|
|
.and_return('not matching checksum')
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
result = subject.execute
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(result).to be_error
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(project).not_to be_repository_read_only
|
|
|
|
expect(project.repository_storage).to eq('default')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|