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 249f466f94)
This commit is contained in:
Takashi Kajinami 2022-11-21 13:55:47 +09:00
parent 2dd553497c
commit 4b37f4c4df
4 changed files with 43 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)