Commit 9141a5e8 authored by David Fernandez's avatar David Fernandez

Properly handle native imports

in the ContainerRepository migration logic
parent aef3a688
...@@ -21,7 +21,6 @@ class ContainerRepository < ApplicationRecord ...@@ -21,7 +21,6 @@ class ContainerRepository < ApplicationRecord
MIGRATION_PHASE_1_STARTED_AT = Date.new(2021, 11, 4).freeze MIGRATION_PHASE_1_STARTED_AT = Date.new(2021, 11, 4).freeze
TooManyImportsError = Class.new(StandardError) TooManyImportsError = Class.new(StandardError)
NativeImportError = Class.new(StandardError)
belongs_to :project belongs_to :project
...@@ -36,7 +35,7 @@ class ContainerRepository < ApplicationRecord ...@@ -36,7 +35,7 @@ class ContainerRepository < ApplicationRecord
enum status: { delete_scheduled: 0, delete_failed: 1 } 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 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 delegate :client, :gitlab_api_client, to: :registry
...@@ -295,7 +294,7 @@ class ContainerRepository < ApplicationRecord ...@@ -295,7 +294,7 @@ class ContainerRepository < ApplicationRecord
def reconcile_import_status(status) def reconcile_import_status(status)
case status case status
when 'native' when 'native'
raise NativeImportError finish_import_as_native
when *IRRECONCILABLE_MIGRATIONS_STATUSES when *IRRECONCILABLE_MIGRATIONS_STATUSES
nil nil
when 'import_complete' when 'import_complete'
...@@ -323,6 +322,8 @@ class ContainerRepository < ApplicationRecord ...@@ -323,6 +322,8 @@ class ContainerRepository < ApplicationRecord
return true return true
when :not_found when :not_found
skip_import(reason: :not_found) skip_import(reason: :not_found)
when :already_imported
finish_import_as_native
else else
abort_import abort_import
end end
...@@ -509,6 +510,13 @@ class ContainerRepository < ApplicationRecord ...@@ -509,6 +510,13 @@ class ContainerRepository < ApplicationRecord
self.find_by(project: path.repository_project, self.find_by(project: path.repository_project,
name: path.repository_name) name: path.repository_name)
end end
private
def finish_import_as_native
self.migration_skipped_reason = :native_import
finish_import
end
end end
ContainerRepository.prepend_mod_with('ContainerRepository') ContainerRepository.prepend_mod_with('ContainerRepository')
...@@ -122,6 +122,16 @@ RSpec.describe ContainerRepository, :aggregate_failures do ...@@ -122,6 +122,16 @@ RSpec.describe ContainerRepository, :aggregate_failures do
expect(repository).to be_import_aborted expect(repository).to be_import_aborted
end end
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 end
shared_examples 'transitioning to importing', skip_import_success: true do shared_examples 'transitioning to importing', skip_import_success: true do
...@@ -151,6 +161,16 @@ RSpec.describe ContainerRepository, :aggregate_failures do ...@@ -151,6 +161,16 @@ RSpec.describe ContainerRepository, :aggregate_failures do
expect(repository).to be_import_aborted expect(repository).to be_import_aborted
end end
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 end
shared_examples 'transitioning out of import_aborted' do shared_examples 'transitioning out of import_aborted' do
......
...@@ -145,8 +145,10 @@ RSpec.shared_examples 'reconciling migration_state' do ...@@ -145,8 +145,10 @@ RSpec.shared_examples 'reconciling migration_state' do
context 'native response' do context 'native response' do
let(:status) { 'native' } let(:status) { 'native' }
it 'raises an error' do it 'finishes the import' do
expect { subject }.to raise_error(described_class::NativeImportError) expect { subject }
.to change { repository.reload.migration_state }.to('import_done')
.and change { repository.reload.migration_skipped_reason }.to('native_import')
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