Fix type validation warning for storage policy rings

Since 63688a14e5 was merged, this module
support configuring storage policies.

When multiple storage policies are used, we need to create multiple
object rings like object.ring.gz, object-1.ring.gz. However the current
regexp to validate the ring name does not consider this format and
shows the type validation warning when creating a non-default policy
rings.

This change updates the regexp used in validation to accept that
object-<number> format as well.

Closes-Bug: #1987260
Change-Id: Ibc7479e7defbfa4c49bf3c9f1574cdcf61b90ab9
This commit is contained in:
Takashi Kajinami 2022-08-22 17:11:34 +09:00
parent 839ccc7f20
commit 11b193cab8
4 changed files with 27 additions and 15 deletions

View File

@ -41,8 +41,10 @@ define swift::ringbuilder::create(
include swift::deps include swift::deps
validate_legacy(Enum['object', 'container', 'account'], 'validate_re', $name, validate_legacy(
['^object|container|account$']) Pattern[/^(object(-(\d)+)?|container|account)$/], 'validate_re', $name,
['^(object(-(\d)+)?|container|account)$']
)
exec { "create_${name}": exec { "create_${name}":
command => "swift-ring-builder /etc/swift/${name}.builder create ${part_power} ${replicas} ${min_part_hours}", command => "swift-ring-builder /etc/swift/${name}.builder create ${part_power} ${replicas} ${min_part_hours}",

View File

@ -14,8 +14,10 @@ define swift::ringbuilder::rebalance(
include swift::deps include swift::deps
validate_legacy(Enum['object', 'container', 'account'], 'validate_re', $name, validate_legacy(
['^object|container|account$']) Pattern[/^(object(-(\d)+)?|container|account)$/], 'validate_re', $name,
['^(object(-(\d)+)?|container|account)$']
)
if $seed { if $seed {
validate_legacy(Integer, 'validate_re', $seed, ['^\d+$']) validate_legacy(Integer, 'validate_re', $seed, ['^\d+$'])

View File

@ -12,7 +12,7 @@ describe 'swift::ringbuilder::create' do
shared_examples 'swift::ringbuilder::create' do shared_examples 'swift::ringbuilder::create' do
describe 'with allowed titles' do describe 'with allowed titles' do
['object', 'container', 'account'].each do |type| ['object', 'container', 'account', 'object-1', 'object-123'].each do |type|
describe "when title is #{type}" do describe "when title is #{type}" do
let :title do let :title do
type type
@ -46,11 +46,15 @@ describe 'swift::ringbuilder::create' do
end end
describe 'with an invalid title' do describe 'with an invalid title' do
let :title do ['invalid', 'container-1', 'account-1', 'object-a', 'object-12a'].each do |type|
'invalid' describe "when title is #{type}" do
end let :title do
type
end
it { should raise_error(Puppet::Error) } it { should raise_error(Puppet::Error) }
end
end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe 'swift::ringbuilder::rebalance' do describe 'swift::ringbuilder::rebalance' do
shared_examples 'swift::ringbuilder::rebalance' do shared_examples 'swift::ringbuilder::rebalance' do
describe 'with allowed titles' do describe 'with allowed titles' do
['object', 'container', 'account'].each do |type| ['object', 'container', 'account', 'object-1', 'object-123'].each do |type|
describe "when title is #{type}" do describe "when title is #{type}" do
let :title do let :title do
type type
@ -49,12 +49,16 @@ describe 'swift::ringbuilder::rebalance' do
end end
describe 'with an invalid title' do describe 'with an invalid title' do
let :title do ['invalid', 'container-1', 'account-1', 'object-a', 'object-12a'].each do |type|
'invalid' describe "when title is #{type}" do
end let :title do
type
end
it 'should raise an error' do it 'should raise an error' do
expect { catalogue }.to raise_error(Puppet::Error) expect { catalogue }.to raise_error(Puppet::Error)
end
end
end end
end end
end end