Commit 373d8e02 authored by George Koltsov's avatar George Koltsov

Capture subgroup creation failure during Group Import

- Capture subgroup creation failure during Group Import
  in order to prevent unexpected behaviour from happening,
  since currently Import tries to create group relations
  in a non persistent group which causes more errors in return
- This change makes sure error is captured and no further
  processing is made on that group
parent 189e569d
---
title: Capture subgroup creation failure during Group Import via archive file
merge_request: 49484
author:
type: fixed
......@@ -74,6 +74,12 @@ module Gitlab
group = create_group(group_attributes)
restore_group(group, group_attributes)
rescue => e
import_failure_service.log_import_failure(
source: 'process_child',
relation_key: 'group',
exception: e
)
end
def create_group(group_attributes)
......@@ -83,13 +89,17 @@ module Gitlab
parent_group = @groups_mapping.fetch(parent_id) { raise(ArgumentError, 'Parent group not found') }
::Groups::CreateService.new(
group = ::Groups::CreateService.new(
user,
name: name,
path: path,
parent_id: parent_group.id,
visibility_level: sub_group_visibility_level(group_attributes.attributes, parent_group)
).execute
group.validate!
group
end
def restore_group(group, group_attributes)
......@@ -134,6 +144,10 @@ module Gitlab
)
end
end
def import_failure_service
Gitlab::ImportExport::ImportFailureService.new(@top_level_group)
end
end
end
end
......
{"name":"ymg09t5704clnxnqfgaj2h098gz4r7gyx4wc3fzmlqj1en24zf","path":"ymg09t5704clnxnqfgaj2h098gz4r7gyx4wc3fzmlqj1en24zf","owner_id":123,"created_at":"2019-11-20 17:01:53 UTC","updated_at":"2019-11-20 17:05:44 UTC","description":"Group Description","avatar":{"url":null},"membership_lock":false,"share_with_group_lock":false,"visibility_level":0,"request_access_enabled":true,"ldap_sync_status":"ready","ldap_sync_error":null,"ldap_sync_last_update_at":null,"ldap_sync_last_successful_update_at":null,"ldap_sync_last_sync_at":null,"lfs_enabled":null,"parent_id":null,"shared_runners_minutes_limit":null,"repository_size_limit":null,"require_two_factor_authentication":false,"two_factor_grace_period":48,"plan_id":null,"project_creation_level":2,"trial_ends_on":null,"file_template_project_id":null,"saml_discovery_token":"rBKx3ioz","custom_project_templates_group_id":null,"auto_devops_enabled":null,"extra_shared_runners_minutes_limit":null,"last_ci_minutes_notification_at":null,"last_ci_minutes_usage_notification_level":null,"runners_token":"token","runners_token_encrypted":"encrypted","subgroup_creation_level":1,"emails_disabled":null,"max_pages_size":null,"max_artifacts_size":null,"id":4351}
\ No newline at end of file
{"name":"a","path":"a","owner_id":null,"created_at":"2019-11-20 17:01:53 UTC","updated_at":"2019-11-20 17:05:44 UTC","description":"","avatar":{"url":null},"membership_lock":false,"share_with_group_lock":false,"visibility_level":0,"request_access_enabled":true,"ldap_sync_status":"ready","ldap_sync_error":null,"ldap_sync_last_update_at":null,"ldap_sync_last_successful_update_at":null,"ldap_sync_last_sync_at":null,"lfs_enabled":null,"parent_id":4351,"shared_runners_minutes_limit":null,"repository_size_limit":null,"require_two_factor_authentication":false,"two_factor_grace_period":48,"plan_id":null,"project_creation_level":2,"trial_ends_on":null,"file_template_project_id":null,"saml_discovery_token":"ki3Xnjw3","custom_project_templates_group_id":null,"auto_devops_enabled":null,"extra_shared_runners_minutes_limit":null,"last_ci_minutes_notification_at":null,"last_ci_minutes_usage_notification_level":null,"subgroup_creation_level":1,"emails_disabled":null,"max_pages_size":null,"max_artifacts_size":null,"id":4352}
......@@ -75,12 +75,31 @@ RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do
before do
setup_import_export_config('group_exports/child_with_no_parent')
end
it 'captures import failures when a child group does not have a valid parent_id' do
group_tree_restorer.restore
expect(group_tree_restorer.restore).to be_falsey
expect(group.import_failures.first.exception_message).to eq('Parent group not found')
end
end
context 'when child group creation fails' do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:shared) { Gitlab::ImportExport::Shared.new(group) }
let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) }
before do
setup_import_export_config('group_exports/child_short_name')
end
it 'captures import failure' do
exception_message = 'Validation failed: Group URL is too short (minimum is 2 characters)'
group_tree_restorer.restore
it 'fails when a child group does not have a valid parent_id' do
expect(shared.errors).to include('Parent group not found')
expect(group.import_failures.first.exception_message).to eq(exception_message)
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