Allow multiple devices per endpoint.
Previously, the Puppet modules only supported a single device per endpoint. This commits allows multiple devices per endpoint by making the device name a part of the namevar for the swift ring devices. it also updates the relevent configs.
This commit is contained in:
parent
b428438460
commit
09f726c363
examples
lib/puppet
provider
type
spec
@ -163,22 +163,19 @@ class role_swift_storage inherits role_swift {
|
|||||||
# these exported resources write ring config
|
# these exported resources write ring config
|
||||||
# resources into the database so that they can be
|
# resources into the database so that they can be
|
||||||
# consumed by the ringbuilder role
|
# consumed by the ringbuilder role
|
||||||
@@ring_object_device { "${swift_local_net_ip}:6000":
|
@@ring_object_device { "${swift_local_net_ip}:6000/1":
|
||||||
zone => $swift_zone,
|
zone => $swift_zone,
|
||||||
device_name => 1,
|
|
||||||
weight => 1,
|
weight => 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ring_container_device { "${swift_local_net_ip}:6001":
|
@@ring_container_device { "${swift_local_net_ip}:6001/1":
|
||||||
zone => $swift_zone,
|
zone => $swift_zone,
|
||||||
device_name => 1,
|
|
||||||
weight => 1,
|
weight => 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO should device be changed to volume
|
# TODO should device be changed to volume
|
||||||
@@ring_account_device { "${swift_local_net_ip}:6002":
|
@@ring_account_device { "${swift_local_net_ip}:6002/1":
|
||||||
zone => $swift_zone,
|
zone => $swift_zone,
|
||||||
device_name => 1,
|
|
||||||
weight => 1,
|
weight => 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,10 +15,9 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
|||||||
if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1]
|
if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1]
|
||||||
rows.each do |row|
|
rows.each do |row|
|
||||||
if row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/
|
if 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}"] = {
|
object_hash["#{$3}:#{$4}/#{$5}"] = {
|
||||||
:id => $1,
|
:id => $1,
|
||||||
:zone => $2,
|
:zone => $2,
|
||||||
:device_name => $5,
|
|
||||||
:weight => $6,
|
:weight => $6,
|
||||||
:partitions => $7,
|
:partitions => $7,
|
||||||
:balance => $8,
|
:balance => $8,
|
||||||
@ -46,13 +45,13 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
[:zone, :device_name, :weight].each do |param|
|
[:zone, :weight].each do |param|
|
||||||
raise(Puppet::Error, "#{param} is required") unless resource[param]
|
raise(Puppet::Error, "#{param} is required") unless resource[param]
|
||||||
end
|
end
|
||||||
swift_ring_builder(
|
swift_ring_builder(
|
||||||
builder_file_path,
|
builder_file_path,
|
||||||
'add',
|
'add',
|
||||||
"z#{resource[:zone]}-#{resource[:name]}/#{resource[:device_name]}",
|
"z#{resource[:zone]}-#{resource[:name]}",
|
||||||
resource[:weight]
|
resource[:weight]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -74,14 +73,6 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
|||||||
Puppet.warning('Setting zone is not yet supported, I am not even sure if it is supported')
|
Puppet.warning('Setting zone is not yet supported, I am not even sure if it is supported')
|
||||||
end
|
end
|
||||||
|
|
||||||
def device_name
|
|
||||||
ring[resource[:name]][:device_name]
|
|
||||||
end
|
|
||||||
|
|
||||||
def device_name=(name)
|
|
||||||
Puppet.warning('I think it makes sense to set the name, it is just not yet supported')
|
|
||||||
end
|
|
||||||
|
|
||||||
def weight
|
def weight
|
||||||
ring[resource[:name]][:weight]
|
ring[resource[:name]][:weight]
|
||||||
# get the weight
|
# get the weight
|
||||||
|
@ -6,15 +6,15 @@ Puppet::Type.newtype(:ring_account_device) do
|
|||||||
newparam(:name, :namevar => true) do
|
newparam(:name, :namevar => true) do
|
||||||
validate do |value|
|
validate do |value|
|
||||||
address = value.split(':')
|
address = value.split(':')
|
||||||
raise(Puppet::Error, "invalid name #{value}") unless address.size == 2
|
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])
|
IPAddr.new(address[0])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newproperty(:zone)
|
newproperty(:zone)
|
||||||
|
|
||||||
newproperty(:device_name)
|
|
||||||
|
|
||||||
newproperty(:weight) do
|
newproperty(:weight) do
|
||||||
munge do |value|
|
munge do |value|
|
||||||
"%.2f" % value
|
"%.2f" % value
|
||||||
|
@ -6,15 +6,15 @@ Puppet::Type.newtype(:ring_container_device) do
|
|||||||
newparam(:name, :namevar => true) do
|
newparam(:name, :namevar => true) do
|
||||||
validate do |value|
|
validate do |value|
|
||||||
address = value.split(':')
|
address = value.split(':')
|
||||||
raise(Puppet::Error, "invalid name #{value}") unless address.size == 2
|
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])
|
IPAddr.new(address[0])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newproperty(:zone)
|
newproperty(:zone)
|
||||||
|
|
||||||
newproperty(:device_name)
|
|
||||||
|
|
||||||
newproperty(:weight) do
|
newproperty(:weight) do
|
||||||
munge do |value|
|
munge do |value|
|
||||||
"%.2f" % value
|
"%.2f" % value
|
||||||
|
@ -6,15 +6,15 @@ Puppet::Type.newtype(:ring_object_device) do
|
|||||||
newparam(:name, :namevar => true) do
|
newparam(:name, :namevar => true) do
|
||||||
validate do |value|
|
validate do |value|
|
||||||
address = value.split(':')
|
address = value.split(':')
|
||||||
raise(Puppet::Error, "invalid name #{value}") unless address.size == 2
|
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])
|
IPAddr.new(address[0])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newproperty(:zone)
|
newproperty(:zone)
|
||||||
|
|
||||||
newproperty(:device_name)
|
|
||||||
|
|
||||||
newproperty(:weight) do
|
newproperty(:weight) do
|
||||||
munge do |value|
|
munge do |value|
|
||||||
"%.2f" % value
|
"%.2f" % value
|
||||||
|
@ -5,7 +5,8 @@ describe 'swift::ringbuilder' do
|
|||||||
{
|
{
|
||||||
:operatingsystem => 'Ubuntu',
|
:operatingsystem => 'Ubuntu',
|
||||||
:osfamily => 'Debian',
|
:osfamily => 'Debian',
|
||||||
:processorcount => 1
|
:processorcount => 1,
|
||||||
|
:concat_basedir => '/tmp/foo'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
describe 'when swift class is not included' do
|
describe 'when swift class is not included' do
|
||||||
@ -23,9 +24,11 @@ describe 'swift::ringbuilder' do
|
|||||||
class { 'ssh::server::install': }"
|
class { 'ssh::server::install': }"
|
||||||
end
|
end
|
||||||
|
|
||||||
it { should contain_swift__ringbuilder__rebalance('object') }
|
it 'should rebalance the ring for all ring types' do
|
||||||
it { should contain_swift__ringbuilder__rebalance('account') }
|
should contain_swift__ringbuilder__rebalance('object')
|
||||||
it { should contain_swift__ringbuilder__rebalance('container') }
|
should contain_swift__ringbuilder__rebalance('account')
|
||||||
|
should contain_swift__ringbuilder__rebalance('container')
|
||||||
|
end
|
||||||
|
|
||||||
describe 'with default parameters' do
|
describe 'with default parameters' do
|
||||||
['object', 'account', 'container'].each do |type|
|
['object', 'account', 'container'].each do |type|
|
||||||
@ -60,43 +63,42 @@ describe 'swift::ringbuilder' do
|
|||||||
'class { memcached: max_memory => 1}
|
'class { memcached: max_memory => 1}
|
||||||
class { swift: swift_hash_suffix => string }
|
class { swift: swift_hash_suffix => string }
|
||||||
class { "ssh::server::install": }
|
class { "ssh::server::install": }
|
||||||
ring_object_device { "127.0.0.1:6000":
|
ring_object_device { "127.0.0.1:6000/1":
|
||||||
zone => 1,
|
zone => 1,
|
||||||
device_name => 1,
|
|
||||||
weight => 1,
|
weight => 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
ring_container_device { "127.0.0.1:6001":
|
ring_container_device { "127.0.0.1:6001/1":
|
||||||
zone => 2,
|
zone => 2,
|
||||||
device_name => 1,
|
|
||||||
weight => 1,
|
weight => 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
ring_account_device { "127.0.0.1:6002":
|
ring_account_device { "127.0.0.1:6002/1":
|
||||||
zone => 3,
|
zone => 3,
|
||||||
device_name => 1,
|
|
||||||
weight => 1,
|
weight => 1,
|
||||||
}'
|
}'
|
||||||
end
|
end
|
||||||
|
|
||||||
it { should contain_swift__ringbuilder__create('object').with(
|
it 'should set up all of the correct dependencies' do
|
||||||
{:before => 'Ring_object_device[127.0.0.1:6000]'}
|
should contain_swift__ringbuilder__create('object').with(
|
||||||
)}
|
{:before => 'Ring_object_device[127.0.0.1:6000/1]'}
|
||||||
it { should contain_swift__ringbuilder__create('container').with(
|
)
|
||||||
{:before => 'Ring_container_device[127.0.0.1:6001]'}
|
should contain_swift__ringbuilder__create('container').with(
|
||||||
)}
|
{:before => 'Ring_container_device[127.0.0.1:6001/1]'}
|
||||||
it { should contain_swift__ringbuilder__create('account').with(
|
)
|
||||||
{:before => 'Ring_account_device[127.0.0.1:6002]'}
|
should contain_swift__ringbuilder__create('account').with(
|
||||||
)}
|
{:before => 'Ring_account_device[127.0.0.1:6002/1]'}
|
||||||
it { should contain_ring_object_device('127.0.0.1:6000').with(
|
)
|
||||||
|
should contain_ring_object_device('127.0.0.1:6000/1').with(
|
||||||
{:notify => 'Swift::Ringbuilder::Rebalance[object]'}
|
{:notify => 'Swift::Ringbuilder::Rebalance[object]'}
|
||||||
)}
|
)
|
||||||
it { should contain_ring_container_device('127.0.0.1:6001').with(
|
should contain_ring_container_device('127.0.0.1:6001/1').with(
|
||||||
{:notify => 'Swift::Ringbuilder::Rebalance[container]'}
|
{:notify => 'Swift::Ringbuilder::Rebalance[container]'}
|
||||||
)}
|
)
|
||||||
it { should contain_ring_account_device('127.0.0.1:6002').with(
|
should contain_ring_account_device('127.0.0.1:6002/1').with(
|
||||||
{:notify => 'Swift::Ringbuilder::Rebalance[account]'}
|
{:notify => 'Swift::Ringbuilder::Rebalance[account]'}
|
||||||
)}
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,8 @@ describe 'swift::storage::all' do
|
|||||||
{
|
{
|
||||||
:concat_basedir => '/tmp/',
|
:concat_basedir => '/tmp/',
|
||||||
:operatingsystem => 'Ubuntu',
|
:operatingsystem => 'Ubuntu',
|
||||||
:osfamily => 'Debian'
|
:osfamily => 'Debian',
|
||||||
|
:concat_basedir => '/tmp/foo'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -113,7 +114,8 @@ describe 'swift::storage::all' do
|
|||||||
let :facts do
|
let :facts do
|
||||||
{
|
{
|
||||||
:operatingsystem => 'Debian',
|
:operatingsystem => 'Debian',
|
||||||
:osfamily => 'Debian'
|
:osfamily => 'Debian',
|
||||||
|
:concat_basedir => '/tmp/foo'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
33
spec/unit/puppet/provider/swift_ring_builder_spec.rb
Normal file
33
spec/unit/puppet/provider/swift_ring_builder_spec.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
require 'puppet'
|
||||||
|
require 'mocha'
|
||||||
|
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'puppet', 'provider', 'swift_ring_builder')
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.mock_with :mocha
|
||||||
|
end
|
||||||
|
provider_class = Puppet::Provider::SwiftRingBuilder
|
||||||
|
describe provider_class do
|
||||||
|
|
||||||
|
let :builder_file_path do
|
||||||
|
'/etc/swift/account.builder'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to lookup the local ring and build an object' do
|
||||||
|
File.expects(:exists?).with(builder_file_path).returns(true)
|
||||||
|
provider_class.expects(:builder_file_path).twice.returns(builder_file_path)
|
||||||
|
provider_class.expects(:swift_ring_builder).returns(
|
||||||
|
'/etc/swift/account.builder, build version 3
|
||||||
|
262144 partitions, 3 replicas, 3 zones, 3 devices, 0.00 balance
|
||||||
|
The minimum number of hours before a partition can be reassigned is 1
|
||||||
|
Devices: id zone ip address port name weight partitions balance meta
|
||||||
|
2 2 192.168.101.14 6002 1 1.00 262144 0.00
|
||||||
|
0 3 192.168.101.15 6002 1 1.00 262144 0.00
|
||||||
|
1 1 192.168.101.13 6002 1 1.00 262144 0.00
|
||||||
|
|
||||||
|
'
|
||||||
|
)
|
||||||
|
resources = provider_class.lookup_ring.inspect
|
||||||
|
resources['192.168.101.15:6002/1'].should_not be_nil
|
||||||
|
resources['192.168.101.13:6002/1'].should_not be_nil
|
||||||
|
resources['192.168.101.14:6002/1'].should_not be_nil
|
||||||
|
end
|
||||||
|
end
|
15
spec/unit/puppet/type/ring_account_device_spec.rb
Normal file
15
spec/unit/puppet/type/ring_account_device_spec.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
require 'puppet'
|
||||||
|
describe Puppet::Type.type(:ring_account_device) do
|
||||||
|
|
||||||
|
it 'should fail if the name has no ":"' do
|
||||||
|
expect do
|
||||||
|
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
|
||||||
|
end.should raise_error(Puppet::Error, /should contain address:port\/device/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail if the name does not contain a "/"' do
|
||||||
|
expect do
|
||||||
|
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
|
||||||
|
end.should raise_error(Puppet::Error, /should contain a device/)
|
||||||
|
end
|
||||||
|
end
|
16
spec/unit/puppet/type/ring_container_device_spec.rb
Normal file
16
spec/unit/puppet/type/ring_container_device_spec.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
require 'puppet'
|
||||||
|
describe Puppet::Type.type(:ring_container_device) do
|
||||||
|
|
||||||
|
it 'should fail if the name has no ":"' do
|
||||||
|
expect do
|
||||||
|
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
|
||||||
|
end.should raise_error(Puppet::Error, /should contain address:port\/device/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail if the name does not contain a "/"' do
|
||||||
|
expect do
|
||||||
|
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
|
||||||
|
end.should raise_error(Puppet::Error, /should contain a device/)
|
||||||
|
end
|
||||||
|
end
|
15
spec/unit/puppet/type/ring_object_device_spec.rb
Normal file
15
spec/unit/puppet/type/ring_object_device_spec.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
require 'puppet'
|
||||||
|
describe Puppet::Type.type(:ring_object_device) do
|
||||||
|
|
||||||
|
it 'should fail if the name has no ":"' do
|
||||||
|
expect do
|
||||||
|
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
|
||||||
|
end.should raise_error(Puppet::Error, /should contain address:port\/device/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail if the name does not contain a "/"' do
|
||||||
|
expect do
|
||||||
|
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
|
||||||
|
end.should raise_error(Puppet::Error, /should contain a device/)
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user