Fix ipv6 support
One shold never parse uri with split(':') as it was in types ring_account_device, ring_container_device and ring_object_device. This is fixed by using uri and just setting variables from that. Also swift_ring_builder didn't add brackets to ipv6 address before adding port information to it. Change-Id: I55b7032143c8446abeed4f6c266c0fff0cb6b3b3
This commit is contained in:
parent
7ad2a10e1f
commit
b6ba9f09b2
@ -8,6 +8,14 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
||||
end
|
||||
end
|
||||
|
||||
def self.address_string(address)
|
||||
ip = IPAddr.new(address)
|
||||
if ip.ipv6?
|
||||
'[' + ip.to_s + ']'
|
||||
else
|
||||
ip.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def self.lookup_ring
|
||||
object_hash = {}
|
||||
@ -30,7 +38,8 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
||||
# Swift 1.8+ output example:
|
||||
if row =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+\S+\s+\d+\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s*((-|\s-?)?\d+\.\d+)\s*(\S*)/
|
||||
|
||||
object_hash["#{$4}:#{$5}/#{$6}"] = {
|
||||
address = address_string("#{$4}")
|
||||
object_hash["#{address}:#{$5}/#{$6}"] = {
|
||||
:id => $1,
|
||||
:region => $2,
|
||||
:zone => $3,
|
||||
@ -43,7 +52,8 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
||||
# Swift 1.8.0 output example:
|
||||
elsif row =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s*((-|\s-?)?\d+\.\d+)\s*(\S*)/
|
||||
|
||||
object_hash["#{$4}:#{$5}/#{$6}"] = {
|
||||
address = address_string("#{$4}")
|
||||
object_hash["#{address}:#{$5}/#{$6}"] = {
|
||||
:id => $1,
|
||||
:region => $2,
|
||||
:zone => $3,
|
||||
@ -55,7 +65,8 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
||||
# This regex is for older swift versions
|
||||
elsif row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/
|
||||
|
||||
object_hash["#{$3}:#{$4}/#{$5}"] = {
|
||||
address = address_string("#{$3}")
|
||||
object_hash["#{address}:#{$4}/#{$5}"] = {
|
||||
:id => $1,
|
||||
:region => 'none',
|
||||
:zone => $2,
|
||||
|
@ -1,15 +1,19 @@
|
||||
Puppet::Type.newtype(:ring_account_device) do
|
||||
require 'ipaddr'
|
||||
require 'uri'
|
||||
|
||||
ensurable
|
||||
|
||||
newparam(:name, :namevar => true) do
|
||||
validate do |value|
|
||||
address = value.split(':')
|
||||
raise(Puppet::Error, "invalid name #{value}, should contain address:port/device") unless address.size == 2
|
||||
port_device = address[1].split('/')
|
||||
raise(Puppet::Error, "namevar should contain a device") unless port_device.size == 2
|
||||
IPAddr.new(address[0])
|
||||
# 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
|
||||
end
|
||||
|
||||
|
@ -1,15 +1,19 @@
|
||||
Puppet::Type.newtype(:ring_container_device) do
|
||||
require 'ipaddr'
|
||||
require 'uri'
|
||||
|
||||
ensurable
|
||||
|
||||
newparam(:name, :namevar => true) do
|
||||
validate do |value|
|
||||
address = value.split(':')
|
||||
raise(Puppet::Error, "invalid name #{value}, should contain address:port/device") unless address.size == 2
|
||||
port_device = address[1].split('/')
|
||||
raise(Puppet::Error, "namevar should contain a device") unless port_device.size == 2
|
||||
IPAddr.new(address[0])
|
||||
# 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
|
||||
end
|
||||
|
||||
|
@ -1,15 +1,19 @@
|
||||
Puppet::Type.newtype(:ring_object_device) do
|
||||
require 'ipaddr'
|
||||
require 'uri'
|
||||
|
||||
ensurable
|
||||
|
||||
newparam(:name, :namevar => true) do
|
||||
validate do |value|
|
||||
address = value.split(':')
|
||||
raise(Puppet::Error, "invalid name #{value}, should contain address:port/device") unless address.size == 2
|
||||
port_device = address[1].split('/')
|
||||
raise(Puppet::Error, "namevar should contain a device") unless port_device.size == 2
|
||||
IPAddr.new(address[0])
|
||||
# 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
|
||||
end
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
require 'puppet'
|
||||
describe Puppet::Type.type(:ring_account_device) do
|
||||
|
||||
it 'should fail if the name has no ":"' do
|
||||
it 'should fail if the name does not contain valid ipaddress' do
|
||||
expect {
|
||||
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
|
||||
}.to raise_error(Puppet::Error, /should contain address:port\/device/)
|
||||
Puppet::Type.type(:ring_account_device).new(:name => '192.168.1.256:80/a')
|
||||
}.to raise_error(Puppet::ResourceError, /invalid address/)
|
||||
end
|
||||
|
||||
it 'should fail if the name does not contain a "/"' do
|
||||
|
@ -1,16 +1,15 @@
|
||||
|
||||
require 'puppet'
|
||||
describe Puppet::Type.type(:ring_container_device) do
|
||||
|
||||
it 'should fail if the name has no ":"' do
|
||||
it 'should fail if the name does not contain valid ipaddress' do
|
||||
expect {
|
||||
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
|
||||
}.to raise_error(Puppet::Error, /should contain address:port\/device/)
|
||||
Puppet::Type.type(:ring_container_device).new(:name => '192.168.1.256:80/a')
|
||||
}.to raise_error(Puppet::ResourceError, /invalid address/)
|
||||
end
|
||||
|
||||
it 'should fail if the name does not contain a "/"' do
|
||||
expect {
|
||||
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
|
||||
Puppet::Type.type(:ring_container_device).new(:name => 'foo:80')
|
||||
}.to raise_error(Puppet::Error, /should contain a device/)
|
||||
end
|
||||
end
|
||||
|
@ -1,15 +1,14 @@
|
||||
require 'puppet'
|
||||
describe Puppet::Type.type(:ring_object_device) do
|
||||
|
||||
it 'should fail if the name has no ":"' do
|
||||
it 'should fail if the name does not contain valid ipaddress' do
|
||||
expect {
|
||||
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
|
||||
}.to raise_error(Puppet::Error, /should contain address:port\/device/)
|
||||
Puppet::Type.type(:ring_object_device).new(:name => '192.168.1.256:80/a')
|
||||
}.to raise_error(Puppet::ResourceError, /invalid address/)
|
||||
end
|
||||
|
||||
it 'should fail if the name does not contain a "/"' do
|
||||
expect {
|
||||
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
|
||||
Puppet::Type.type(:ring_object_device).new(:name => 'foo:80')
|
||||
}.to raise_error(Puppet::Error, /should contain a device/)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user