Use validate_legacy

This changes all the puppet 3 validate_* functions
to use the validate_legacy function.

The validate_legacy function has been available since
about three years but require Puppet >= 4.4.0 and since
there is Puppet 4.10.12 as latest we should assume people
are running a fairly new Puppet 4 version.

This is the first step to then remove all validate function
calls and use proper types for parameter as described in spec [1].

[1] https://review.openstack.org/#/c/568929/

Change-Id: I5661c2d685b4bf2422936326db1c3d543a49f92a
This commit is contained in:
Tobias Urdin 2019-02-23 22:57:48 +01:00
parent 12143624e8
commit ba1ec6d40c
13 changed files with 36 additions and 29 deletions

View File

@ -35,9 +35,10 @@ class swift::config (
) { ) {
include ::swift::deps include ::swift::deps
validate_hash($swift_config)
validate_hash($swift_container_sync_realms_config) validate_legacy(Hash, 'validate_hash', $swift_config)
validate_hash($swift_proxy_config) validate_legacy(Hash, 'validate_hash', $swift_container_sync_realms_config)
validate_legacy(Hash, 'validate_hash', $swift_proxy_config)
create_resources('swift_config', $swift_config) create_resources('swift_config', $swift_config)
create_resources('swift_container_sync_realms_config', $swift_container_sync_realms_config) create_resources('swift_container_sync_realms_config', $swift_container_sync_realms_config)

View File

@ -170,9 +170,9 @@ class swift::proxy(
include ::swift::deps include ::swift::deps
Swift_config<| |> ~> Service['swift-proxy-server'] Swift_config<| |> ~> Service['swift-proxy-server']
validate_bool($account_autocreate) validate_legacy(Boolean, 'validate_bool', $account_autocreate)
validate_bool($allow_account_management) validate_legacy(Boolean, 'validate_bool', $allow_account_management)
validate_array($pipeline) validate_legacy(Array, 'validate_array', $pipeline)
if($write_affinity_node_count and ! $write_affinity) { if($write_affinity_node_count and ! $write_affinity) {
fail('Usage of write_affinity_node_count requires write_affinity to be set') fail('Usage of write_affinity_node_count requires write_affinity to be set')

View File

@ -83,30 +83,30 @@ class swift::proxy::tempauth (
include ::swift::deps include ::swift::deps
validate_array($account_user_list) validate_legacy(Array, 'validate_array', $account_user_list)
if ($reseller_prefix) { if ($reseller_prefix) {
validate_string($reseller_prefix) validate_legacy(String, 'validate_string', $reseller_prefix)
$reseller_prefix_upcase = upcase($reseller_prefix) $reseller_prefix_upcase = upcase($reseller_prefix)
} }
if ($token_life) { if ($token_life) {
validate_integer($token_life) validate_legacy(Integer, 'validate_integer', $token_life)
} }
if ($auth_prefix) { if ($auth_prefix) {
validate_re($auth_prefix,'\/(.*)+\/') validate_legacy(Pattern[/\/(.*)+\//], 'validate_re', $auth_prefix, ['\/(.*)+\/'])
} }
if ($allow_overrides) { if ($allow_overrides) {
validate_bool($allow_overrides) validate_legacy(Boolean, 'validate_bool', $allow_overrides)
} }
if ($storage_url_scheme) { if ($storage_url_scheme) {
validate_re($storage_url_scheme, ['http','https','default']) validate_legacy(Enum['http', 'https', 'default'], 'validate_re',
$storage_url_scheme, [['http', 'https', 'default']])
} }
swift_proxy_config { swift_proxy_config {
'filter:tempauth/use': value => 'egg:swift#tempauth'; 'filter:tempauth/use': value => 'egg:swift#tempauth';
'filter:tempauth/reseller_prefix': value => $reseller_prefix_upcase; 'filter:tempauth/reseller_prefix': value => $reseller_prefix_upcase;

View File

@ -41,7 +41,8 @@ define swift::ringbuilder::create(
include ::swift::deps include ::swift::deps
validate_re($name, '^object|container|account$') validate_legacy(Enum['object', 'container', 'account'], 'validate_re', $name,
['^object|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

@ -35,8 +35,8 @@ define swift::ringbuilder::policy_ring(
$min_part_hours = undef, $min_part_hours = undef,
) { ) {
validate_legacy(Pattern[/^\d+$/], 'validate_re', $title, ['^\d+$'])
validate_re($title, '^\d+$')
include ::swift::deps include ::swift::deps
Class['swift'] -> Swift::Ringbuilder::Policy_ring[$title] Class['swift'] -> Swift::Ringbuilder::Policy_ring[$title]

View File

@ -14,9 +14,11 @@ define swift::ringbuilder::rebalance(
include ::swift::deps include ::swift::deps
validate_re($name, '^object|container|account$') validate_legacy(Enum['object', 'container', 'account'], 'validate_re', $name,
['^object|container|account$'])
if $seed { if $seed {
validate_re($seed, '^\d+$') validate_legacy(Integer, 'validate_re', $seed, ['^\d+$'])
} }
exec { "rebalance_${name}": exec { "rebalance_${name}":

View File

@ -46,7 +46,8 @@ define swift::storage::generic(
Swift_config<| |> ~> Service["swift-${name}-auditor"] Swift_config<| |> ~> Service["swift-${name}-auditor"]
Swift_config<| |> ~> Service["swift-${name}-replicator"] Swift_config<| |> ~> Service["swift-${name}-replicator"]
validate_re($name, '^object|container|account$') validate_legacy(Enum['object', 'container', 'account'], 'validate_re',
$name, ['^object|container|account$'])
package { "swift-${name}": package { "swift-${name}":
ensure => $package_ensure, ensure => $package_ensure,

View File

@ -54,7 +54,8 @@ define swift::storage::node(
include ::swift::deps include ::swift::deps
validate_re($zone, '^\d+$', 'The zone parameter must be an integer') validate_legacy(Integer, 'validate_re', $zone,
['^\d+$', 'The zone parameter must be an integer'])
Swift::Storage::Server { Swift::Storage::Server {
storage_local_net_ip => $storage_local_net_ip, storage_local_net_ip => $storage_local_net_ip,

View File

@ -209,11 +209,12 @@ define swift::storage::server(
include "::swift::storage::${type}" include "::swift::storage::${type}"
validate_re($name, '^\d+$') validate_legacy(Pattern[/^\d+$/], 'validate_re', $name, ['^\d+$'])
validate_re($type, '^object|container|account$') validate_legacy(Enum['object', 'container', 'account'], 'validate_re',
validate_array($pipeline) $type, ['^object|container|account$'])
validate_bool($allow_versions) validate_legacy(Array, 'validate_array', $pipeline)
validate_bool($splice) validate_legacy(Boolean, 'validate_bool', $allow_versions)
validate_legacy(Boolean, 'validate_bool', $splice)
# TODO - validate that name is an integer # TODO - validate that name is an integer
$bind_port = $name $bind_port = $name

View File

@ -230,7 +230,7 @@ describe 'swift::proxy' do
[:account_autocreate, :allow_account_management].each do |param| [:account_autocreate, :allow_account_management].each do |param|
it "should fail when #{param} is not passed a boolean" do it "should fail when #{param} is not passed a boolean" do
params[param] = 'false' params[param] = 'false'
should raise_error(Puppet::Error, /is not a boolean/) should raise_error(Puppet::Error)
end end
end end

View File

@ -22,7 +22,7 @@ describe 'swift::storage::generic' do
'foo' 'foo'
end end
it_raises 'a Puppet::Error', /does not match/ it { should raise_error(Puppet::Error) }
end end
%w(account object container).each do |t| %w(account object container).each do |t|

View File

@ -32,7 +32,7 @@ describe 'swift::storage::node' do
:mnt_base_dir => '/srv/node' } :mnt_base_dir => '/srv/node' }
end end
it_raises 'a Puppet::Error', /The zone parameter must be an integer/ it { should raise_error(Puppet::Error) }
end end
describe 'with valid preconditons and policy_index=1 should contain ring devices' do describe 'with valid preconditons and policy_index=1 should contain ring devices' do

View File

@ -36,7 +36,7 @@ describe 'swift::storage::server' do
'foo' 'foo'
end end
it_raises 'a Puppet::Error', /does not match/ it { should raise_error(Puppet::Error) }
end end
['account', 'object', 'container'].each do |t| ['account', 'object', 'container'].each do |t|
@ -84,7 +84,7 @@ describe 'swift::storage::server' do
describe "when pipeline is not passed an array" do describe "when pipeline is not passed an array" do
let :params do req_params.merge({:pipeline => 'not an array'}) end let :params do req_params.merge({:pipeline => 'not an array'}) end
it_raises 'a Puppet::Error', /is not an Array/ it { should raise_error(Puppet::Error) }
end end
describe "when replicator_concurrency is set" do describe "when replicator_concurrency is set" do