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