From 68841e3727d1578d26a1ed16151bb0c6994eca69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Torbj=C3=B6rn=20L=C3=B6nnemark?= <tobbez@ryara.net>
Date: Mon, 16 Dec 2024 21:31:57 +0100
Subject: [PATCH] Replace use of removed validate_* functions

They have been removed from puppetlabs-stdlib.
---
 manifests/conf.pp               |   4 +-
 manifests/interface.pp          | 104 +++++++++-----------------------
 manifests/mroute.pp             |   5 +-
 manifests/mroute/validate_gw.pp |   2 +-
 manifests/route.pp              |  53 +++-------------
 manifests/rule.pp               |  11 +---
 6 files changed, 45 insertions(+), 134 deletions(-)

diff --git a/manifests/conf.pp b/manifests/conf.pp
index 35fb8d9..c72fdda 100644
--- a/manifests/conf.pp
+++ b/manifests/conf.pp
@@ -87,9 +87,7 @@ define network::conf (
 
   $options_hash = undef,
 
-  $ensure       = present ) {
-
-  validate_re($ensure, ['present','absent'], 'Valid values are: present, absent. WARNING: If set to absent the conf file is removed.')
+  Enum['present', 'absent'] $ensure       = present ) {
 
   include ::network
 
diff --git a/manifests/interface.pp b/manifests/interface.pp
index 2de043b..51d73d6 100644
--- a/manifests/interface.pp
+++ b/manifests/interface.pp
@@ -270,15 +270,15 @@
 #
 define network::interface (
 
-  $enable                = true,
-  $ensure                = 'present',
+  Boolean $enable                = true,
+  Enum['present', 'absent'] $ensure                = 'present',
   $template              = "network/interface/${::osfamily}.erb",
   $options               = undef,
   $options_extra_redhat  = undef,
   $options_extra_debian  = undef,
   $options_extra_suse    = undef,
   $interface             = $name,
-  $restart_all_nic = $::osfamily ? {
+  Boolean $restart_all_nic = $::osfamily ? {
     'RedHat' => $::operatingsystemmajrelease ? {
       '8'     => false,
       default => true,
@@ -302,7 +302,7 @@ define network::interface (
 
   ## Debian specific
   $manage_order          = '10',
-  $auto                  = true,
+  Boolean $auto                  = true,
   $allow_hotplug         = undef,
   $method                = '',
   $family                = 'inet',
@@ -348,19 +348,19 @@ define network::interface (
   $additional_networks   = [ ],
 
   # Common ifupdown scripts
-  $up                    = [ ],
-  $pre_up                = [ ],
-  $post_up               = [ ],
-  $down                  = [ ],
-  $pre_down              = [ ],
-  $post_down             = [ ],
+  Array $up                    = [ ],
+  Array $pre_up                = [ ],
+  Array $post_up               = [ ],
+  Array $down                  = [ ],
+  Array $pre_down              = [ ],
+  Array $post_down             = [ ],
 
   # For virtual routing and forwarding (VRF)
   $vrf                   = undef,
   $vrf_table             = undef,
 
   # For bonding
-  $slaves                = [ ],
+  Array $slaves                = [ ],
   $bond_mode             = undef,
   $bond_miimon           = undef,
   $bond_downdelay        = undef,
@@ -368,7 +368,7 @@ define network::interface (
   $bond_lacp_rate        = undef,
   $bond_master           = undef,
   $bond_primary          = undef,
-  $bond_slaves           = [ ],
+  Array $bond_slaves           = [ ],
   $bond_xmit_hash_policy = undef,
   $bond_num_grat_arp     = undef,
   $bond_arp_all          = undef,
@@ -385,7 +385,7 @@ define network::interface (
   $team_master           = undef,
 
   # For bridging
-  $bridge_ports          = [ ],
+  Array $bridge_ports          = [ ],
   $bridge_stp            = undef,
   $bridge_fd             = undef,
   $bridge_maxwait        = undef,
@@ -395,11 +395,11 @@ define network::interface (
   $wpa_ssid              = undef,
   $wpa_bssid             = undef,
   $wpa_psk               = undef,
-  $wpa_key_mgmt          = [ ],
-  $wpa_group             = [ ],
-  $wpa_pairwise          = [ ],
-  $wpa_auth_alg          = [ ],
-  $wpa_proto             = [ ],
+  Array $wpa_key_mgmt          = [ ],
+  Array $wpa_group             = [ ],
+  Array $wpa_pairwise          = [ ],
+  Array $wpa_auth_alg          = [ ],
+  Array $wpa_proto             = [ ],
   $wpa_identity          = undef,
   $wpa_password          = undef,
   $wpa_scan_ssid         = undef,
@@ -442,16 +442,16 @@ define network::interface (
   $vid                   = undef,
   $physdev               = undef,
   $bridge                = undef,
-  $arpcheck              = undef,
+  Optional[Enum['yes', 'no']] $arpcheck              = undef,
   $zone                  = undef,
-  $arp                   = undef,
-  $nozeroconf            = undef,
+  Optional[Enum['yes', 'no']] $arp                   = undef,
+  Optional[Enum['yes', 'no']] $nozeroconf            = undef,
   $linkdelay             = undef,
   $check_link_down       = false,
   $hotplug               = undef,
   $persistent_dhclient   = undef,
   $nm_name               = undef,
-  $iprule                = undef,
+  Optional[Array] $iprule                = undef,
 
   # RedHat specific for InfiniBand
   $connected_mode        = undef,
@@ -479,10 +479,10 @@ define network::interface (
   $ovsbootproto          = undef,
 
   # RedHat specific for zLinux
-  $subchannels           = undef,
-  $nettype               = undef,
-  $layer2                = undef,
-  $zlinux_options        = undef,
+  Optional[Array] $subchannels           = undef,
+  Optional[Enum['qeth', 'lcs', 'ctc']] $nettype               = undef,
+  Optional[Integer[0,1]] $layer2                = undef,
+  Optional[String] $zlinux_options        = undef,
 
   ## Suse specific
   $startmode             = '',
@@ -490,8 +490,8 @@ define network::interface (
   $firewall              = undef,
   $aliases               = undef,
   $remote_ipaddr         = undef,
-  $check_duplicate_ip    = undef,
-  $send_gratuitous_arp   = undef,
+  Optional[Enum['yes', 'no']] $check_duplicate_ip    = undef,
+  Optional[Enum['yes', 'no']] $send_gratuitous_arp   = undef,
   $pre_up_script         = undef,
   $post_up_script        = undef,
   $pre_down_script       = undef,
@@ -513,59 +513,15 @@ define network::interface (
 
   include ::network
 
-  validate_re($ensure, '^(present|absent)$', "Ensure can only be present or absent (to add or remove an interface). Current value: ${ensure}")
-  validate_bool($auto)
-  validate_bool($enable)
-  validate_bool($restart_all_nic)
-
-  validate_array($up)
-  validate_array($pre_up)
-  validate_array($down)
-  validate_array($pre_down)
-  validate_array($slaves)
-  validate_array($bond_slaves)
-  validate_array($bridge_ports)
-  validate_array($wpa_key_mgmt)
-  validate_array($wpa_group)
-  validate_array($wpa_pairwise)
-  validate_array($wpa_auth_alg)
-  validate_array($wpa_proto)
-
   # $subchannels is only valid for zLinux/SystemZ/s390x.
   if $::architecture == 's390x' {
-    validate_array($subchannels)
-    validate_re($nettype, '^(qeth|lcs|ctc)$', "${name}::\$nettype may be 'qeth', 'lcs' or 'ctc' only and is set to <${nettype}>.")
     # Different parameters required for RHEL6 and RHEL7
     if $::operatingsystemmajrelease =~ /^7|^8/ {
-      validate_string($zlinux_options)
+      assert_type(String, $zlinux_options)
     } else {
-      validate_re($layer2, '^0|1$', "${name}::\$layer2 must be 1 or 0 and is to <${layer2}>.")
-    }
-  }
-  if $::osfamily == 'RedHat' {
-    if $iprule != undef {
-      validate_array($iprule)
+      assert_type(Integer, $layer2)
     }
   }
-  if $arp != undef and ! ($arp in ['yes', 'no']) {
-    fail('arp must be one of: undef, yes, no')
-  }
-
-  if $arpcheck != undef and ! ($arpcheck in ['yes', 'no']) {
-    fail('arpcheck must be one of: undef, yes, no')
-  }
-
-  if $nozeroconf != undef and ! ($nozeroconf in ['yes', 'no']) {
-    fail('nozeroconf must be one of: undef, yes, no')
-  }
-
-  if $check_duplicate_ip != undef and ! ($check_duplicate_ip in ['yes', 'no']) {
-    fail('check_duplicate_ip must be one of: undef, yes, no')
-  }
-
-  if $send_gratuitous_arp != undef and ! ($send_gratuitous_arp in ['yes', 'no']) {
-    fail('send_gratuitous_arp must be one of: undef, yes, no')
-  }
 
   if $::osfamily != 'RedHat' and ($type == 'InfiniBand' or $connected_mode) {
     fail('InfiniBand parameters are supported only for RedHat family.')
diff --git a/manifests/mroute.pp b/manifests/mroute.pp
index 0796f94..6aa4c4f 100644
--- a/manifests/mroute.pp
+++ b/manifests/mroute.pp
@@ -72,7 +72,7 @@
 # Deploys the file /etc/sysconfig/network/ifroute-$name.
 #
 define network::mroute (
-  $routes,
+  Hash $routes,
   $interface           = $name,
   $config_file_notify  = 'class_default',
   $restart_all_nic     = false,
@@ -82,9 +82,6 @@ define network::mroute (
   $route_down_template = undef,
   $table               = undef,
 ) {
-  # Validate our arrays
-  validate_hash($routes)
-
   include ::network
   $real_reload_command = $reload_command ? {
     undef => $::operatingsystem ? {
diff --git a/manifests/mroute/validate_gw.pp b/manifests/mroute/validate_gw.pp
index a85794d..a370257 100644
--- a/manifests/mroute/validate_gw.pp
+++ b/manifests/mroute/validate_gw.pp
@@ -2,5 +2,5 @@
 #
 define network::mroute::validate_gw($routes) {
   $route = $routes[$name]
-  validate_string($route)
+  assert_type(String, $route)
 }
diff --git a/manifests/route.pp b/manifests/route.pp
index 8f86ad3..3860750 100644
--- a/manifests/route.pp
+++ b/manifests/route.pp
@@ -103,58 +103,25 @@
 # Copyright (C) 2011 Mike Arnold, unless otherwise noted.
 #
 define network::route (
-  $ipaddress,
-  $netmask,
-  $gateway   = undef,
-  $metric    = undef,
-  $mtu       = undef,
-  $scope     = undef,
-  $source    = undef,
-  $table     = undef,
-  $cidr      = undef,
-  $family    = [ 'inet4' ],
+  Array $ipaddress,
+  Array $netmask,
+  Optional[Array] $gateway   = undef,
+  Optional[Array] $metric    = undef,
+  Optional[Integer] $mtu       = undef,
+  Optional[Array] $scope     = undef,
+  Optional[Array] $source    = undef,
+  Optional[Array] $table     = undef,
+  Optional[Array] $cidr      = undef,
+  Optional[Array] $family    = [ 'inet4' ],
   $interface = $name,
   $ensure    = 'present'
 ) {
-  # Validate our arrays
-  validate_array($ipaddress)
-  validate_array($netmask)
-
-  if $gateway {
-    validate_array($gateway)
-  }
-
-  if $metric {
-    validate_array($metric)
-  }
-
-  if $mtu {
-    validate_integer($mtu)
-  }
-
-  if $scope {
-    validate_array($scope)
-  }
-
-  if $source {
-    validate_array($source)
-  }
-
-  if $table {
-    validate_array($table)
-  }
-
   if $cidr {
-    validate_array($cidr)
     $_cidr = $cidr
   } else {
     $_cidr = build_cidr_array($netmask)
   }
 
-  if $family {
-    validate_array($family)
-  }
-
   include ::network
 
   case $::osfamily {
diff --git a/manifests/rule.pp b/manifests/rule.pp
index 7637bb9..66bfcf7 100644
--- a/manifests/rule.pp
+++ b/manifests/rule.pp
@@ -26,18 +26,11 @@
 #
 
 define network::rule (
-  $iprule,
+  Array $iprule,
   $interface = $name,
-  $family    = [],
+  Array $family    = [],
   $ensure    = 'present'
 ) {
-  # Validate our arrays
-  validate_array($iprule)
-
-  if $family {
-    validate_array($family)
-  }
-
   include ::network
 
   case $::osfamily {
-- 
GitLab