Fix swift-ring-builder for swift 1.8

In some case, there are no spaces before - of the balance in swift 1.8.
The change fix this.

/etc/swift/object.builder, build version 9
32768 partitions, 3.000000 replicas, 1 regions, 3 zones, 9 devices, 200.00 balance
The minimum number of hours before a partition can be reassigned is 24
Devices:    id  region  zone      ip address  port      name weight partitions balance meta
             0     1     1      10.68.0.45  6000       sdd 100.00      32768 200.00
             1     1     2      10.68.0.46  6000       sdd 100.00          0-100.00
...

Change-Id: Ic7757a22ce94e4d51ae11780d4626c90a9ed430f
This commit is contained in:
Mehdi Abaakouk 2013-04-29 10:32:42 +02:00
parent a8f84b5548
commit a9ec8e1c2d
2 changed files with 30 additions and 3 deletions

View File

@ -17,7 +17,12 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
# Swift 1.7+ output example:
# Devices: id region zone ip address port name weight partitions balance meta
# 0 1 2 127.0.0.1 6022 2 1.00 262144 0.00
if row =~ /^\s*(\d+)\s+\d+\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s*(\S*)/
# 0 1 3 192.168.101.15 6002 1 1.00 262144 -100.00
# Swift 1.8+ output example:
# Devices: id region zone ip address port name weight partitions balance meta
# 2 1 2 192.168.101.14 6002 1 1.00 262144 200.00 m2
# 0 1 3 192.168.101.15 6002 1 1.00 262144-100.00 m2
if 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["#{$3}:#{$4}/#{$5}"] = {
:id => $1,
@ -25,7 +30,7 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
:weight => $6,
:partitions => $7,
:balance => $8,
:meta => $9
:meta => $10
}
# 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*)$/

View File

@ -11,7 +11,29 @@ describe provider_class do
'/etc/swift/account.builder'
end
it 'should be able to lookup the local ring and build an object' do
it 'should be able to lookup the local ring and build an object 1.8' do
File.expects(:exists?).with(builder_file_path).returns(true)
provider_class.expects(:builder_file_path).twice.returns(builder_file_path)
# Swift 1.8 output
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 region zone ip address port name weight partitions balance meta
2 1 2 192.168.101.14 6002 1 1.00 262144 200.00 m2
0 1 3 192.168.101.15 6002 1 1.00 262144-100.00 m2
3 1 1 192.168.101.16 6002 1 1.00 262144-100.00
1 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
resources['192.168.101.16:6002/1'].should_not be_nil
end
it 'should be able to lookup the local ring and build an object 1.7' do
File.expects(:exists?).with(builder_file_path).returns(true)
provider_class.expects(:builder_file_path).twice.returns(builder_file_path)
# Swift 1.7 output