Commit cbb541ad authored by Jaime Martinez's avatar Jaime Martinez Committed by David Fernandez

Handle 404 responses from the container registry import status API

parent 435ea6c8
...@@ -53,8 +53,14 @@ module ContainerRegistry ...@@ -53,8 +53,14 @@ module ContainerRegistry
# https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#get-repository-import-status # https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#get-repository-import-status
def import_status(path) def import_status(path)
with_import_token_faraday do |faraday_client| with_import_token_faraday do |faraday_client|
body_hash = response_body(faraday_client.get(import_url_for(path))) response = faraday_client.get(import_url_for(path))
body_hash['status'] || 'error'
# Temporary solution for https://gitlab.com/gitlab-org/gitlab/-/issues/356085#solutions
# this will trigger a `retry_pre_import`
break 'pre_import_failed' unless response.success?
body_hash = response_body(response)
body_hash&.fetch('status') || 'error'
end end
end end
......
...@@ -107,20 +107,30 @@ RSpec.describe ContainerRegistry::GitlabApiClient do ...@@ -107,20 +107,30 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
describe '#import_status' do describe '#import_status' do
subject { client.import_status(path) } subject { client.import_status(path) }
before do context 'with successful response' do
stub_import_status(path, status) before do
end stub_import_status(path, status)
end
context 'with a status' do
let(:status) { 'this_is_a_test' }
it { is_expected.to eq(status) }
end
context 'with a status' do context 'with no status' do
let(:status) { 'this_is_a_test' } let(:status) { nil }
it { is_expected.to eq(status) } it { is_expected.to eq('error') }
end
end end
context 'with no status' do context 'with non successful response' do
let(:status) { nil } before do
stub_import_status(path, nil, status_code: 404)
end
it { is_expected.to eq('error') } it { is_expected.to eq('pre_import_failed') }
end end
end end
...@@ -230,11 +240,11 @@ RSpec.describe ContainerRegistry::GitlabApiClient do ...@@ -230,11 +240,11 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
.to_return(status: status_code, body: '') .to_return(status: status_code, body: '')
end end
def stub_import_status(path, status) def stub_import_status(path, status, status_code: 200)
stub_request(:get, "#{registry_api_url}/gitlab/v1/import/#{path}/") stub_request(:get, "#{registry_api_url}/gitlab/v1/import/#{path}/")
.with(headers: { 'Accept' => described_class::JSON_TYPE, 'Authorization' => "bearer #{import_token}" }) .with(headers: { 'Accept' => described_class::JSON_TYPE, 'Authorization' => "bearer #{import_token}" })
.to_return( .to_return(
status: 200, status: status_code,
body: { status: status }.to_json, body: { status: status }.to_json,
headers: { content_type: 'application/json' } headers: { content_type: 'application/json' }
) )
......
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