From ee05a902463d3ee9b0dd9c7547da4bae7a11061e Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 21 Nov 2022 13:55:47 +0900 Subject: [PATCH] Ensure consistent IPv6 address format This change ensures the shortened address representations are always used for ring devices to avoid broken idempotency caused by different representations (shortened[1] vs canonical[2]). [1] ::1 [2] 0000:0000:0000:0000:0000:0000:0000:0001 Closes-Bug: #1997313 Change-Id: I762f0780ba25536aa616482a49d59c7db69924d6 (cherry picked from commit 249f466f94441ae554478467949378d81b034f89) (cherry picked from commit 4b37f4c4df42c3069b502ee9f539fdb5d0d4c897) (cherry picked from commit 81f930723b694260558f396b077a6fec4f9223f1) (cherry picked from commit e4a28d280671ef2452b6a0857a505f0c8891fbc3) --- lib/puppet/provider/swift_ring_builder.rb | 2 +- lib/puppet/type/ring_account_device.rb | 15 ++++++++++++--- lib/puppet/type/ring_container_device.rb | 15 ++++++++++++--- lib/puppet/type/ring_object_device.rb | 19 ++++++++++++++++++- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/lib/puppet/provider/swift_ring_builder.rb b/lib/puppet/provider/swift_ring_builder.rb index 19be7488..fcddfbd9 100644 --- a/lib/puppet/provider/swift_ring_builder.rb +++ b/lib/puppet/provider/swift_ring_builder.rb @@ -11,7 +11,7 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider def address_string(address) ip = IPAddr.new(address) if ip.ipv6? - '[' + ip.to_s + ']' + '[' + ip.to_s + ']' else ip.to_s end diff --git a/lib/puppet/type/ring_account_device.rb b/lib/puppet/type/ring_account_device.rb index d27659c1..31f9f73c 100644 --- a/lib/puppet/type/ring_account_device.rb +++ b/lib/puppet/type/ring_account_device.rb @@ -11,12 +11,21 @@ Puppet::Type.newtype(:ring_account_device) do end # we have to have URI Scheme so we just add http:// and ignore it later uri = URI('http://' + value) - address = uri.host - port_device = uri.port if ['','/'].include?(uri.path) raise(Puppet::Error, "namevar should contain a device") end - IPAddr.new(address) + IPAddr.new(uri.host) + end + + munge do |value| + # we have to have URI Scheme so we just add http:// and ignore it later + uri = URI('http://' + value) + ip = IPAddr.new(uri.host) + if ip.ipv6? + value.gsub(uri.host, '[' + ip.to_s + ']') + else + value + end end end diff --git a/lib/puppet/type/ring_container_device.rb b/lib/puppet/type/ring_container_device.rb index e1b954cd..ab469d10 100644 --- a/lib/puppet/type/ring_container_device.rb +++ b/lib/puppet/type/ring_container_device.rb @@ -11,12 +11,21 @@ Puppet::Type.newtype(:ring_container_device) do end # we have to have URI Scheme so we just add http:// and ignore it later uri = URI('http://' + value) - address = uri.host - port_device = uri.port if ['','/'].include?(uri.path) raise(Puppet::Error, "namevar should contain a device") end - IPAddr.new(address) + IPAddr.new(uri.host) + end + + munge do |value| + # we have to have URI Scheme so we just add http:// and ignore it later + uri = URI('http://' + value) + ip = IPAddr.new(uri.host) + if ip.ipv6? + value.gsub(uri.host, '[' + ip.to_s + ']') + else + value + end end end diff --git a/lib/puppet/type/ring_object_device.rb b/lib/puppet/type/ring_object_device.rb index 1868c098..31d59cfe 100644 --- a/lib/puppet/type/ring_object_device.rb +++ b/lib/puppet/type/ring_object_device.rb @@ -14,12 +14,29 @@ Puppet::Type.newtype(:ring_object_device) do # we have to have URI Scheme so we just add http:// and ignore it later uri = URI('http://' + value) address = uri.host - port_device = uri.port if ['','/'].include?(uri.path) raise(Puppet::Error, "namevar should contain a device") end IPAddr.new(address) end + + munge do |value| + # If storage policy_index is specified first strip that off. + # Resource name is not required to start with a policy_index + if !value.split(/^\d+:/)[1].nil? + value_without_policy = value.split(/^\d+:/)[1] + else + value_without_policy = value + end + # we have to have URI Scheme so we just add http:// and ignore it later + uri = URI('http://' + value_without_policy) + ip = IPAddr.new(uri.host) + if ip.ipv6? + value.gsub(uri.host, '[' + ip.to_s + ']') + else + value + end + end end newproperty(:region)