Commit 02423421 authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-e2e-group-wiki-storage-move' into 'master'

E2E to test Group Wiki repository storage move

See merge request gitlab-org/gitlab!56809
parents 726c581a 2ab3318d
......@@ -9,6 +9,7 @@ module QA
include QA::Page::Component::Wiki
include QA::Page::Component::WikiSidebar
include QA::Page::Component::LazyLoader
include QA::Page::Component::LegacyClonePanel
end
end
end
......
......@@ -89,6 +89,19 @@ module QA
raise ResourceUpdateFailedError, "Could not update require_two_factor_authentication to #{value}. Request returned (#{response.code}): `#{response}`."
end
end
def change_repository_storage(new_storage)
post_body = { destination_storage_name: new_storage }
response = post Runtime::API::Request.new(api_client, "/groups/#{id}/repository_storage_moves").url, post_body
unless response.code.between?(200, 300)
raise ResourceUpdateFailedError, "Could not change repository storage to #{new_storage}. Request returned (#{response.code}): `#{response}`."
end
wait_until(sleep_interval: 1) { Runtime::API::RepositoryStorageMoves.has_status?(self, 'finished', new_storage) }
rescue Support::Repeater::RepeaterConditionExceededError
raise Runtime::API::RepositoryStorageMoves::RepositoryStorageMovesError, 'Timed out while waiting for the group repository storage move to finish'
end
end
end
end
......@@ -16,6 +16,14 @@ module QA
end
end
attribute :repository_http_location do
EE::Page::Group::Wiki::Show.perform do |show|
show.click_clone_repository
show.choose_repository_clone_http
show.repository_location
end
end
def initialize
@title = 'Home'
@content = 'This wiki page is created via API'
......@@ -42,6 +50,20 @@ module QA
title: title
}
end
def api_list_wiki_pages_path
"/groups/#{group.id}/wikis"
end
def has_page_content?(page_title, page_content)
response = get Runtime::API::Request.new(api_client, "#{api_list_wiki_pages_path}?with_content=1").url
unless response.code == HTTP_STATUS_OK
raise ResourceQueryError, "Could not get a list of all wiki pages for a given group. Request returned (#{response.code}): `#{response}`."
end
parse_body(response).any? { |page| page[:title] == page_title && page[:content] == page_content }
end
end
end
end
......
......@@ -33,6 +33,8 @@ module QA
def resource_equals?(resource, move)
if resource.class.name.include?('Snippet')
move[:snippet][:id] == resource.id
elsif resource.class.name.include?('Group')
move[:group][:id] == resource.id
else
move[:project][:path_with_namespace] == resource.path_with_namespace
end
......
......@@ -180,10 +180,10 @@ module QA
wait_for_reliable_connection
end
def verify_storage_move(source_storage, destination_storage)
def verify_storage_move(source_storage, destination_storage, repo_type: :project)
return if QA::Runtime::Env.dot_com?
repo_path = verify_storage_move_from_gitaly(source_storage[:name])
repo_path = verify_storage_move_from_gitaly(source_storage[:name], repo_type: repo_type)
destination_storage[:type] == :praefect ? verify_storage_move_to_praefect(repo_path, destination_storage[:name]) : verify_storage_move_to_gitaly(repo_path, destination_storage[:name])
end
......@@ -404,13 +404,13 @@ module QA
Service::Shellout.sql_to_docker_exec_cmd(sql, 'postgres', 'SQL_PASSWORD', 'praefect_production', 'postgres.test', @postgres)
end
def verify_storage_move_from_gitaly(storage)
def verify_storage_move_from_gitaly(storage, repo_type: :project)
wait_until_shell_command("docker exec #{@gitlab} bash -c 'tail -n 50 /var/log/gitlab/gitaly/current'") do |line|
log = JSON.parse(line)
if (log['grpc.method'] == 'RenameRepository' || log['grpc.method'] == 'RemoveRepository') &&
log['grpc.request.repoStorage'] == storage &&
!log['grpc.request.repoPath'].include?('wiki')
repo_type(log['grpc.request.repoPath']) == repo_type
break log['grpc.request.repoPath']
end
rescue JSON::ParserError
......@@ -444,6 +444,17 @@ module QA
yield JSON.parse(line)
end
end
def repo_type(repo_path)
return :snippet if repo_path.start_with?('@snippets')
return :design if repo_path.end_with?('.design.git')
if repo_path.end_with?('.wiki.git')
return repo_path.start_with?('@groups') ? :group_wiki : :wiki
end
:project
end
end
end
end
......@@ -9,7 +9,7 @@ module QA
it 'confirms a `finished` status after moving project repository storage' do
expect(project).to have_file('README.md')
expect { project.change_repository_storage(destination_storage[:name]) }.not_to raise_error
expect { praefect_manager.verify_storage_move(source_storage, destination_storage) }.not_to raise_error
expect { praefect_manager.verify_storage_move(source_storage, destination_storage, repo_type: :project) }.not_to raise_error
Resource::Repository::ProjectPush.fabricate! do |push|
push.project = project
......
......@@ -24,7 +24,7 @@ module QA
it 'moves snippet repository from one Gitaly storage to another', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1700' do
expect(snippet).to have_file('original_file')
expect { snippet.change_repository_storage(destination_storage[:name]) }.not_to raise_error
expect { praefect_manager.verify_storage_move(source_storage, destination_storage) }.not_to raise_error
expect { praefect_manager.verify_storage_move(source_storage, destination_storage, repo_type: :snippet) }.not_to raise_error
# verifies you can push commits to the moved snippet
Resource::Repository::Push.fabricate! do |push|
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
describe 'Group Wiki repository storage', :requires_admin, :orchestrated, :repository_storage do
let(:source_storage) { { type: :gitaly, name: 'default' } }
let(:destination_storage) { { type: :gitaly, name: QA::Runtime::Env.additional_repository_storage } }
let(:original_page_title) { 'Wiki page to move storage of' }
let(:original_page_content) { 'Original wiki content' }
let(:group) do
Resource::Group.fabricate_via_api! do |group|
group.path = "group-to-move-storage-of-#{SecureRandom.hex(8)}"
group.api_client = Runtime::API::Client.as_admin
end
end
let(:wiki) do
Resource::Wiki::GroupPage.fabricate_via_api! do |wiki|
wiki.title = original_page_title
wiki.content = original_page_content
wiki.group = group
wiki.api_client = Runtime::API::Client.as_admin
end
end
praefect_manager = Service::PraefectManager.new
before do
praefect_manager.gitlab = 'gitlab'
end
it 'moves group Wiki repository from one Gitaly storage to another', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1733' do
expect(wiki).to have_page_content(original_page_title, original_page_content)
expect { group.change_repository_storage(destination_storage[:name]) }.not_to raise_error
expect { praefect_manager.verify_storage_move(source_storage, destination_storage, repo_type: :group_wiki) }.not_to raise_error
# verifies you can push commits to the moved Wiki
Resource::Repository::WikiPush.fabricate! do |push|
push.wiki = wiki
push.repository_http_uri = "#{wiki.group.web_url.sub('/groups/', '/')}.wiki.git"
push.file_name = 'new-page.md'
push.file_content = 'new page content'
push.commit_message = 'Adding a new Wiki page'
push.new_branch = false
end
aggregate_failures do
expect(wiki).to have_page_content(original_page_title, original_page_content)
expect(wiki).to have_page_content('new page', 'new page content')
end
end
end
end
end
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