From c2aa24ac273f1b7addc900919153e382dc9ed30a Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Sat, 23 Feb 2019 12:44:16 +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: I6e75488ea8cfb5cb2be5fdb892355274ab18224b --- manifests/config.pp | 5 +++-- manifests/params.pp | 18 ++++++++++-------- manifests/virtualenv/agent_instance.pp | 9 ++++++--- manifests/virtualenv/instance.pp | 11 +++++++---- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 363e634..16f2d3a 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -31,8 +31,9 @@ class monasca::config ( $monasca_config = {}, $monasca_ini = {}, ) { - validate_hash($monasca_config) - validate_hash($monasca_ini) + + validate_legacy(Hash, 'validate_hash', $monasca_config) + validate_legacy(Hash, 'validate_hash', $monasca_ini) create_resources('monasca_config', $monasca_config) create_resources('monasca_ini', $monasca_ini) diff --git a/manifests/params.pp b/manifests/params.pp index e64aff6..cba2b94 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -93,15 +93,17 @@ class monasca::params( 'database_type' => 'influxdb', } ) { + include ::openstacklib::defaults - validate_string($admin_password) - validate_string($admin_project_name) - validate_string($user_password) - validate_string($agent_password) - validate_string($sql_password) - validate_string($sql_host) - validate_string($api_db_password) - validate_string($pers_db_password) + + validate_legacy(String, 'validate_string', $admin_password) + validate_legacy(String, 'validate_string', $admin_project_name) + validate_legacy(String, 'validate_string', $user_password) + validate_legacy(String, 'validate_string', $agent_password) + validate_legacy(String, 'validate_string', $sql_password) + validate_legacy(String, 'validate_string', $sql_host) + validate_legacy(String, 'validate_string', $api_db_password) + validate_legacy(String, 'validate_string', $pers_db_password) if $::osfamily == 'Debian' { $agent_package = 'monasca-agent' diff --git a/manifests/virtualenv/agent_instance.pp b/manifests/virtualenv/agent_instance.pp index 92f8e95..c048c39 100644 --- a/manifests/virtualenv/agent_instance.pp +++ b/manifests/virtualenv/agent_instance.pp @@ -36,13 +36,16 @@ define monasca::virtualenv::agent_instance( $venv_active = false, $venv_extra_args = undef, ) { - validate_string($ensure) + + validate_legacy(String, 'validate_string', $ensure) + $valid_values = [ '^present$', '^absent$', ] - validate_re($ensure, $valid_values, - "Unknown value '${ensure}' for ensure, must be present or absent") + + validate_legacy(Enum['present', 'absent'], 'validate_re', $ensure, + [$valid_values, "Unknown value '${ensure}' for ensure, must be present or absent"]) File[$basedir] -> anchor { 'monasca::virtualenv::instance': } Package<| name == 'python-virtualenv' |> -> Anchor['monasca::virtualenv::instance'] diff --git a/manifests/virtualenv/instance.pp b/manifests/virtualenv/instance.pp index aedaf09..767c774 100644 --- a/manifests/virtualenv/instance.pp +++ b/manifests/virtualenv/instance.pp @@ -58,20 +58,23 @@ define monasca::virtualenv::instance( $venv_active = false, $venv_extra_args = undef, ) { - validate_string($ensure) + + validate_legacy(String, 'validate_string', $ensure) + $valid_values = [ '^present$', '^absent$', ] - validate_re($ensure, $valid_values, - "Unknown value '${ensure}' for ensure, must be present or absent") + + validate_legacy(Enum['present', 'absent'], 'validate_re', $ensure, + [$valid_values, "Unknown value '${ensure}' for ensure, must be present or absent"]) $req_dest = "${basedir}/${venv_prefix}-requirements.txt" $venv_dir = "${basedir}/${venv_prefix}-venv" $venv_name = "${venv_prefix}-${name}" if $ensure == 'present' { - validate_string($venv_requirements) + validate_legacy(String, 'validate_string', $venv_requirements) file { $req_dest: ensure => 'file',