Commit 6527e913 authored by David Fernandez's avatar David Fernandez

Merge branch '356984-fix' into 'master'

Gracefully handle non-existing repos during registry phase 2 migration

See merge request gitlab-org/gitlab!83746
parents f080e57c 987f3ce0
......@@ -125,7 +125,7 @@ class ContainerRepository < ApplicationRecord
end
event :finish_import do
transition %i[pre_importing importing import_aborted] => :import_done
transition %i[default pre_importing importing import_aborted] => :import_done
end
event :already_migrated do
......@@ -294,7 +294,7 @@ class ContainerRepository < ApplicationRecord
def reconcile_import_status(status)
case status
when 'native'
finish_import_as_native
finish_import_as(:native_import)
when *IRRECONCILABLE_MIGRATIONS_STATUSES
nil
when 'import_complete'
......@@ -321,9 +321,9 @@ class ContainerRepository < ApplicationRecord
when :ok
return true
when :not_found
skip_import(reason: :not_found)
finish_import_as(:not_found)
when :already_imported
finish_import_as_native
finish_import_as(:native_import)
else
abort_import
end
......@@ -513,8 +513,8 @@ class ContainerRepository < ApplicationRecord
private
def finish_import_as_native
self.migration_skipped_reason = :native_import
def finish_import_as(reason)
self.migration_skipped_reason = reason
finish_import
end
end
......
......@@ -132,6 +132,16 @@ RSpec.describe ContainerRepository, :aggregate_failures do
.and change { repository.reload.migration_skipped_reason }.to('native_import')
end
end
context 'non-existing repository' do
it 'finishes the import' do
expect(repository).to receive(:migration_pre_import).and_return(:not_found)
expect { subject }
.to change { repository.reload.migration_state }.to('import_done')
.and change { repository.reload.migration_skipped_reason }.to('not_found')
end
end
end
shared_examples 'transitioning to importing', skip_import_success: true do
......@@ -283,7 +293,7 @@ RSpec.describe ContainerRepository, :aggregate_failures do
subject { repository.finish_import }
it_behaves_like 'transitioning from allowed states', %w[pre_importing importing import_aborted]
it_behaves_like 'transitioning from allowed states', %w[default pre_importing importing import_aborted]
it_behaves_like 'queueing the next import'
it 'sets migration_import_done_at and queues the next import' do
......@@ -1155,10 +1165,10 @@ RSpec.describe ContainerRepository, :aggregate_failures do
context 'not found response' do
let(:response) { :not_found }
it 'aborts the migration' do
it 'completes the migration' do
expect(subject).to eq(false)
expect(container_repository).to be_import_skipped
expect(container_repository).to be_import_done
expect(container_repository.reload.migration_skipped_reason).to eq('not_found')
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