Commit f544acf6 authored by Robert Speicher's avatar Robert Speicher

Merge branch...

Merge branch '36809-projects-update-repository-storage-service-should-handle-design-repositories' into 'master'

Resolve "Projects::UpdateRepositoryStorageService should handle design repositories"

Closes #36809

See merge request gitlab-org/gitlab!20509
parents 0a016946 d5492911
......@@ -23,6 +23,10 @@ module Projects
result &&= mirror_repository(new_repository_storage_key, type: Gitlab::GlRepository::WIKI)
end
if project.design_repository.exists?
result &&= mirror_repository(new_repository_storage_key, type: Gitlab::GlRepository::DESIGN)
end
if result
mark_old_paths_for_archive
......@@ -71,6 +75,13 @@ module Projects
wiki.disk_path,
"#{new_project_path}.wiki")
end
if design_repository.exists?
GitlabShellWorker.perform_async(:mv_repository,
old_repository_storage,
design_repository.disk_path,
"#{new_project_path}.design")
end
end
end
......
---
title: Handle design repositories when moving a project to a new storage
merge_request: 20509
author:
type: fixed
......@@ -14,7 +14,7 @@ describe Projects::UpdateRepositoryStorageService do
allow(Time).to receive(:now).and_return(time)
end
context 'without wiki' do
context 'without wiki and design repository' do
let(:project) { create(:project, :repository, repository_read_only: true, wiki_enabled: false) }
context 'when the move succeeds' do
......@@ -56,47 +56,43 @@ describe Projects::UpdateRepositoryStorageService do
end
end
context 'with wiki' do
let(:project) { create(:project, :repository, repository_read_only: true, wiki_enabled: true) }
shared_examples 'moves repository to another storage' do |repository_type|
let(:project_repository_double) { double(:repository) }
let(:repository_double) { double(:repository) }
let(:wiki_repository_double) { double(:repository) }
before do
project.create_wiki
# Default stub for non-specified params
allow(Gitlab::Git::Repository).to receive(:new).and_call_original
relative_path = project.repository.raw.relative_path
allow(Gitlab::Git::Repository).to receive(:new)
.with('test_second_storage', relative_path, "project-#{project.id}", project.full_path)
.and_return(repository_double)
.with('test_second_storage', project.repository.raw.relative_path, project.repository.gl_repository, project.repository.full_path)
.and_return(project_repository_double)
wiki_relative_path = project.wiki.repository.raw.relative_path
allow(Gitlab::Git::Repository).to receive(:new)
.with('test_second_storage', wiki_relative_path, "wiki-#{project.id}", project.wiki.full_path)
.and_return(wiki_repository_double)
.with('test_second_storage', repository.raw.relative_path, repository.gl_repository, repository.full_path)
.and_return(repository_double)
end
context 'when the move succeeds' do
it 'moves the repository and its wiki to the new storage and unmarks the repository as read only' do
old_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
it "moves the project and its #{repository_type} repository to the new storage and unmarks the repository as read only" do
old_project_repository_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
project.repository.path_to_repo
end
old_wiki_path = project.wiki.full_path
expect(repository_double).to receive(:fetch_repository_as_mirror)
old_repository_path = repository.full_path
allow(project_repository_double).to receive(:fetch_repository_as_mirror)
.with(project.repository.raw).and_return(true)
expect(wiki_repository_double).to receive(:fetch_repository_as_mirror)
.with(project.wiki.repository.raw).and_return(true)
allow(repository_double).to receive(:fetch_repository_as_mirror)
.with(repository.raw).and_return(true)
subject.execute('test_second_storage')
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('test_second_storage')
expect(gitlab_shell.repository_exists?('default', old_path)).to be(false)
expect(gitlab_shell.repository_exists?('default', old_wiki_path)).to be(false)
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
end
......@@ -108,12 +104,13 @@ describe Projects::UpdateRepositoryStorageService do
end
end
context 'when the move of the wiki fails' do
context "when the move of the #{repository_type} repository fails" do
it 'unmarks the repository as read-only without updating the repository storage' do
expect(repository_double).to receive(:fetch_repository_as_mirror)
allow(project_repository_double).to receive(:fetch_repository_as_mirror)
.with(project.repository.raw).and_return(true)
expect(wiki_repository_double).to receive(:fetch_repository_as_mirror)
.with(project.wiki.repository.raw).and_return(false)
allow(repository_double).to receive(:fetch_repository_as_mirror)
.with(repository.raw).and_return(false)
expect(GitlabShellWorker).not_to receive(:perform_async)
subject.execute('test_second_storage')
......@@ -124,6 +121,28 @@ describe Projects::UpdateRepositoryStorageService do
end
end
context 'with wiki repository' do
include_examples 'moves repository to another storage', 'wiki' do
let(:project) { create(:project, :repository, repository_read_only: true, wiki_enabled: true) }
let(:repository) { project.wiki.repository }
before do
project.create_wiki
end
end
end
context 'with design repository' do
include_examples 'moves repository to another storage', 'design' do
let(:project) { create(:project, :repository, repository_read_only: true) }
let(:repository) { project.design_repository }
before do
project.design_repository.create_if_not_exists
end
end
end
context 'when a object pool was joined' do
let(:project) { create(:project, :repository, wiki_enabled: false, repository_read_only: true) }
let(:pool) { create(:pool_repository, :ready, source_project: project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment