Commit bb9d360c authored by Sean McGivern's avatar Sean McGivern

Merge branch 'mark-legacy-git-access' into 'master'

Route path lookups through legacy_disk_path

See merge request gitlab-org/gitlab-ce!17743
parents 963e445f 008a6a6c
...@@ -96,7 +96,7 @@ module ApplicationSettingsHelper ...@@ -96,7 +96,7 @@ module ApplicationSettingsHelper
def repository_storages_options_for_select(selected) def repository_storages_options_for_select(selected)
options = Gitlab.config.repositories.storages.map do |name, storage| options = Gitlab.config.repositories.storages.map do |name, storage|
["#{name} - #{storage['path']}", name] ["#{name} - #{storage.legacy_disk_path}", name]
end end
options_for_select(options, selected) options_for_select(options, selected)
......
...@@ -503,7 +503,7 @@ class Project < ActiveRecord::Base ...@@ -503,7 +503,7 @@ class Project < ActiveRecord::Base
end end
def repository_storage_path def repository_storage_path
Gitlab.config.repositories.storages[repository_storage].try(:[], 'path') Gitlab.config.repositories.storages[repository_storage]&.legacy_disk_path
end end
def team def team
......
...@@ -467,12 +467,7 @@ unless Settings.repositories.storages['default'] ...@@ -467,12 +467,7 @@ unless Settings.repositories.storages['default']
end end
Settings.repositories.storages.each do |key, storage| Settings.repositories.storages.each do |key, storage|
storage = Settingslogic.new(storage) Settings.repositories.storages[key] = Gitlab::GitalyClient::StorageSettings.new(storage)
# Expand relative paths
storage['path'] = Settings.absolute(storage['path'])
Settings.repositories.storages[key] = storage
end end
# #
...@@ -486,7 +481,7 @@ repositories_storages = Settings.repositories.storages.values ...@@ -486,7 +481,7 @@ repositories_storages = Settings.repositories.storages.values
repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(%r{/$}, '') repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(%r{/$}, '')
repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home']) repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home'])
if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs['path'].gsub(%r{/$}, '')) } if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs.legacy_disk_path.gsub(%r{/$}, '')) }
Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive') Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive')
end end
......
...@@ -5,7 +5,7 @@ end ...@@ -5,7 +5,7 @@ end
def find_parent_path(name, path) def find_parent_path(name, path)
parent = Pathname.new(path).realpath.parent parent = Pathname.new(path).realpath.parent
Gitlab.config.repositories.storages.detect do |n, rs| Gitlab.config.repositories.storages.detect do |n, rs|
name != n && Pathname.new(rs['path']).realpath == parent name != n && Pathname.new(rs.legacy_disk_path).realpath == parent
end end
rescue Errno::EIO, Errno::ENOENT => e rescue Errno::EIO, Errno::ENOENT => e
warning = "WARNING: couldn't verify #{path} (#{name}). "\ warning = "WARNING: couldn't verify #{path} (#{name}). "\
...@@ -33,7 +33,7 @@ def validate_storages_config ...@@ -33,7 +33,7 @@ def validate_storages_config
"If you're using the Gitlab Development Kit, you can update your configuration running `gdk reconfigure`.\n" "If you're using the Gitlab Development Kit, you can update your configuration running `gdk reconfigure`.\n"
end end
if !repository_storage.is_a?(Hash) || repository_storage['path'].nil? if !repository_storage.is_a?(Gitlab::GitalyClient::StorageSettings) || repository_storage.legacy_disk_path.nil?
storage_validation_error("#{name} is not a valid storage, because it has no `path` key. Refer to gitlab.yml.example for an updated example") storage_validation_error("#{name} is not a valid storage, because it has no `path` key. Refer to gitlab.yml.example for an updated example")
end end
...@@ -50,7 +50,7 @@ end ...@@ -50,7 +50,7 @@ end
def validate_storages_paths def validate_storages_paths
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
parent_name, _parent_path = find_parent_path(name, repository_storage['path']) parent_name, _parent_path = find_parent_path(name, repository_storage.legacy_disk_path)
if parent_name if parent_name
storage_validation_error("#{name} is a nested path of #{parent_name}. Nested paths are not supported for repository storages") storage_validation_error("#{name} is a nested path of #{parent_name}. Nested paths are not supported for repository storages")
end end
......
...@@ -12,7 +12,7 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration ...@@ -12,7 +12,7 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration
end end
def repository_storage_path def repository_storage_path
Gitlab.config.repositories.storages[repository_storage]['path'] Gitlab.config.repositories.storages[repository_storage].legacy_disk_path
end end
def repository_path def repository_path
......
...@@ -60,7 +60,7 @@ class RemoveDotGitFromGroupNames < ActiveRecord::Migration ...@@ -60,7 +60,7 @@ class RemoveDotGitFromGroupNames < ActiveRecord::Migration
def move_namespace(group_id, path_was, path) def move_namespace(group_id, path_was, path)
repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{group_id}").map do |row| repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{group_id}").map do |row|
Gitlab.config.repositories.storages[row['repository_storage']]['path'] Gitlab.config.repositories.storages[row['repository_storage']].legacy_disk_path
end.compact end.compact
# Move the namespace directory in all storages paths used by member projects # Move the namespace directory in all storages paths used by member projects
......
...@@ -71,7 +71,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration ...@@ -71,7 +71,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
route_exists = route_exists?(path) route_exists = route_exists?(path)
Gitlab.config.repositories.storages.each_value do |storage| Gitlab.config.repositories.storages.each_value do |storage|
if route_exists || path_exists?(path, storage['path']) if route_exists || path_exists?(path, storage.legacy_disk_path)
counter += 1 counter += 1
path = "#{base}#{counter}" path = "#{base}#{counter}"
...@@ -84,7 +84,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration ...@@ -84,7 +84,7 @@ class RemoveDotGitFromUsernames < ActiveRecord::Migration
def move_namespace(namespace_id, path_was, path) def move_namespace(namespace_id, path_was, path)
repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{namespace_id}").map do |row| repository_storage_paths = select_all("SELECT distinct(repository_storage) FROM projects WHERE namespace_id = #{namespace_id}").map do |row|
Gitlab.config.repositories.storages[row['repository_storage']]['path'] Gitlab.config.repositories.storages[row['repository_storage']].legacy_disk_path
end.compact end.compact
# Move the namespace directory in all storages paths used by member projects # Move the namespace directory in all storages paths used by member projects
......
...@@ -65,7 +65,7 @@ module Backup ...@@ -65,7 +65,7 @@ module Backup
def restore def restore
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
path = repository_storage['path'] path = repository_storage.legacy_disk_path
next unless File.exist?(path) next unless File.exist?(path)
# Move repos dir to 'repositories.old' dir # Move repos dir to 'repositories.old' dir
...@@ -200,7 +200,7 @@ module Backup ...@@ -200,7 +200,7 @@ module Backup
end end
def repository_storage_paths_args def repository_storage_paths_args
Gitlab.config.repositories.storages.values.map { |rs| rs['path'] } Gitlab.config.repositories.storages.values.map { |rs| rs.legacy_disk_path }
end end
def progress def progress
......
...@@ -74,7 +74,7 @@ module Gitlab ...@@ -74,7 +74,7 @@ module Gitlab
}.freeze }.freeze
def repository_storage_path def repository_storage_path
Gitlab.config.repositories.storages[repository_storage]['path'] Gitlab.config.repositories.storages[repository_storage].legacy_disk_path
end end
# Overridden to have the correct `source_type` for the `route` relation # Overridden to have the correct `source_type` for the `route` relation
......
...@@ -212,7 +212,7 @@ module Gitlab ...@@ -212,7 +212,7 @@ module Gitlab
end end
def shard_name_from_shard_path(shard_path) def shard_name_from_shard_path(shard_path)
Gitlab.config.repositories.storages.find { |_, info| info['path'] == shard_path }&.first || Gitlab.config.repositories.storages.find { |_, info| info.legacy_disk_path == shard_path }&.first ||
raise(ShardNameNotFoundError, "no shard found for path '#{shard_path}'") raise(ShardNameNotFoundError, "no shard found for path '#{shard_path}'")
end end
......
...@@ -93,7 +93,7 @@ module Gitlab ...@@ -93,7 +93,7 @@ module Gitlab
@relative_path = relative_path @relative_path = relative_path
@gl_repository = gl_repository @gl_repository = gl_repository
storage_path = Gitlab.config.repositories.storages[@storage]['path'] storage_path = Gitlab.config.repositories.storages[@storage].legacy_disk_path
@gitlab_projects = Gitlab::Git::GitlabProjects.new( @gitlab_projects = Gitlab::Git::GitlabProjects.new(
storage_path, storage_path,
relative_path, relative_path,
......
...@@ -35,7 +35,7 @@ module Gitlab ...@@ -35,7 +35,7 @@ module Gitlab
def initialize(storage, logger = Rails.logger) def initialize(storage, logger = Rails.logger)
@storage = storage @storage = storage
config = Gitlab.config.repositories.storages[@storage] config = Gitlab.config.repositories.storages[@storage]
@storage_path = config['path'] @storage_path = config.legacy_disk_path
@logger = logger @logger = logger
@hostname = Gitlab::Environment.hostname @hostname = Gitlab::Environment.hostname
......
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
if !config.present? if !config.present?
NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Storage '#{storage}' is not configured")) NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Storage '#{storage}' is not configured"))
elsif !config['path'].present? elsif !config.legacy_disk_path.present?
NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Path for storage '#{storage}' is not configured")) NullCircuitBreaker.new(storage, hostname, error: Misconfiguration.new("Path for storage '#{storage}' is not configured"))
else else
new(storage, hostname) new(storage, hostname)
......
module Gitlab
module GitalyClient
# This is a chokepoint that is meant to help us stop remove all places
# where production code (app, config, db, lib) touches Git repositories
# directly.
class StorageSettings
DirectPathAccessError = Class.new(StandardError)
# This class will give easily recognizable NoMethodErrors
Deprecated = Class.new
attr_reader :legacy_disk_path
def initialize(storage)
raise "expected a Hash, got a #{storage.class.name}" unless storage.is_a?(Hash)
# Support a nil 'path' field because some of the circuit breaker tests use it.
@legacy_disk_path = File.expand_path(storage['path'], Rails.root) if storage['path']
storage['path'] = Deprecated
@hash = storage
end
def gitaly_address
@hash.fetch(:gitaly_address)
end
private
def method_missing(m, *args, &block)
@hash.public_send(m, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
end
end
end
end
...@@ -77,7 +77,7 @@ module Gitlab ...@@ -77,7 +77,7 @@ module Gitlab
end end
def storage_path(storage_name) def storage_path(storage_name)
storages_paths&.dig(storage_name, 'path') storages_paths[storage_name]&.legacy_disk_path
end end
# All below test methods use shell commands to perform actions on storage volumes. # All below test methods use shell commands to perform actions on storage volumes.
......
...@@ -21,11 +21,11 @@ module Gitlab ...@@ -21,11 +21,11 @@ module Gitlab
result = repo_path result = repo_path
storage = Gitlab.config.repositories.storages.values.find do |params| storage = Gitlab.config.repositories.storages.values.find do |params|
repo_path.start_with?(params['path']) repo_path.start_with?(params.legacy_disk_path)
end end
if storage if storage
result = result.sub(storage['path'], '') result = result.sub(storage.legacy_disk_path, '')
elsif fail_on_not_found elsif fail_on_not_found
raise NotFoundError.new("No known storage path matches #{repo_path.inspect}") raise NotFoundError.new("No known storage path matches #{repo_path.inspect}")
end end
......
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
address = val['gitaly_address'] address = val['gitaly_address']
end end
storages << { name: key, path: val['path'] } storages << { name: key, path: val.legacy_disk_path }
end end
if Rails.env.test? if Rails.env.test?
......
...@@ -82,7 +82,7 @@ module Gitlab ...@@ -82,7 +82,7 @@ module Gitlab
repository.gitaly_repository_client.create_repository repository.gitaly_repository_client.create_repository
true true
else else
repo_path = File.join(Gitlab.config.repositories.storages[storage]['path'], relative_path) repo_path = File.join(Gitlab.config.repositories.storages[storage].legacy_disk_path, relative_path)
Gitlab::Git::Repository.create(repo_path, bare: true, symlink_hooks_to: gitlab_shell_hooks_path) Gitlab::Git::Repository.create(repo_path, bare: true, symlink_hooks_to: gitlab_shell_hooks_path)
end end
end end
...@@ -131,7 +131,7 @@ module Gitlab ...@@ -131,7 +131,7 @@ module Gitlab
if is_enabled if is_enabled
repository.gitaly_repository_client.fetch_remote(remote, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags, timeout: git_timeout, prune: prune) repository.gitaly_repository_client.fetch_remote(remote, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags, timeout: git_timeout, prune: prune)
else else
storage_path = Gitlab.config.repositories.storages[repository.storage]["path"] storage_path = Gitlab.config.repositories.storages[repository.storage].legacy_disk_path
local_fetch_remote(storage_path, repository.relative_path, remote, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags, prune: prune) local_fetch_remote(storage_path, repository.relative_path, remote, ssh_auth: ssh_auth, forced: forced, no_tags: no_tags, prune: prune)
end end
end end
...@@ -478,7 +478,7 @@ module Gitlab ...@@ -478,7 +478,7 @@ module Gitlab
def gitaly_namespace_client(storage_path) def gitaly_namespace_client(storage_path)
storage, _value = Gitlab.config.repositories.storages.find do |storage, value| storage, _value = Gitlab.config.repositories.storages.find do |storage, value|
value['path'] == storage_path value.legacy_disk_path == storage_path
end end
Gitlab::GitalyClient::NamespaceService.new(storage) Gitlab::GitalyClient::NamespaceService.new(storage)
......
...@@ -129,7 +129,7 @@ module Gitlab ...@@ -129,7 +129,7 @@ module Gitlab
def all_repos def all_repos
Gitlab.config.repositories.storages.each_value do |repository_storage| Gitlab.config.repositories.storages.each_value do |repository_storage|
IO.popen(%W(find #{repository_storage['path']} -mindepth 2 -type d -name *.git)) do |find| IO.popen(%W(find #{repository_storage.legacy_disk_path} -mindepth 2 -type d -name *.git)) do |find|
find.each_line do |path| find.each_line do |path|
yield path.chomp yield path.chomp
end end
...@@ -138,7 +138,7 @@ module Gitlab ...@@ -138,7 +138,7 @@ module Gitlab
end end
def repository_storage_paths_args def repository_storage_paths_args
Gitlab.config.repositories.storages.values.map { |rs| rs['path'] } Gitlab.config.repositories.storages.values.map { |rs| rs.legacy_disk_path }
end end
def user_home def user_home
......
...@@ -6,8 +6,8 @@ module SystemCheck ...@@ -6,8 +6,8 @@ module SystemCheck
def multi_check def multi_check
Gitlab.config.repositories.storages.each do |storage_name, repository_storage| Gitlab.config.repositories.storages.each do |storage_name, repository_storage|
$stdout.puts $stdout.puts
$stdout.puts "* Storage: #{storage_name} (#{repository_storage['path']})".color(:yellow) $stdout.puts "* Storage: #{storage_name} (#{repository_storage.legacy_disk_path})".color(:yellow)
toplevel_namespace_dirs = disk_namespaces(repository_storage['path']) toplevel_namespace_dirs = disk_namespaces(repository_storage.legacy_disk_path)
orphans = (toplevel_namespace_dirs - existing_namespaces) orphans = (toplevel_namespace_dirs - existing_namespaces)
print_orphans(orphans, storage_name) print_orphans(orphans, storage_name)
......
...@@ -6,10 +6,12 @@ module SystemCheck ...@@ -6,10 +6,12 @@ module SystemCheck
def multi_check def multi_check
Gitlab.config.repositories.storages.each do |storage_name, repository_storage| Gitlab.config.repositories.storages.each do |storage_name, repository_storage|
storage_path = repository_storage.legacy_disk_path
$stdout.puts $stdout.puts
$stdout.puts "* Storage: #{storage_name} (#{repository_storage['path']})".color(:yellow) $stdout.puts "* Storage: #{storage_name} (#{storage_path})".color(:yellow)
repositories = disk_repositories(repository_storage['path']) repositories = disk_repositories(storage_path)
orphans = (repositories - fetch_repositories(storage_name)) orphans = (repositories - fetch_repositories(storage_name))
print_orphans(orphans, storage_name) print_orphans(orphans, storage_name)
......
...@@ -61,7 +61,7 @@ namespace :gitlab do ...@@ -61,7 +61,7 @@ namespace :gitlab do
puts "Repo base directory exists?" puts "Repo base directory exists?"
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path'] repo_base_path = repository_storage.legacy_disk_path
print "#{name}... " print "#{name}... "
if File.exist?(repo_base_path) if File.exist?(repo_base_path)
...@@ -86,7 +86,7 @@ namespace :gitlab do ...@@ -86,7 +86,7 @@ namespace :gitlab do
puts "Repo storage directories are symlinks?" puts "Repo storage directories are symlinks?"
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path'] repo_base_path = repository_storage.legacy_disk_path
print "#{name}... " print "#{name}... "
unless File.exist?(repo_base_path) unless File.exist?(repo_base_path)
...@@ -110,7 +110,7 @@ namespace :gitlab do ...@@ -110,7 +110,7 @@ namespace :gitlab do
puts "Repo paths access is drwxrws---?" puts "Repo paths access is drwxrws---?"
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path'] repo_base_path = repository_storage.legacy_disk_path
print "#{name}... " print "#{name}... "
unless File.exist?(repo_base_path) unless File.exist?(repo_base_path)
...@@ -140,7 +140,7 @@ namespace :gitlab do ...@@ -140,7 +140,7 @@ namespace :gitlab do
puts "Repo paths owned by #{gitlab_shell_ssh_user}:root, or #{gitlab_shell_ssh_user}:#{Gitlab.config.gitlab_shell.owner_group}?" puts "Repo paths owned by #{gitlab_shell_ssh_user}:root, or #{gitlab_shell_ssh_user}:#{Gitlab.config.gitlab_shell.owner_group}?"
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_base_path = repository_storage['path'] repo_base_path = repository_storage.legacy_disk_path
print "#{name}... " print "#{name}... "
unless File.exist?(repo_base_path) unless File.exist?(repo_base_path)
......
...@@ -12,7 +12,7 @@ namespace :gitlab do ...@@ -12,7 +12,7 @@ namespace :gitlab do
namespaces = Namespace.pluck(:path) namespaces = Namespace.pluck(:path)
namespaces << HASHED_REPOSITORY_NAME # add so that it will be ignored namespaces << HASHED_REPOSITORY_NAME # add so that it will be ignored
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
git_base_path = repository_storage['path'] git_base_path = repository_storage.legacy_disk_path
all_dirs = Dir.glob(git_base_path + '/*') all_dirs = Dir.glob(git_base_path + '/*')
puts git_base_path.color(:yellow) puts git_base_path.color(:yellow)
...@@ -54,7 +54,7 @@ namespace :gitlab do ...@@ -54,7 +54,7 @@ namespace :gitlab do
move_suffix = "+orphaned+#{Time.now.to_i}" move_suffix = "+orphaned+#{Time.now.to_i}"
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
repo_root = repository_storage['path'] repo_root = repository_storage.legacy_disk_path
# Look for global repos (legacy, depth 1) and normal repos (depth 2) # Look for global repos (legacy, depth 1) and normal repos (depth 2)
IO.popen(%W(find #{repo_root} -mindepth 1 -maxdepth 2 -name *.git)) do |find| IO.popen(%W(find #{repo_root} -mindepth 1 -maxdepth 2 -name *.git)) do |find|
find.each_line do |path| find.each_line do |path|
......
...@@ -68,7 +68,7 @@ namespace :gitlab do ...@@ -68,7 +68,7 @@ namespace :gitlab do
puts "Version:\t#{gitlab_shell_version || "unknown".color(:red)}" puts "Version:\t#{gitlab_shell_version || "unknown".color(:red)}"
puts "Repository storage paths:" puts "Repository storage paths:"
Gitlab.config.repositories.storages.each do |name, repository_storage| Gitlab.config.repositories.storages.each do |name, repository_storage|
puts "- #{name}: \t#{repository_storage['path']}" puts "- #{name}: \t#{repository_storage.legacy_disk_path}"
end end
puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}" puts "Hooks:\t\t#{Gitlab.config.gitlab_shell.hooks_path}"
puts "Git:\t\t#{Gitlab.config.git.bin_path}" puts "Git:\t\t#{Gitlab.config.git.bin_path}"
......
...@@ -15,7 +15,7 @@ describe '6_validations' do ...@@ -15,7 +15,7 @@ describe '6_validations' do
describe 'validate_storages_config' do describe 'validate_storages_config' do
context 'with correct settings' do context 'with correct settings' do
before do before do
mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/d' }) mock_storages('foo' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c'), 'bar' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/d'))
end end
it 'passes through' do it 'passes through' do
...@@ -25,7 +25,7 @@ describe '6_validations' do ...@@ -25,7 +25,7 @@ describe '6_validations' do
context 'when one of the settings is incorrect' do context 'when one of the settings is incorrect' do
before do before do
mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c', 'failure_count_threshold' => 'not a number' }) mock_storages('foo' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c', 'failure_count_threshold' => 'not a number'))
end end
it 'throws an error' do it 'throws an error' do
...@@ -35,7 +35,7 @@ describe '6_validations' do ...@@ -35,7 +35,7 @@ describe '6_validations' do
context 'with invalid storage names' do context 'with invalid storage names' do
before do before do
mock_storages('name with spaces' => { 'path' => 'tmp/tests/paths/a/b/c' }) mock_storages('name with spaces' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c'))
end end
it 'throws an error' do it 'throws an error' do
...@@ -67,7 +67,7 @@ describe '6_validations' do ...@@ -67,7 +67,7 @@ describe '6_validations' do
describe 'validate_storages_paths' do describe 'validate_storages_paths' do
context 'with correct settings' do context 'with correct settings' do
before do before do
mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/d' }) mock_storages('foo' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c'), 'bar' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/d'))
end end
it 'passes through' do it 'passes through' do
...@@ -77,7 +77,7 @@ describe '6_validations' do ...@@ -77,7 +77,7 @@ describe '6_validations' do
context 'with nested storage paths' do context 'with nested storage paths' do
before do before do
mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/c/d' }) mock_storages('foo' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c'), 'bar' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c/d'))
end end
it 'throws an error' do it 'throws an error' do
...@@ -87,7 +87,7 @@ describe '6_validations' do ...@@ -87,7 +87,7 @@ describe '6_validations' do
context 'with similar but un-nested storage paths' do context 'with similar but un-nested storage paths' do
before do before do
mock_storages('foo' => { 'path' => 'tmp/tests/paths/a/b/c' }, 'bar' => { 'path' => 'tmp/tests/paths/a/b/c2' }) mock_storages('foo' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c'), 'bar' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/paths/a/b/c2'))
end end
it 'passes through' do it 'passes through' do
...@@ -97,7 +97,7 @@ describe '6_validations' do ...@@ -97,7 +97,7 @@ describe '6_validations' do
describe 'inaccessible storage' do describe 'inaccessible storage' do
before do before do
mock_storages('foo' => { 'path' => 'tmp/tests/a/path/that/does/not/exist' }) mock_storages('foo' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/a/path/that/does/not/exist'))
end end
it 'passes through with a warning' do it 'passes through with a warning' do
......
require 'spec_helper' require 'spec_helper'
require_relative '../../config/initializers/1_settings' require_relative '../../config/initializers/1_settings' unless defined?(Settings)
describe Settings do describe Settings do
describe '#ldap' do describe '#ldap' do
......
...@@ -33,7 +33,7 @@ describe Backup::Repository do ...@@ -33,7 +33,7 @@ describe Backup::Repository do
let(:timestamp) { Time.utc(2017, 3, 22) } let(:timestamp) { Time.utc(2017, 3, 22) }
let(:temp_dirs) do let(:temp_dirs) do
Gitlab.config.repositories.storages.map do |name, storage| Gitlab.config.repositories.storages.map do |name, storage|
File.join(storage['path'], '..', 'repositories.old.' + timestamp.to_i.to_s) File.join(storage.legacy_disk_path, '..', 'repositories.old.' + timestamp.to_i.to_s)
end end
end end
......
...@@ -54,7 +54,7 @@ describe ::Gitlab::BareRepositoryImport::Repository do ...@@ -54,7 +54,7 @@ describe ::Gitlab::BareRepositoryImport::Repository do
context 'hashed storage' do context 'hashed storage' do
let(:gitlab_shell) { Gitlab::Shell.new } let(:gitlab_shell) { Gitlab::Shell.new }
let(:repository_storage) { 'default' } let(:repository_storage) { 'default' }
let(:root_path) { Gitlab.config.repositories.storages[repository_storage]['path'] } let(:root_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' } let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
let(:hashed_path) { "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" } let(:hashed_path) { "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" }
let(:repo_path) { File.join(root_path, "#{hashed_path}.git") } let(:repo_path) { File.join(root_path, "#{hashed_path}.git") }
......
...@@ -26,7 +26,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do ...@@ -26,7 +26,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do
let(:storages_paths) do let(:storages_paths) do
{ {
default: { path: tmp_dir } default: Gitlab::GitalyClient::StorageSettings.new('path' => tmp_dir)
}.with_indifferent_access }.with_indifferent_access
end end
...@@ -56,7 +56,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do ...@@ -56,7 +56,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do
context 'storage points to not existing folder' do context 'storage points to not existing folder' do
let(:storages_paths) do let(:storages_paths) do
{ {
default: { path: 'tmp/this/path/doesnt/exist' } default: Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/this/path/doesnt/exist')
}.with_indifferent_access }.with_indifferent_access
end end
...@@ -102,7 +102,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do ...@@ -102,7 +102,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do
context 'storage points to not existing folder' do context 'storage points to not existing folder' do
let(:storages_paths) do let(:storages_paths) do
{ {
default: { path: 'tmp/this/path/doesnt/exist' } default: Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/this/path/doesnt/exist')
}.with_indifferent_access }.with_indifferent_access
end end
......
...@@ -48,8 +48,8 @@ describe ::Gitlab::RepoPath do ...@@ -48,8 +48,8 @@ describe ::Gitlab::RepoPath do
describe '.strip_storage_path' do describe '.strip_storage_path' do
before do before do
allow(Gitlab.config.repositories).to receive(:storages).and_return({ allow(Gitlab.config.repositories).to receive(:storages).and_return({
'storage1' => { 'path' => '/foo' }, 'storage1' => Gitlab::GitalyClient::StorageSettings.new('path' => '/foo'),
'storage2' => { 'path' => '/bar' } 'storage2' => Gitlab::GitalyClient::StorageSettings.new('path' => '/bar')
}) })
end end
......
...@@ -405,7 +405,7 @@ describe Gitlab::Shell do ...@@ -405,7 +405,7 @@ describe Gitlab::Shell do
describe '#create_repository' do describe '#create_repository' do
shared_examples '#create_repository' do shared_examples '#create_repository' do
let(:repository_storage) { 'default' } let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage]['path'] } let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:repo_name) { 'project/path' } let(:repo_name) { 'project/path' }
let(:created_path) { File.join(repository_storage_path, repo_name + '.git') } let(:created_path) { File.join(repository_storage_path, repo_name + '.git') }
...@@ -679,7 +679,7 @@ describe Gitlab::Shell do ...@@ -679,7 +679,7 @@ describe Gitlab::Shell do
describe 'namespace actions' do describe 'namespace actions' do
subject { described_class.new } subject { described_class.new }
let(:storage_path) { Gitlab.config.repositories.storages.default.path } let(:storage_path) { Gitlab.config.repositories.storages.default.legacy_disk_path }
describe '#add_namespace' do describe '#add_namespace' do
it 'creates a namespace' do it 'creates a namespace' do
......
...@@ -29,7 +29,9 @@ describe RemoveDotGitFromUsernames do ...@@ -29,7 +29,9 @@ describe RemoveDotGitFromUsernames do
update_namespace(user, 'test.git') update_namespace(user, 'test.git')
update_namespace(user2, 'test_git') update_namespace(user2, 'test_git')
storages = { 'default' => 'tmp/tests/custom_repositories' } default_hash = Gitlab.config.repositories.storages.default.to_h
default_hash['path'] = 'tmp/tests/custom_repositories'
storages = { 'default' => Gitlab::GitalyClient::StorageSettings.new(default_hash) }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
allow(migration).to receive(:route_exists?).with('test_git').and_return(true) allow(migration).to receive(:route_exists?).with('test_git').and_return(true)
......
...@@ -305,7 +305,7 @@ describe Namespace do ...@@ -305,7 +305,7 @@ describe Namespace do
end end
describe '#rm_dir', 'callback' do describe '#rm_dir', 'callback' do
let(:repository_storage_path) { Gitlab.config.repositories.storages.default['path'] } let(:repository_storage_path) { Gitlab.config.repositories.storages.default.legacy_disk_path }
let(:path_in_dir) { File.join(repository_storage_path, namespace.full_path) } let(:path_in_dir) { File.join(repository_storage_path, namespace.full_path) }
let(:deleted_path) { namespace.full_path.gsub(namespace.path, "#{namespace.full_path}+#{namespace.id}+deleted") } let(:deleted_path) { namespace.full_path.gsub(namespace.path, "#{namespace.full_path}+#{namespace.id}+deleted") }
let(:deleted_path_in_dir) { File.join(repository_storage_path, deleted_path) } let(:deleted_path_in_dir) { File.join(repository_storage_path, deleted_path) }
......
...@@ -1101,8 +1101,8 @@ describe Project do ...@@ -1101,8 +1101,8 @@ describe Project do
before do before do
storages = { storages = {
'default' => { 'path' => 'tmp/tests/repositories' }, 'default' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories'),
'picked' => { 'path' => 'tmp/tests/repositories' } 'picked' => Gitlab::GitalyClient::StorageSettings.new('path' => 'tmp/tests/repositories')
} }
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
......
...@@ -153,7 +153,7 @@ describe Projects::CreateService, '#execute' do ...@@ -153,7 +153,7 @@ describe Projects::CreateService, '#execute' do
context 'when another repository already exists on disk' do context 'when another repository already exists on disk' do
let(:repository_storage) { 'default' } let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage]['path'] } let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:opts) do let(:opts) do
{ {
......
...@@ -105,7 +105,7 @@ describe Projects::ForkService do ...@@ -105,7 +105,7 @@ describe Projects::ForkService do
context 'repository already exists' do context 'repository already exists' do
let(:repository_storage) { 'default' } let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage]['path'] } let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
before do before do
gitlab_shell.create_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}") gitlab_shell.create_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}")
......
...@@ -146,7 +146,7 @@ describe Projects::TransferService do ...@@ -146,7 +146,7 @@ describe Projects::TransferService do
context 'namespace which contains orphan repository with same projects path name' do context 'namespace which contains orphan repository with same projects path name' do
let(:repository_storage) { 'default' } let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage]['path'] } let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
before do before do
group.add_owner(user) group.add_owner(user)
......
...@@ -190,7 +190,7 @@ describe Projects::UpdateService do ...@@ -190,7 +190,7 @@ describe Projects::UpdateService do
context 'when renaming a project' do context 'when renaming a project' do
let(:repository_storage) { 'default' } let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage]['path'] } let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
context 'with legacy storage' do context 'with legacy storage' do
let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) } let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) }
......
...@@ -4,7 +4,7 @@ RSpec.configure do |config| ...@@ -4,7 +4,7 @@ RSpec.configure do |config|
end end
config.before(:all, :broken_storage) do config.before(:all, :broken_storage) do
FileUtils.rm_rf Gitlab.config.repositories.storages.broken['path'] FileUtils.rm_rf Gitlab.config.repositories.storages.broken.legacy_disk_path
end end
config.before(:each, :broken_storage) do config.before(:each, :broken_storage) do
......
...@@ -50,8 +50,12 @@ module StubConfiguration ...@@ -50,8 +50,12 @@ module StubConfiguration
# Default storage is always required # Default storage is always required
messages['default'] ||= Gitlab.config.repositories.storages.default messages['default'] ||= Gitlab.config.repositories.storages.default
messages.each do |storage_name, storage_settings| messages.each do |storage_name, storage_hash|
storage_settings['path'] = TestEnv.repos_path unless storage_settings.key?('path') if !storage_hash.key?('path') || storage_hash['path'] == Gitlab::GitalyClient::StorageSettings::Deprecated
storage_hash['path'] = TestEnv.repos_path
end
messages[storage_name] = Gitlab::GitalyClient::StorageSettings.new(storage_hash.to_h)
end end
allow(Gitlab.config.repositories).to receive(:storages).and_return(Settingslogic.new(messages)) allow(Gitlab.config.repositories).to receive(:storages).and_return(Settingslogic.new(messages))
......
...@@ -225,7 +225,7 @@ module TestEnv ...@@ -225,7 +225,7 @@ module TestEnv
end end
def repos_path def repos_path
Gitlab.config.repositories.storages.default['path'] Gitlab.config.repositories.storages.default.legacy_disk_path
end end
def backup_path def backup_path
......
...@@ -195,14 +195,23 @@ describe 'gitlab:app namespace rake task' do ...@@ -195,14 +195,23 @@ describe 'gitlab:app namespace rake task' do
end end
context 'multiple repository storages' do context 'multiple repository storages' do
let(:gitaly_address) { Gitlab.config.repositories.storages.default.gitaly_address } let(:storage_default) do
Gitlab::GitalyClient::StorageSettings.new(@default_storage_hash.merge('path' => 'tmp/tests/default_storage'))
end
let(:test_second_storage) do
Gitlab::GitalyClient::StorageSettings.new(@default_storage_hash.merge('path' => 'tmp/tests/custom_storage'))
end
let(:storages) do let(:storages) do
{ {
'default' => { 'path' => Settings.absolute('tmp/tests/default_storage'), 'gitaly_address' => gitaly_address }, 'default' => storage_default,
'test_second_storage' => { 'path' => Settings.absolute('tmp/tests/custom_storage'), 'gitaly_address' => gitaly_address } 'test_second_storage' => test_second_storage
} }
end end
before(:all) do
@default_storage_hash = Gitlab.config.repositories.storages.default.to_h
end
before do before do
# We only need a backup of the repositories for this test # We only need a backup of the repositories for this test
stub_env('SKIP', 'db,uploads,builds,artifacts,lfs,registry') stub_env('SKIP', 'db,uploads,builds,artifacts,lfs,registry')
......
...@@ -6,13 +6,16 @@ describe 'gitlab:cleanup rake tasks' do ...@@ -6,13 +6,16 @@ describe 'gitlab:cleanup rake tasks' do
end end
describe 'cleanup' do describe 'cleanup' do
let(:gitaly_address) { Gitlab.config.repositories.storages.default.gitaly_address }
let(:storages) do let(:storages) do
{ {
'default' => { 'path' => Settings.absolute('tmp/tests/default_storage'), 'gitaly_address' => gitaly_address } 'default' => Gitlab::GitalyClient::StorageSettings.new(@default_storage_hash.merge('path' => 'tmp/tests/default_storage'))
} }
end end
before(:all) do
@default_storage_hash = Gitlab.config.repositories.storages.default.to_h
end
before do before do
FileUtils.mkdir(Settings.absolute('tmp/tests/default_storage')) FileUtils.mkdir(Settings.absolute('tmp/tests/default_storage'))
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
......
require 'rake_helper' require 'rake_helper'
describe 'gitlab:git rake tasks' do describe 'gitlab:git rake tasks' do
before(:all) do
@default_storage_hash = Gitlab.config.repositories.storages.default.to_h
end
before do before do
Rake.application.rake_require 'tasks/gitlab/git' Rake.application.rake_require 'tasks/gitlab/git'
storages = { 'default' => Gitlab::GitalyClient::StorageSettings.new(@default_storage_hash.merge('path' => 'tmp/tests/default_storage')) }
storages = { 'default' => { 'path' => Settings.absolute('tmp/tests/default_storage') } }
FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/1/2/test.git')) FileUtils.mkdir_p(Settings.absolute('tmp/tests/default_storage/@hashed/1/2/test.git'))
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
......
...@@ -99,14 +99,14 @@ describe 'gitlab:gitaly namespace rake task' do ...@@ -99,14 +99,14 @@ describe 'gitlab:gitaly namespace rake task' do
describe 'storage_config' do describe 'storage_config' do
it 'prints storage configuration in a TOML format' do it 'prints storage configuration in a TOML format' do
config = { config = {
'default' => { 'default' => Gitlab::GitalyClient::StorageSettings.new(
'path' => '/path/to/default', 'path' => '/path/to/default',
'gitaly_address' => 'unix:/path/to/my.socket' 'gitaly_address' => 'unix:/path/to/my.socket'
}, ),
'nfs_01' => { 'nfs_01' => Gitlab::GitalyClient::StorageSettings.new(
'path' => '/path/to/nfs_01', 'path' => '/path/to/nfs_01',
'gitaly_address' => 'unix:/path/to/my.socket' 'gitaly_address' => 'unix:/path/to/my.socket'
} )
} }
allow(Gitlab.config.repositories).to receive(:storages).and_return(config) allow(Gitlab.config.repositories).to receive(:storages).and_return(config)
allow(Rails.env).to receive(:test?).and_return(false) allow(Rails.env).to receive(:test?).and_return(false)
...@@ -134,7 +134,7 @@ describe 'gitlab:gitaly namespace rake task' do ...@@ -134,7 +134,7 @@ describe 'gitlab:gitaly namespace rake task' do
parsed_output = TomlRB.parse(expected_output) parsed_output = TomlRB.parse(expected_output)
config.each do |name, params| config.each do |name, params|
expect(parsed_output['storage']).to include({ 'name' => name, 'path' => params['path'] }) expect(parsed_output['storage']).to include({ 'name' => name, 'path' => params.legacy_disk_path })
end end
end end
end end
......
...@@ -11,7 +11,7 @@ describe 'gitlab:shell rake tasks' do ...@@ -11,7 +11,7 @@ describe 'gitlab:shell rake tasks' do
it 'invokes create_hooks task' do it 'invokes create_hooks task' do
expect(Rake::Task['gitlab:shell:create_hooks']).to receive(:invoke) expect(Rake::Task['gitlab:shell:create_hooks']).to receive(:invoke)
storages = Gitlab.config.repositories.storages.values.map { |rs| rs['path'] } storages = Gitlab.config.repositories.storages.values.map(&:legacy_disk_path)
expect(Kernel).to receive(:system).with('bin/install', *storages).and_call_original expect(Kernel).to receive(:system).with('bin/install', *storages).and_call_original
expect(Kernel).to receive(:system).with('bin/compile').and_call_original expect(Kernel).to receive(:system).with('bin/compile').and_call_original
......
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