Merge "Replace deprecated ip functions"

This commit is contained in:
Zuul 2021-08-16 22:44:20 +00:00 committed by Gerrit Code Review
commit 688a80c255
27 changed files with 29 additions and 70 deletions

View File

@ -1,29 +0,0 @@
require 'ipaddr'
# Custom function to verify if the parameter is a string representing an ip address
# or an array of strings representing an ip address
# Returns true if all elements are proper ip addresses and false otherwise
Puppet::Functions.create_function(:is_ip_addresses) do
dispatch :is_ip_addresses do
param 'Variant[Array, String, Undef]', :ip_addr
end
def is_ip_addresses(ip_addr)
if not ip_addr
return false
end
if ip_addr.class == String
ips = [ip_addr]
else
ips = ip_addr
end
ips.each do |ip|
begin
tmpip = IPAddr.new ip
rescue
return false
end
end
return true
end
end

View File

@ -72,18 +72,18 @@ define tripleo::pacemaker::haproxy_with_vip(
$ensure = true)
{
if($ensure) {
if !is_ip_addresses($ip_address) {
fail("Haproxy VIP: ${ip_address} is not a proper IP address.")
}
if is_ipv6_address($ip_address) {
if $ip_address =~ Stdlib::Compat::Ipv6 {
$netmask = '128'
$vip_nic = interface_for_ip($ip_address)
$ipv6_addrlabel = '99'
} else {
} elsif $ip_address =~ Stdlib::Compat::Ip_address {
$netmask = '32'
$vip_nic = ''
$ipv6_addrlabel = ''
} else {
fail("Haproxy VIP: ${ip_address} is not a proper IP address.")
}
if $nic != undef {
$nic_real = $nic
} else {

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::aodh::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::barbican::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::cinder::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -53,7 +53,7 @@ class tripleo::profile::base::database::mysql::client (
$step = Integer(hiera('step')),
) {
if $step >= 1 {
if is_ip_addresses($mysql_client_bind_address) {
if $mysql_client_bind_address =~ Stdlib::Compat::Ip_address {
$client_bind_changes = [
"set ${mysql_read_default_group}/bind-address '${mysql_client_bind_address}'"
]

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::designate::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::glance::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::gnocchi::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -153,7 +153,7 @@ class tripleo::profile::base::heat (
include heat::db
include heat::logging
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::heat::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -97,7 +97,7 @@ class tripleo::profile::base::horizon (
include tripleo::profile::base::apache
include apache::mod::remoteip
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$horizon_memcached_servers = prefix(any2array(normalize_ip_for_uri($memcached_hosts_real)), 'inet6:')
} else {
$horizon_memcached_servers = any2array(normalize_ip_for_uri($memcached_hosts_real))

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::ironic::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::ironic_inspector::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::manila::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::mistral::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::neutron::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -116,7 +116,7 @@ class tripleo::profile::base::nova (
$sync_db = false
}
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::nova::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::novajoin::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::octavia::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::placement::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -58,7 +58,7 @@ class tripleo::profile::base::zaqar::authtoken (
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
if $step >= 3 {
if is_ipv6_address($memcached_hosts_real[0]) {
if $memcached_hosts_real[0] =~ Stdlib::Compat::Ipv6 {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")

View File

@ -45,7 +45,7 @@ class tripleo::profile::pacemaker::ceph_nfs (
$ganesha_vip = hiera('ganesha_vip')
# NB: Until the IPaddr2 RA has a fix for https://bugzilla.redhat.com/show_bug.cgi?id=1445628
# we need to specify the nic when creating the ipv6 vip.
if is_ipv6_address($ganesha_vip) {
if $ganesha_vip =~ Stdlib::Compat::Ipv6 {
$netmask = '128'
$nic = interface_for_ip($ganesha_vip)
$ipv6_addrlabel = '99'

View File

@ -46,7 +46,7 @@ class tripleo::profile::pacemaker::clustercheck (
# configuration used by the galera resource agent,
# and by the clustercheck service when it is configured
# to listen via socat
if is_ipv6_address($bind_address) {
if $bind_address =~ Stdlib::Compat::Ipv6 {
$socat_listen_type = 'tcp6-listen'
} else {
$socat_listen_type = 'tcp4-listen'

View File

@ -321,7 +321,7 @@ monitor interval=${monitor_interval_slave}s role=Slave timeout=${dbs_timeout}s",
}
# We create a separate VIP by default now in OVN (since train)
if is_ipv6_address($ovn_dbs_vip) {
if $ovn_dbs_vip =~ Stdlib::Compat::Ipv6 {
$netmask = '128'
$vip_nic = interface_for_ip($ovn_dbs_vip)
$ipv6_addrlabel = '99'

View File

@ -1,12 +0,0 @@
require 'spec_helper'
require 'puppet'
describe 'is_ip_addresses' do
it { should run.with_params('192.168.2.1').and_return(true) }
it { should run.with_params('::1').and_return(true) }
it { should run.with_params('192.168.2.256').and_return(false) }
it { should run.with_params(['192.168.2.1']).and_return(true) }
it { should run.with_params(['192.168.2.1', '5a40:79cf:8251:5dc5:1624:3c03:3c04:9ba8', 'fe80::204:acff:fe17:bf38', '::1:2']).and_return(true) }
it { should run.with_params(['192.168.2.1', 'a.b.c.d']).and_return(false) }
it { should run.with_params(['c.d.d.e', 'a.b.c.d']).and_return(false) }
end