Skip to content
Snippets Groups Projects
Verified Commit d4a02848 authored by Jessie Young's avatar Jessie Young :palm_tree: Committed by GitLab
Browse files

Merge branch...

Merge branch '431944-geo-container-registry-sync-jobs-should-fail-on-failure-to-pull-from-the-primary-registry' into 'master' 

Geo: Container registry sync jobs should fail on failure to pull

See merge request !148105



Merged-by: Jessie Young's avatarJessie Young <jessieyoung@gitlab.com>
Approved-by: default avatarRyan Cobb <rcobb@gitlab.com>
Approved-by: Jessie Young's avatarJessie Young <jessieyoung@gitlab.com>
Co-authored-by: default avatarIan Baum <ibaum@gitlab.com>
parents 9a2f8068 756f9cdb
No related branches found
No related tags found
1 merge request!148105Geo: Container registry sync jobs should fail on failure to pull
Pipeline #1233616111 passed
......@@ -22,6 +22,8 @@ def initialize(container_repository)
end
def execute
raise "No valid connection to primary registry" unless client.connected?
tags_to_sync.each { |tag| sync_tag(tag) }
tags_to_remove.each { |tag| remove_tag(tag) }
......
......@@ -49,6 +49,7 @@
before do
stub_container_registry_config(enabled: true, api_url: secondary_api_url)
stub_registry_replication_config(enabled: true, primary_api_url: primary_api_url)
stub_connected(true)
end
def stub_repository_tags_requests(repository_url, tags)
......@@ -92,6 +93,12 @@ def stub_missing_blobs_requests(primary_repository_url, secondary_repository_url
end
end
def stub_connected(connected)
allow_next_instance_of(ContainerRegistry::Client) do |client|
allow(client).to receive(:connected?).and_return(connected)
end
end
describe '#execute' do
subject { described_class.new(container_repository) }
......@@ -314,6 +321,11 @@ def stub_missing_blobs_requests(primary_repository_url, secondary_repository_url
subject.execute
end
it 'raises an error with a bad connection' do
stub_connected(false)
expect { subject.execute }.to raise_error.with_message('No valid connection to primary registry')
end
end
describe '#client' do
......
......@@ -58,6 +58,10 @@ def registry_info
}
end
def connected?
!registry_info.empty?
end
def repository_tags(name, page_size: DEFAULT_TAGS_PAGE_SIZE)
response = faraday.get("/v2/#{name}/tags/list") do |req|
req.params['n'] = page_size
......
......@@ -468,6 +468,32 @@
it_behaves_like 'handling registry info'
end
describe '#connected?' do
subject { client.connected? }
context 'with a valid connection' do
before do
stub_container_registry_config(enabled: true, api_url: registry_api_url, key: 'spec/fixtures/x509_certificate_pk.key')
stub_registry_info
end
it 'returns true' do
expect(subject).to be true
end
end
context 'with an invalid connection' do
before do
stub_container_registry_config(enabled: true, api_url: registry_api_url, key: 'spec/fixtures/x509_certificate_pk.key')
stub_registry_info(status: 500)
end
it 'returns false' do
expect(subject).to be false
end
end
end
def stub_upload(path, content, digest, status = 200)
stub_request(:post, "#{registry_api_url}/v2/#{path}/blobs/uploads/")
.with(headers: headers_with_accept_types)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment