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
This commit is contained in:
Takashi Kajinami
2023-06-23 14:19:22 +09:00
parent a22990d4d5
commit d1c23f0fb4
9 changed files with 67 additions and 85 deletions

View File

@@ -61,31 +61,28 @@
# string; optional; default to undef # string; optional; default to undef
# #
define openstacklib::db::mysql ( define openstacklib::db::mysql (
$password = undef, Optional[String[1]] $password = undef,
$plugin = undef, Optional[String[1]] $plugin = undef,
$dbname = $title, String[1] $dbname = $title,
$user = $title, String[1] $user = $title,
$host = '127.0.0.1', String[1] $host = '127.0.0.1',
$charset = 'utf8', String[1] $charset = 'utf8',
$collate = 'utf8_general_ci', String[1] $collate = 'utf8_general_ci',
$allowed_hosts = [], Variant[String[1], Array[String[1]]] $allowed_hosts = [],
$privileges = 'ALL', Variant[String[1], Array[String[1]]] $privileges = 'ALL',
$create_user = true, Boolean $create_user = true,
$create_grant = true, Boolean $create_grant = true,
$tls_options = ['NONE'], Variant[String[1], Array[String[1]]] $tls_options = ['NONE'],
# DEPRECATED PARAMETER # DEPRECATED PARAMETER
$password_hash = undef, Optional[String[1]] $password_hash = undef,
) { ) {
include mysql::server include mysql::server
include mysql::client include mysql::client
validate_legacy(Boolean, 'validate_bool', $create_user)
validate_legacy(Boolean, 'validate_bool', $create_grant)
if $password_hash != undef { if $password_hash != undef {
warning('The password_hash parameter was deprecated and will be removed warning("The password_hash parameter was deprecated and will be removed \
in a future release. Use password instead') in a future release. Use password instead")
$password_hash_real = $password_hash $password_hash_real = $password_hash
} elsif $password != undef { } elsif $password != undef {
$password_hash_real = mysql::password($password) $password_hash_real = mysql::password($password)

View File

@@ -36,20 +36,19 @@
# Defaults to ['NONE'] # Defaults to ['NONE']
# #
define openstacklib::db::mysql::host_access ( define openstacklib::db::mysql::host_access (
$user, String[1] $user,
$password_hash, String[1] $password_hash,
$database, String[1] $database,
$privileges, Variant[String[1], Array[String[1]]] $privileges,
$plugin = undef, Optional[String[1]] $plugin = undef,
$create_user = true, Boolean $create_user = true,
$create_grant = true, Boolean $create_grant = true,
$tls_options = ['NONE'], Variant[String[1], Array[String[1]]] $tls_options = ['NONE'],
) { ) {
validate_legacy(Pattern[/_/], 'validate_re', $title, if ! ($title =~ /_/) {
['_', 'Title must be $dbname_$host']) fail('Title must be $dbname_$host')
validate_legacy(Boolean, 'validate_bool', $create_user) }
validate_legacy(Boolean, 'validate_bool', $create_grant)
$host = inline_template('<%= @title.split("_").last.downcase %>') $host = inline_template('<%= @title.split("_").last.downcase %>')

View File

@@ -31,13 +31,13 @@
# string; required # string; required
# #
define openstacklib::db::postgresql ( define openstacklib::db::postgresql (
$password = undef, Optional[String[1]] $password = undef,
$dbname = $title, String[1] $dbname = $title,
$user = $title, String[1] $user = $title,
$encoding = undef, Optional[String[1]] $encoding = undef,
$privileges = 'ALL', Variant[String[1], Array[String[1]]] $privileges = 'ALL',
# DEPRECATED PARAMETERS # DEPRECATED PARAMETERS
$password_hash = undef, Optional[String[1]] $password_hash = undef,
){ ){
if $password_hash != undef { if $password_hash != undef {

View File

@@ -17,14 +17,12 @@
# Defaults to 'present' # Defaults to 'present'
# #
class openstacklib::iscsid( class openstacklib::iscsid(
$enabled = true, Boolean $enabled = true,
$manage_service = true, Boolean $manage_service = true,
$package_ensure = 'present' $package_ensure = 'present'
) { ) {
include openstacklib::params include openstacklib::params
validate_legacy(Boolean, 'validate_bool', $enabled)
validate_legacy(Boolean, 'validate_bool', $manage_service)
package { 'open-iscsi': package { 'open-iscsi':
ensure => $package_ensure, ensure => $package_ensure,

View File

@@ -62,21 +62,17 @@
# Defaults to true # Defaults to true
# #
define openstacklib::messaging::rabbitmq( define openstacklib::messaging::rabbitmq(
$userid = 'guest', $userid = 'guest',
$password = 'guest', $password = 'guest',
$virtual_host = '/', $virtual_host = '/',
$is_admin = false, Boolean $is_admin = false,
$configure_permission = '.*', $configure_permission = '.*',
$write_permission = '.*', $write_permission = '.*',
$read_permission = '.*', $read_permission = '.*',
$manage_user = true, Boolean $manage_user = true,
$manage_user_permissions = true, Boolean $manage_user_permissions = true,
$manage_vhost = 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 $manage_user {
if $userid == 'guest' { if $userid == 'guest' {

View File

@@ -34,17 +34,14 @@
# Defaults to false. # Defaults to false.
# #
define openstacklib::policy ( define openstacklib::policy (
$policy_path = $name, Stdlib::Absolutepath $policy_path = $name,
$policies = {}, Hash $policies = {},
$file_mode = '0640', $file_mode = '0640',
$file_user = undef, $file_user = undef,
$file_group = undef, $file_group = undef,
$file_format = 'json', Enum['json', 'yaml'] $file_format = 'json',
$purge_config = false, 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) { if empty($policies) {
create_resources('openstacklib::policy::default', { $policy_path => { create_resources('openstacklib::policy::default', { $policy_path => {

View File

@@ -37,18 +37,16 @@
# Defaults to false. # Defaults to false.
# #
define openstacklib::policy::base ( define openstacklib::policy::base (
$file_path, Stdlib::Absolutepath $file_path,
$key, String[1] $key,
$value = '', String $value = '',
$file_mode = '0640', $file_mode = '0640',
$file_user = undef, $file_user = undef,
$file_group = undef, $file_group = undef,
$file_format = 'json', Enum['json', 'yaml'] $file_format = 'json',
$purge_config = false, Boolean $purge_config = false,
) { ) {
validate_legacy(Boolean, 'validate_bool', $purge_config)
ensure_resource('openstacklib::policy::default', $file_path, { ensure_resource('openstacklib::policy::default', $file_path, {
file_path => $file_path, file_path => $file_path,
file_mode => $file_mode, file_mode => $file_mode,

View File

@@ -31,14 +31,13 @@
# Defaults to false. # Defaults to false.
# #
define openstacklib::policy::default ( define openstacklib::policy::default (
$file_path = $name, Stdlib::Absolutepath $file_path = $name,
$file_mode = '0640', $file_mode = '0640',
$file_user = undef, $file_user = undef,
$file_group = undef, $file_group = undef,
$file_format = 'json', Enum['json', 'yaml'] $file_format = 'json',
$purge_config = false, Boolean $purge_config = false,
) { ) {
validate_legacy(Boolean, 'validate_bool', $purge_config)
case $file_format { case $file_format {
'json': { 'json': {

View File

@@ -22,11 +22,9 @@
# that should not autostart on install. # that should not autostart on install.
# #
class openstacklib::policyrcd( class openstacklib::policyrcd(
$services Array[String[1]] $services
) { ) {
validate_legacy(Array, 'validate_array', $services)
if $facts['os']['family'] == 'Debian' { if $facts['os']['family'] == 'Debian' {
# We put this out there so openstack services wont auto start # We put this out there so openstack services wont auto start
# when installed. # when installed.