Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ca22192a
Commit
ca22192a
authored
Feb 10, 2021
by
James Fargher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure new project storage selection never chooses an invalid storage
parent
1a0afd17
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
app/models/application_setting_implementation.rb
app/models/application_setting_implementation.rb
+3
-2
spec/support/shared_examples/models/application_setting_shared_examples.rb
...ed_examples/models/application_setting_shared_examples.rb
+10
-5
No files found.
app/models/application_setting_implementation.rb
View file @
ca22192a
...
...
@@ -328,9 +328,10 @@ module ApplicationSettingImplementation
def
normalized_repository_storage_weights
strong_memoize
(
:normalized_repository_storage_weights
)
do
weights_total
=
repository_storages_weighted
.
values
.
reduce
(:
+
)
repository_storages_weights
=
repository_storages_weighted
.
slice
(
*
Gitlab
.
config
.
repositories
.
storages
.
keys
)
weights_total
=
repository_storages_weights
.
values
.
reduce
(:
+
)
repository_storages_weight
ed
.
transform_values
do
|
w
|
repository_storages_weight
s
.
transform_values
do
|
w
|
next
w
if
weights_total
==
0
w
.
to_f
/
weights_total
...
...
spec/support/shared_examples/models/application_setting_shared_examples.rb
View file @
ca22192a
...
...
@@ -289,6 +289,7 @@ RSpec.shared_examples 'application settings examples' do
describe
'#pick_repository_storage'
do
before
do
allow
(
Gitlab
.
config
.
repositories
.
storages
).
to
receive
(
:keys
).
and_return
(
%w(default backup)
)
allow
(
setting
).
to
receive
(
:repository_storages_weighted
).
and_return
({
'default'
=>
20
,
'backup'
=>
80
})
end
...
...
@@ -304,15 +305,19 @@ RSpec.shared_examples 'application settings examples' do
describe
'#normalized_repository_storage_weights'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:storages
,
:normalized
)
do
{
'default'
=>
0
,
'backup'
=>
100
}
|
{
'default'
=>
0.0
,
'backup'
=>
1.0
}
{
'default'
=>
100
,
'backup'
=>
100
}
|
{
'default'
=>
0.5
,
'backup'
=>
0.5
}
{
'default'
=>
20
,
'backup'
=>
80
}
|
{
'default'
=>
0.2
,
'backup'
=>
0.8
}
{
'default'
=>
0
,
'backup'
=>
0
}
|
{
'default'
=>
0.0
,
'backup'
=>
0.0
}
where
(
:config_storages
,
:storages
,
:normalized
)
do
%w(default backup)
|
{
'default'
=>
0
,
'backup'
=>
100
}
|
{
'default'
=>
0.0
,
'backup'
=>
1.0
}
%w(default backup)
|
{
'default'
=>
100
,
'backup'
=>
100
}
|
{
'default'
=>
0.5
,
'backup'
=>
0.5
}
%w(default backup)
|
{
'default'
=>
20
,
'backup'
=>
80
}
|
{
'default'
=>
0.2
,
'backup'
=>
0.8
}
%w(default backup)
|
{
'default'
=>
0
,
'backup'
=>
0
}
|
{
'default'
=>
0.0
,
'backup'
=>
0.0
}
%w(default)
|
{
'default'
=>
0
,
'backup'
=>
100
}
|
{
'default'
=>
0.0
}
%w(default)
|
{
'default'
=>
100
,
'backup'
=>
100
}
|
{
'default'
=>
1.0
}
%w(default)
|
{
'default'
=>
20
,
'backup'
=>
80
}
|
{
'default'
=>
1.0
}
end
with_them
do
before
do
allow
(
Gitlab
.
config
.
repositories
.
storages
).
to
receive
(
:keys
).
and_return
(
config_storages
)
allow
(
setting
).
to
receive
(
:repository_storages_weighted
).
and_return
(
storages
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment