Commit c15fb16d authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'qa-e2e-snippet-repository-storage-move' into 'master'

Add E2E for snippet repository storage move

See merge request gitlab-org/gitlab!53813
parents 471ffe77 9a1884f2
......@@ -6,6 +6,7 @@ module QA
attr_accessor :title, :description, :file_content, :visibility, :file_name
attribute :id
attribute :http_url_to_repo
def initialize
@title = 'New snippet title'
......@@ -53,6 +54,10 @@ module QA
'/snippets'
end
def api_put_path
"/snippets/#{id}"
end
def api_post_body
{
title: title,
......@@ -72,6 +77,28 @@ module QA
file[:file_path] = file.delete(:name)
end
end
def has_file?(file_path)
response = get Runtime::API::Request.new(api_client, api_get_path).url
raise ResourceNotFoundError, "Request returned (#{response.code}): `#{response}`." if response.code == HTTP_STATUS_NOT_FOUND
file_output = parse_body(response)[:files]
file_output.any? { |file| file[:path] == file_path }
end
def change_repository_storage(new_storage)
post_body = { destination_storage_name: new_storage }
response = post Runtime::API::Request.new(api_client, "/snippets/#{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 snippet repository storage move to finish'
end
end
end
end
......@@ -9,9 +9,9 @@ module QA
RepositoryStorageMovesError = Class.new(RuntimeError)
def has_status?(project, status, destination_storage = Env.additional_repository_storage)
find_any do |move|
next unless move[:project][:path_with_namespace] == project.path_with_namespace
def has_status?(resource, status, destination_storage = Env.additional_repository_storage)
find_any(resource) do |move|
next unless resource_equals?(resource, move)
QA::Runtime::Logger.debug("Move data: #{move}")
......@@ -20,16 +20,28 @@ module QA
end
end
def find_any
def find_any(resource)
Logger.debug('Getting repository storage moves')
Support::Waiter.wait_until do
with_paginated_response_body(Request.new(api_client, '/project_repository_storage_moves', per_page: '100').url) do |page|
with_paginated_response_body(Request.new(api_client, "/#{resource_name(resource)}_repository_storage_moves", per_page: '100').url) do |page|
break true if page.any? { |item| yield item }
end
end
end
def resource_equals?(resource, move)
if resource.class.name.include?('Snippet')
move[:snippet][:id] == resource.id
else
move[:project][:path_with_namespace] == resource.path_with_namespace
end
end
def resource_name(resource)
resource.class.name.split('::').last.downcase
end
private
def api_client
......
# frozen_string_literal: true
module QA
RSpec.describe 'Create' do
describe 'Snippet 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(:snippet) do
Resource::Snippet.fabricate_via_api! do |snippet|
snippet.title = 'Snippet to move storage of'
snippet.file_name = 'original_file'
snippet.file_content = 'Original file content'
snippet.api_client = Runtime::API::Client.as_admin
end
end
praefect_manager = Service::PraefectManager.new
before do
praefect_manager.gitlab = 'gitlab'
end
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
# verifies you can push commits to the moved snippet
Resource::Repository::Push.fabricate! do |push|
push.repository_http_uri = snippet.http_url_to_repo
push.file_name = 'new_file'
push.file_content = 'new file content'
push.commit_message = 'Adding a new snippet file'
push.new_branch = false
end
aggregate_failures do
expect(snippet).to have_file('original_file')
expect(snippet).to have_file('new_file')
end
end
end
end
end
......@@ -9,6 +9,7 @@ module QA
HTTP_STATUS_CREATED = 201
HTTP_STATUS_NO_CONTENT = 204
HTTP_STATUS_ACCEPTED = 202
HTTP_STATUS_NOT_FOUND = 404
HTTP_STATUS_SERVER_ERROR = 500
def post(url, payload, args = {})
......
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