Commit 53b14341 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ashmckenzie/7516-add-qa-tests-for-geo-push-to-primary-proxy-with-ssh' into 'master'

Geo: SSH push to secondary specs

See merge request gitlab-org/gitlab-ee!7791
parents f99e2977 4e77ebf1
......@@ -43,6 +43,10 @@ module QA
end
end
module Profile
autoload :Menu, 'qa/ee/page/profile/menu'
end
module Project
autoload :Show, 'qa/ee/page/project/show'
......
# frozen_string_literal: true
module QA
module EE
module Page
module Profile
module Menu
def wait_for_key_to_replicate(text, max_wait: Runtime::Geo.max_file_replication_time)
wait(max: max_wait) { page.has_text?(text) }
end
end
end
end
end
end
......@@ -61,8 +61,6 @@ module QA
def configure_identity(name, email)
run(%Q{git config user.name #{name}})
run(%Q{git config user.email #{email}})
add_credentials_to_netrc
end
def commit_file(name, contents, message)
......@@ -113,21 +111,17 @@ module QA
attr_reader :uri, :username, :password, :known_hosts_file, :private_key_file
def debug?
Runtime::Env.respond_to?(:verbose?) && Runtime::Env.verbose?
end
def ssh_key_set?
!private_key_file.nil?
end
def run(command_str)
command = [env_vars, command_str, '2>&1'].compact.join(' ')
warn "DEBUG: command=[#{command}]" if debug?
warn "DEBUG: command=[#{command}]" if Runtime::Env.verbose?
output, _ = Open3.capture2(command)
output = output.chomp.gsub(/\s+$/, '')
warn "DEBUG: output=[#{output}]" if debug?
warn "DEBUG: output=[#{output}]" if Runtime::Env.verbose?
output
end
......
......@@ -4,6 +4,8 @@ module QA
module Page
module Profile
class Menu < Page::Base
prepend QA::EE::Page::Profile::Menu
view 'app/views/layouts/nav/sidebar/_profile.html.haml' do
element :access_token_link, 'link_to profile_personal_access_tokens_path' # rubocop:disable QA/ElementWithPattern
element :access_token_title, 'Access Tokens' # rubocop:disable QA/ElementWithPattern
......
......@@ -9,11 +9,12 @@ module QA
end
def gitlab_ctl(command, input: nil)
if input.nil?
shell "docker exec #{@name} gitlab-ctl #{command}"
else
shell "docker exec #{@name} bash -c '#{input} | gitlab-ctl #{command}'"
end
docker_exec("gitlab-ctl #{command}", input: input)
end
def docker_exec(command, input: nil)
command = "#{input} | #{command}" if input
shell "docker exec #{@name} bash -c '#{command}'"
end
end
end
......
......@@ -2,47 +2,59 @@
module QA
context :geo, :orchestrated, :geo do
describe 'GitLab Geo repository replication' do
it 'users pushes code to the primary node' do
describe 'GitLab HTTP push' do
it 'is replicated to the secondary' do
file_name = 'README.md'
file_content = 'This is a Geo project! Commit from primary.'
Runtime::Browser.visit(:geo_primary, QA::Page::Main::Login) do
# Visit the primary node and login
Page::Main::Login.act { sign_in_using_credentials }
# Create a new Project
project = Factory::Resource::Project.fabricate! do |project|
project.name = 'geo-project'
project.description = 'Geo test project'
end
# Perform a git push over HTTP directly to the primary
Factory::Repository::ProjectPush.fabricate! do |push|
push.project = project
push.file_name = 'README.md'
push.file_content = '# This is Geo project!'
push.file_name = file_name
push.file_content = "# #{file_content}"
push.commit_message = 'Add README.md'
end
project.visit!
# Validate git push worked and file exists with content
Page::Project::Show.perform do |show|
show.wait_for_repository_replication
expect(page).to have_content(file_name)
expect(page).to have_content(file_content)
end
Runtime::Browser.visit(:geo_secondary, QA::Page::Main::Login) do
Page::Main::OAuth.act do
authorize! if needs_authorization?
end
# Visit the secondary node and login
Page::Main::OAuth.act { authorize! if needs_authorization? }
EE::Page::Main::Banner.perform do |banner|
expect(banner).to have_secondary_read_only_banner
end
Page::Main::Menu.perform do |menu|
menu.go_to_projects
end
Page::Main::Menu.perform { |menu| menu.go_to_projects }
Page::Dashboard::Projects.perform do |dashboard|
dashboard.wait_for_project_replication(project.name)
dashboard.go_to_project(project.name)
end
# Validate the content has been sync'd from the primary
Page::Project::Show.perform do |show|
show.wait_for_repository_replication
show.wait_for_repository_replication_with(file_name)
expect(page).to have_content 'README.md'
expect(page).to have_content 'This is Geo project!'
expect(page).to have_content(file_name)
expect(page).to have_content(file_content)
end
end
end
......
......@@ -2,12 +2,12 @@
module QA
context :geo, :orchestrated, :geo do
describe 'GitLab Geo HTTP push secondary' do
let(:file_name) { 'README.md' }
let(:file_content_primary) { 'This is a Geo project! Commit from primary.' }
let(:file_content_secondary) { 'This is a Geo project! Commit from secondary.' }
describe 'GitLab HTTP push to secondary' do
it 'is redirected to the primary and ultimately replicated to the secondary' do
file_name = 'README.md'
file_content_primary = 'This is a Geo project! Commit from primary.'
file_content_secondary = 'This is a Geo project! Commit from secondary.'
Runtime::Browser.visit(:geo_primary, QA::Page::Main::Login) do
# Visit the primary node and login
Page::Main::Login.act { sign_in_using_credentials }
......@@ -19,22 +19,17 @@ module QA
end
# Perform a git push over HTTP directly to the primary
#
# This push is required to ensure we have the primary credentials
# written out to the .netrc
Factory::Repository::ProjectPush.fabricate! do |push|
push.project = project
push.file_name = file_name
push.file_content = "# #{file_content_primary}"
push.commit_message = 'Add README.md'
push.commit_message = "Add #{file_name}"
end
project.visit!
# Validate git push worked and file exists with content
Page::Project::Show.perform do |show|
show.wait_for_repository_replication
expect(page).to have_content file_name
expect(page).to have_content file_content_primary
end
Runtime::Browser.visit(:geo_secondary, QA::Page::Main::Login) do
# Visit the secondary node and login
Page::Main::OAuth.act { authorize! if needs_authorization? }
......@@ -50,14 +45,6 @@ module QA
dashboard.go_to_project(project.name)
end
# Validate the content has been sync'd from the primary
Page::Project::Show.perform do |show|
show.wait_for_repository_replication_with(file_content_primary)
expect(page).to have_content file_name
expect(page).to have_content file_content_primary
end
# Grab the HTTP URI for the secondary and store as 'location'
location = Page::Project::Show.act do
choose_repository_clone_http
......@@ -70,7 +57,7 @@ module QA
push.repository_http_uri = location.uri
push.file_name = file_name
push.file_content = "# #{file_content_secondary}"
push.commit_message = 'Update README.md'
push.commit_message = "Update #{file_name}"
end
# Validate git push worked and new content is visible
......@@ -78,8 +65,8 @@ module QA
show.wait_for_repository_replication_with(file_content_secondary)
show.refresh
expect(page).to have_content file_name
expect(page).to have_content file_content_secondary
expect(page).to have_content(file_name)
expect(page).to have_content(file_content_secondary)
end
end
end
......
# frozen_string_literal: true
module QA
context :geo, :orchestrated, :geo do
describe 'GitLab SSH push' do
it "is replicated to the secondary" do
file_name = 'README.md'
key_title = "key for ssh tests #{Time.now.to_f}"
file_content = 'This is a Geo project! Commit from primary.'
Runtime::Browser.visit(:geo_primary, QA::Page::Main::Login) do
# Visit the primary node and login
Page::Main::Login.act { sign_in_using_credentials }
# Create a new SSH key for the user
key = Factory::Resource::SSHKey.fabricate! do |resource|
resource.title = key_title
end
# Create a new Project
project = Factory::Resource::Project.fabricate! do |project|
project.name = 'geo-project'
project.description = 'Geo test project'
end
# Perform a git push over SSH directly to the primary
Factory::Repository::ProjectPush.fabricate! do |push|
push.ssh_key = key
push.project = project
push.file_name = file_name
push.file_content = "# #{file_content}"
push.commit_message = 'Add README.md'
end
project.visit!
# Validate git push worked and file exists with content
Page::Project::Show.perform do |show|
show.wait_for_repository_replication
expect(page).to have_content(file_name)
expect(page).to have_content(file_content)
end
Runtime::Browser.visit(:geo_secondary, QA::Page::Main::Login) do
# Visit the secondary node and login
Page::Main::OAuth.act { authorize! if needs_authorization? }
EE::Page::Main::Banner.perform do |banner|
expect(banner).to have_secondary_read_only_banner
end
# Ensure the SSH key has replicated
Page::Main::Menu.act { go_to_profile_settings }
Page::Profile::Menu.act { click_ssh_keys }
expect(page).to have_content(key_title)
expect(page).to have_content(key.fingerprint)
# Ensure project has replicated
Page::Main::Menu.perform { |menu| menu.go_to_projects }
Page::Dashboard::Projects.perform do |dashboard|
dashboard.wait_for_project_replication(project.name)
dashboard.go_to_project(project.name)
end
# Validate the content has been sync'd from the primary
Page::Project::Show.perform do |show|
show.wait_for_repository_replication_with(file_content)
expect(page).to have_content(file_name)
expect(page).to have_content(file_content)
end
end
end
end
end
end
end
# frozen_string_literal: true
module QA
context :geo, :orchestrated, :geo do
describe 'GitLab SSH push to secondary' do
it "is proxy'd to the primary and ultimately replicated to the secondary" do
file_name = 'README.md'
key_title = "key for ssh tests #{Time.now.to_f}"
file_content_primary = 'This is a Geo project! Commit from primary.'
file_content_secondary = 'This is a Geo project! Commit from secondary.'
Runtime::Browser.visit(:geo_primary, QA::Page::Main::Login) do
# Visit the primary node and login
Page::Main::Login.act { sign_in_using_credentials }
# Create a new SSH key for the user
key = Factory::Resource::SSHKey.fabricate! do |resource|
resource.title = key_title
end
# Create a new Project
project = Factory::Resource::Project.fabricate! do |project|
project.name = 'geo-project'
project.description = 'Geo test project'
end
# Perform a git push over SSH directly to the primary
#
# This push is required to ensure we have the primary credentials
# written out to the .netrc
Factory::Repository::ProjectPush.fabricate! do |push|
push.ssh_key = key
push.project = project
push.file_name = file_name
push.file_content = "# #{file_content_primary}"
push.commit_message = "Add #{file_name}"
end
project.visit!
Runtime::Browser.visit(:geo_secondary, QA::Page::Main::Login) do
# Visit the secondary node and login
Page::Main::OAuth.act { authorize! if needs_authorization? }
EE::Page::Main::Banner.perform do |banner|
expect(banner).to have_secondary_read_only_banner
end
# Ensure the SSH key has replicated
Page::Main::Menu.act { go_to_profile_settings }
Page::Profile::Menu.perform do |menu|
menu.click_ssh_keys
menu.wait_for_key_to_replicate(key_title)
end
expect(page).to have_content(key_title)
expect(page).to have_content(key.fingerprint)
# Ensure project has replicated
Page::Main::Menu.perform { |menu| menu.go_to_projects }
Page::Dashboard::Projects.perform do |dashboard|
dashboard.wait_for_project_replication(project.name)
dashboard.go_to_project(project.name)
end
# Grab the SSH URI for the secondary and store as 'location'
location = Page::Project::Show.act do
choose_repository_clone_ssh
repository_location
end
# Perform a git push over SSH at the secondary
Factory::Repository::Push.fabricate! do |push|
push.new_branch = false
push.ssh_key = key
push.repository_ssh_uri = location.uri
push.file_name = file_name
push.file_content = "# #{file_content_secondary}"
push.commit_message = "Update #{file_name}"
end
# Validate git push worked and new content is visible
Page::Project::Show.perform do |show|
show.wait_for_repository_replication_with(file_content_secondary)
expect(page).to have_content(file_content_secondary)
end
end
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