Commit ce90b934 authored by Stan Hu's avatar Stan Hu

Merge branch '356562-handle-native-imports' into 'master'

Properly handle native imports

See merge request gitlab-org/gitlab!83446
parents 4df7f344 9141a5e8
......@@ -21,7 +21,6 @@ class ContainerRepository < ApplicationRecord
MIGRATION_PHASE_1_STARTED_AT = Date.new(2021, 11, 4).freeze
TooManyImportsError = Class.new(StandardError)
NativeImportError = Class.new(StandardError)
belongs_to :project
......@@ -36,7 +35,7 @@ class ContainerRepository < ApplicationRecord
enum status: { delete_scheduled: 0, delete_failed: 1 }
enum expiration_policy_cleanup_status: { cleanup_unscheduled: 0, cleanup_scheduled: 1, cleanup_unfinished: 2, cleanup_ongoing: 3 }
enum migration_skipped_reason: { not_in_plan: 0, too_many_retries: 1, too_many_tags: 2, root_namespace_in_deny_list: 3, migration_canceled: 4, not_found: 5 }
enum migration_skipped_reason: { not_in_plan: 0, too_many_retries: 1, too_many_tags: 2, root_namespace_in_deny_list: 3, migration_canceled: 4, not_found: 5, native_import: 6 }
delegate :client, :gitlab_api_client, to: :registry
......@@ -295,7 +294,7 @@ class ContainerRepository < ApplicationRecord
def reconcile_import_status(status)
case status
when 'native'
raise NativeImportError
finish_import_as_native
when *IRRECONCILABLE_MIGRATIONS_STATUSES
nil
when 'import_complete'
......@@ -323,6 +322,8 @@ class ContainerRepository < ApplicationRecord
return true
when :not_found
skip_import(reason: :not_found)
when :already_imported
finish_import_as_native
else
abort_import
end
......@@ -509,6 +510,13 @@ class ContainerRepository < ApplicationRecord
self.find_by(project: path.repository_project,
name: path.repository_name)
end
private
def finish_import_as_native
self.migration_skipped_reason = :native_import
finish_import
end
end
ContainerRepository.prepend_mod_with('ContainerRepository')
......@@ -122,6 +122,16 @@ RSpec.describe ContainerRepository, :aggregate_failures do
expect(repository).to be_import_aborted
end
end
context 'already imported' do
it 'finishes the import' do
expect(repository).to receive(:migration_pre_import).and_return(:already_imported)
expect { subject }
.to change { repository.reload.migration_state }.to('import_done')
.and change { repository.reload.migration_skipped_reason }.to('native_import')
end
end
end
shared_examples 'transitioning to importing', skip_import_success: true do
......@@ -151,6 +161,16 @@ RSpec.describe ContainerRepository, :aggregate_failures do
expect(repository).to be_import_aborted
end
end
context 'already imported' do
it 'finishes the import' do
expect(repository).to receive(:migration_import).and_return(:already_imported)
expect { subject }
.to change { repository.reload.migration_state }.to('import_done')
.and change { repository.reload.migration_skipped_reason }.to('native_import')
end
end
end
shared_examples 'transitioning out of import_aborted' do
......
......@@ -145,8 +145,10 @@ RSpec.shared_examples 'reconciling migration_state' do
context 'native response' do
let(:status) { 'native' }
it 'raises an error' do
expect { subject }.to raise_error(described_class::NativeImportError)
it 'finishes the import' do
expect { subject }
.to change { repository.reload.migration_state }.to('import_done')
.and change { repository.reload.migration_skipped_reason }.to('native_import')
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