From d1c23f0fb4f1dc2c703b18294d8938e3ca8f3d11 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Fri, 23 Jun 2023 14:19:22 +0900 Subject: [PATCH] replace validate_legacy with proper data types the validate_legacy function is marked for deprecation in v9.0.0 from puppetlabs-stdlib. This also adds a few strict validations to the db classes based on the validations implemented in the underlying resources. Change-Id: I9e809415a532a694a50492a5600863d7d3d18a20 --- manifests/db/mysql.pp | 33 ++++++++++++++----------------- manifests/db/mysql/host_access.pp | 23 +++++++++++---------- manifests/db/postgresql.pp | 12 +++++------ manifests/iscsid.pp | 8 +++----- manifests/messaging/rabbitmq.pp | 24 ++++++++++------------ manifests/policy.pp | 17 +++++++--------- manifests/policy/base.pp | 18 ++++++++--------- manifests/policy/default.pp | 13 ++++++------ manifests/policyrcd.pp | 4 +--- 9 files changed, 67 insertions(+), 85 deletions(-) diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 3cb9312d..9fdb18de 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -61,31 +61,28 @@ # string; optional; default to undef # define openstacklib::db::mysql ( - $password = undef, - $plugin = undef, - $dbname = $title, - $user = $title, - $host = '127.0.0.1', - $charset = 'utf8', - $collate = 'utf8_general_ci', - $allowed_hosts = [], - $privileges = 'ALL', - $create_user = true, - $create_grant = true, - $tls_options = ['NONE'], + Optional[String[1]] $password = undef, + Optional[String[1]] $plugin = undef, + String[1] $dbname = $title, + String[1] $user = $title, + String[1] $host = '127.0.0.1', + String[1] $charset = 'utf8', + String[1] $collate = 'utf8_general_ci', + Variant[String[1], Array[String[1]]] $allowed_hosts = [], + Variant[String[1], Array[String[1]]] $privileges = 'ALL', + Boolean $create_user = true, + Boolean $create_grant = true, + Variant[String[1], Array[String[1]]] $tls_options = ['NONE'], # DEPRECATED PARAMETER - $password_hash = undef, + Optional[String[1]] $password_hash = undef, ) { include mysql::server include mysql::client - validate_legacy(Boolean, 'validate_bool', $create_user) - validate_legacy(Boolean, 'validate_bool', $create_grant) - if $password_hash != undef { - warning('The password_hash parameter was deprecated and will be removed -in a future release. Use password instead') + warning("The password_hash parameter was deprecated and will be removed \ +in a future release. Use password instead") $password_hash_real = $password_hash } elsif $password != undef { $password_hash_real = mysql::password($password) diff --git a/manifests/db/mysql/host_access.pp b/manifests/db/mysql/host_access.pp index a6689be0..b2ea87db 100644 --- a/manifests/db/mysql/host_access.pp +++ b/manifests/db/mysql/host_access.pp @@ -36,20 +36,19 @@ # Defaults to ['NONE'] # define openstacklib::db::mysql::host_access ( - $user, - $password_hash, - $database, - $privileges, - $plugin = undef, - $create_user = true, - $create_grant = true, - $tls_options = ['NONE'], + String[1] $user, + String[1] $password_hash, + String[1] $database, + Variant[String[1], Array[String[1]]] $privileges, + Optional[String[1]] $plugin = undef, + Boolean $create_user = true, + Boolean $create_grant = true, + Variant[String[1], Array[String[1]]] $tls_options = ['NONE'], ) { - validate_legacy(Pattern[/_/], 'validate_re', $title, - ['_', 'Title must be $dbname_$host']) - validate_legacy(Boolean, 'validate_bool', $create_user) - validate_legacy(Boolean, 'validate_bool', $create_grant) + if ! ($title =~ /_/) { + fail('Title must be $dbname_$host') + } $host = inline_template('<%= @title.split("_").last.downcase %>') diff --git a/manifests/db/postgresql.pp b/manifests/db/postgresql.pp index a7ddedf7..f6a43f3f 100644 --- a/manifests/db/postgresql.pp +++ b/manifests/db/postgresql.pp @@ -31,13 +31,13 @@ # string; required # define openstacklib::db::postgresql ( - $password = undef, - $dbname = $title, - $user = $title, - $encoding = undef, - $privileges = 'ALL', + Optional[String[1]] $password = undef, + String[1] $dbname = $title, + String[1] $user = $title, + Optional[String[1]] $encoding = undef, + Variant[String[1], Array[String[1]]] $privileges = 'ALL', # DEPRECATED PARAMETERS - $password_hash = undef, + Optional[String[1]] $password_hash = undef, ){ if $password_hash != undef { diff --git a/manifests/iscsid.pp b/manifests/iscsid.pp index 43ab55d1..6f6b7a0a 100644 --- a/manifests/iscsid.pp +++ b/manifests/iscsid.pp @@ -17,14 +17,12 @@ # Defaults to 'present' # class openstacklib::iscsid( - $enabled = true, - $manage_service = true, - $package_ensure = 'present' + Boolean $enabled = true, + Boolean $manage_service = true, + $package_ensure = 'present' ) { include openstacklib::params - validate_legacy(Boolean, 'validate_bool', $enabled) - validate_legacy(Boolean, 'validate_bool', $manage_service) package { 'open-iscsi': ensure => $package_ensure, diff --git a/manifests/messaging/rabbitmq.pp b/manifests/messaging/rabbitmq.pp index 05fc7dea..d8600032 100644 --- a/manifests/messaging/rabbitmq.pp +++ b/manifests/messaging/rabbitmq.pp @@ -62,21 +62,17 @@ # Defaults to true # define openstacklib::messaging::rabbitmq( - $userid = 'guest', - $password = 'guest', - $virtual_host = '/', - $is_admin = false, - $configure_permission = '.*', - $write_permission = '.*', - $read_permission = '.*', - $manage_user = true, - $manage_user_permissions = true, - $manage_vhost = true, + $userid = 'guest', + $password = 'guest', + $virtual_host = '/', + Boolean $is_admin = false, + $configure_permission = '.*', + $write_permission = '.*', + $read_permission = '.*', + Boolean $manage_user = true, + Boolean $manage_user_permissions = true, + Boolean $manage_vhost = true, ) { - validate_legacy(Boolean, 'validate_bool', $is_admin) - validate_legacy(Boolean, 'validate_bool', $manage_user) - validate_legacy(Boolean, 'validate_bool', $manage_user_permissions) - validate_legacy(Boolean, 'validate_bool', $manage_vhost) if $manage_user { if $userid == 'guest' { diff --git a/manifests/policy.pp b/manifests/policy.pp index 7b1f3e0f..a6b5b1f1 100644 --- a/manifests/policy.pp +++ b/manifests/policy.pp @@ -34,17 +34,14 @@ # Defaults to false. # define openstacklib::policy ( - $policy_path = $name, - $policies = {}, - $file_mode = '0640', - $file_user = undef, - $file_group = undef, - $file_format = 'json', - $purge_config = false, + Stdlib::Absolutepath $policy_path = $name, + Hash $policies = {}, + $file_mode = '0640', + $file_user = undef, + $file_group = undef, + Enum['json', 'yaml'] $file_format = 'json', + Boolean $purge_config = false, ) { - validate_legacy(Hash, 'validate_hash', $policies) - validate_legacy(Stdlib::Absolutepath, 'validate_absolute_path', $policy_path) - validate_legacy(Boolean, 'validate_bool', $purge_config) if empty($policies) { create_resources('openstacklib::policy::default', { $policy_path => { diff --git a/manifests/policy/base.pp b/manifests/policy/base.pp index f20909a7..a0d81230 100644 --- a/manifests/policy/base.pp +++ b/manifests/policy/base.pp @@ -37,18 +37,16 @@ # Defaults to false. # define openstacklib::policy::base ( - $file_path, - $key, - $value = '', - $file_mode = '0640', - $file_user = undef, - $file_group = undef, - $file_format = 'json', - $purge_config = false, + Stdlib::Absolutepath $file_path, + String[1] $key, + String $value = '', + $file_mode = '0640', + $file_user = undef, + $file_group = undef, + Enum['json', 'yaml'] $file_format = 'json', + Boolean $purge_config = false, ) { - validate_legacy(Boolean, 'validate_bool', $purge_config) - ensure_resource('openstacklib::policy::default', $file_path, { file_path => $file_path, file_mode => $file_mode, diff --git a/manifests/policy/default.pp b/manifests/policy/default.pp index 6a1abbfa..cd548c85 100644 --- a/manifests/policy/default.pp +++ b/manifests/policy/default.pp @@ -31,14 +31,13 @@ # Defaults to false. # define openstacklib::policy::default ( - $file_path = $name, - $file_mode = '0640', - $file_user = undef, - $file_group = undef, - $file_format = 'json', - $purge_config = false, + Stdlib::Absolutepath $file_path = $name, + $file_mode = '0640', + $file_user = undef, + $file_group = undef, + Enum['json', 'yaml'] $file_format = 'json', + Boolean $purge_config = false, ) { - validate_legacy(Boolean, 'validate_bool', $purge_config) case $file_format { 'json': { diff --git a/manifests/policyrcd.pp b/manifests/policyrcd.pp index 48be90df..4d554c24 100644 --- a/manifests/policyrcd.pp +++ b/manifests/policyrcd.pp @@ -22,11 +22,9 @@ # that should not autostart on install. # class openstacklib::policyrcd( - $services + Array[String[1]] $services ) { - validate_legacy(Array, 'validate_array', $services) - if $facts['os']['family'] == 'Debian' { # We put this out there so openstack services wont auto start # when installed.