From 4b558f6f007f3f0ee01150a55962f750876bef13 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Sat, 23 Feb 2019 11:57:34 +0100 Subject: [PATCH] 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: Ib21fef57404d63579743270be4080d248a4ca8cc --- manifests/api.pp | 3 ++- manifests/api/db.pp | 4 ++-- manifests/config.pp | 12 ++++++------ manifests/db/mysql.pp | 2 +- manifests/policy.pp | 2 +- manifests/registry.pp | 3 ++- manifests/registry/db.pp | 4 ++-- spec/classes/glance_api_spec.rb | 2 +- spec/classes/glance_registry_spec.rb | 2 +- 9 files changed, 18 insertions(+), 16 deletions(-) diff --git a/manifests/api.pp b/manifests/api.pp index 076852be..70f7f43d 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -521,7 +521,8 @@ class glance::api( # Set the pipeline, it is allowed to be blank if $pipeline != '' { - validate_re($pipeline, '^(\w+([+]\w+)*)*$') + validate_legacy(Pattern[/^(\w+([+]\w+)*)*$/], 'validate_re', $pipeline, ['^(\w+([+]\w+)*)*$']) + glance_api_config { 'paste_deploy/flavor': ensure => present, diff --git a/manifests/api/db.pp b/manifests/api/db.pp index 70022ad1..17341cd4 100644 --- a/manifests/api/db.pp +++ b/manifests/api/db.pp @@ -66,8 +66,8 @@ class glance::api::db ( $database_retry_interval_real = pick($::glance::api::database_retry_interval, $database_retry_interval) $database_max_overflow_real = pick($::glance::api::database_max_overflow, $database_max_overflow) - validate_re($database_connection_real, - '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') + validate_legacy(Oslo::Dbconn, 'validate_re', $database_connection_real, + ['^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?']) oslo::db { 'glance_api_config': db_max_retries => $database_db_max_retries, diff --git a/manifests/config.pp b/manifests/config.pp index 6771a032..c64bfbe6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -49,12 +49,12 @@ class glance::config ( include ::glance::deps - validate_hash($api_config) - validate_hash($api_paste_ini_config) - validate_hash($registry_config) - validate_hash($registry_paste_ini_config) - validate_hash($cache_config) - validate_hash($image_import_config) + validate_legacy(Hash, 'validate_hash', $api_config) + validate_legacy(Hash, 'validate_hash', $api_paste_ini_config) + validate_legacy(Hash, 'validate_hash', $registry_config) + validate_legacy(Hash, 'validate_hash', $registry_paste_ini_config) + validate_legacy(Hash, 'validate_hash', $cache_config) + validate_legacy(Hash, 'validate_hash', $image_import_config) create_resources('glance_api_config', $api_config) create_resources('glance_api_paste_ini', $api_paste_ini_config) diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 9267e78c..48953a1c 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -42,7 +42,7 @@ class glance::db::mysql( include ::glance::deps - validate_string($password) + validate_legacy(String, 'validate_string', $password) ::openstacklib::db::mysql { 'glance': user => $user, diff --git a/manifests/policy.pp b/manifests/policy.pp index ad207c11..44765dba 100644 --- a/manifests/policy.pp +++ b/manifests/policy.pp @@ -31,7 +31,7 @@ class glance::policy ( include ::glance::deps include ::glance::params - validate_hash($policies) + validate_legacy(Hash, 'validate_hash', $policies) Openstacklib::Policy::Base { file_path => $policy_path, diff --git a/manifests/registry.pp b/manifests/registry.pp index 92fd53c3..100e1db9 100644 --- a/manifests/registry.pp +++ b/manifests/registry.pp @@ -146,7 +146,8 @@ class glance::registry( # Set the pipeline, it is allowed to be blank if $pipeline != '' { - validate_re($pipeline, '^(\w+([+]\w+)*)*$') + validate_legacy(Pattern[/^(\w+([+]\w+)*)*$/], 'validate_re', $pipeline, ['^(\w+([+]\w+)*)*$']) + glance_registry_config { 'paste_deploy/flavor': ensure => present, diff --git a/manifests/registry/db.pp b/manifests/registry/db.pp index cc18d000..262810ed 100644 --- a/manifests/registry/db.pp +++ b/manifests/registry/db.pp @@ -66,8 +66,8 @@ class glance::registry::db ( $database_retry_interval_real = pick($::glance::registry::database_retry_interval, $database_retry_interval) $database_max_overflow_real = pick($::glance::registry::database_max_overflow, $database_max_overflow) - validate_re($database_connection_real, - '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') + validate_legacy(Oslo::Dbconn, 'validate_re', $database_connection_real, + ['^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?']) oslo::db { 'glance_registry_config': db_max_retries => $database_db_max_retries, diff --git a/spec/classes/glance_api_spec.rb b/spec/classes/glance_api_spec.rb index 49f94bfa..30531e08 100644 --- a/spec/classes/glance_api_spec.rb +++ b/spec/classes/glance_api_spec.rb @@ -274,7 +274,7 @@ describe 'glance::api' do end it { expect { is_expected.to contain_glance_api_config('filter:paste_deploy/flavor') }.to\ - raise_error(Puppet::Error, /validate_re\(\): .* does not match/) } + raise_error(Puppet::Error) } end end diff --git a/spec/classes/glance_registry_spec.rb b/spec/classes/glance_registry_spec.rb index 1208ac9d..3e4aeb21 100644 --- a/spec/classes/glance_registry_spec.rb +++ b/spec/classes/glance_registry_spec.rb @@ -150,7 +150,7 @@ describe 'glance::registry' do end it { expect { is_expected.to contain_glance_registry_config('filter:paste_deploy/flavor') }.to\ - raise_error(Puppet::Error, /validate_re\(\): .* does not match/) } + raise_error(Puppet::Error) } end end