Improve logging when username update fails due to registry tags

When a user cannot be renamed due to existing container registry tags, log the
namespace and an example project that has tags.
This commit is contained in:
Stan Hu 2018-10-01 23:13:40 -04:00
parent 2bb8c1caa5
commit bba99da98c
4 changed files with 36 additions and 3 deletions

View file

@ -5,8 +5,10 @@ module Storage
extend ActiveSupport::Concern
def move_dir
if any_project_has_container_registry_tags?
raise Gitlab::UpdatePathError.new('Namespace cannot be moved, because at least one project has tags in container registry')
proj_with_tags = first_project_with_container_registry_tags
if proj_with_tags
raise Gitlab::UpdatePathError.new("Namespace #{name} (#{id}) cannot be moved because at least one project (e.g. #{proj_with_tags.name} (#{proj_with_tags.id})) has tags in container registry")
end
parent_was = if parent_changed? && parent_id_was.present?

View file

@ -135,6 +135,10 @@ class Namespace < ActiveRecord::Base
all_projects.any?(&:has_container_registry_tags?)
end
def first_project_with_container_registry_tags
all_projects.find(&:has_container_registry_tags?)
end
def send_update_instructions
projects.each do |project|
project.send_move_instructions("#{full_path_was}/#{project.path}")

View file

@ -0,0 +1,5 @@
---
title: Improve logging when username update fails due to registry tags
merge_request: 22038
author:
type: other

View file

@ -82,6 +82,27 @@ describe Namespace do
it { expect(namespace.human_name).to eq(namespace.owner_name) }
end
describe '#first_project_with_container_registry_tags' do
let(:container_repository) { create(:container_repository) }
let!(:project) { create(:project, namespace: namespace, container_repositories: [container_repository]) }
before do
stub_container_registry_config(enabled: true)
end
it 'returns the project' do
stub_container_registry_tags(repository: :any, tags: ['tag'])
expect(namespace.first_project_with_container_registry_tags).to eq(project)
end
it 'returns no project' do
stub_container_registry_tags(repository: :any, tags: nil)
expect(namespace.first_project_with_container_registry_tags).to be_nil
end
end
describe '.search' do
let(:namespace) { create(:namespace) }
@ -184,7 +205,8 @@ describe Namespace do
end
it 'raises an error about not movable project' do
expect { namespace.move_dir }.to raise_error(/Namespace cannot be moved/)
expect { namespace.move_dir }.to raise_error(Gitlab::UpdatePathError,
/Namespace .* cannot be moved/)
end
end
end