swift-ring-builder 2.2.2+ output parse fix

Starting in swift 2.2.2 an extra line for overload is printed
by swift-ring-builder.
Check for this and skip that line to avoid avoid warning messages.

Change-Id: I2d81db0a29249101116c1899565f024aaac69000
Closes-Bug: #1524936
This commit is contained in:
Adam Vinsh 2015-12-10 13:45:42 -05:00
parent 67df8085d0
commit 1dfe3d29a9
2 changed files with 61 additions and 0 deletions

View File

@ -20,19 +20,41 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
def self.lookup_ring
object_hash = {}
if File.exists?(builder_file_path)
# Swift < 2.2.2 Skip first 4 info lines from swift-ring-builder output
if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1]
# Swift 2.2.2+ Skip additional line to account for Overload info
if !rows[0].nil? and rows[0].start_with?('Devices:')
rows.shift
end
rows.each do |row|
# Swift 1.7+ output example:
# /etc/swift/object.builder, build version 1
# 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion
# 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
# 0 1 2 127.0.0.1 6022 2 1.00 262144 0.00
# 0 1 3 192.168.101.15 6002 1 1.00 262144 -100.00
#
# Swift 1.8.0 output example:
# /etc/swift/object.builder, build version 1
# 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion
# 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
#
# Swift 1.8+ output example:
# /etc/swift/object.builder, build version 1
# 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion
# The minimum number of hours before a partition can be reassigned is 1
# Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
# 0 1 2 127.0.0.1 6021 127.0.0.1 6021 2 1.00 262144 0.00
#
# Swift 2.2.2+ output example:
# /etc/swift/object.builder, build version 1
# 262144 partitions, 1.000000 replicas, 1 regions, 1 zones, 1 devices, 0.00 balance, 0.00 dispersion
# The minimum number of hours before a partition can be reassigned is 1
# The overload factor is 0.00% (0.000000)
# Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
# 0 1 2 127.0.0.1 6021 127.0.0.1 6021 2 1.00 262144 0.00
# Swift 1.8+ output example:

View File

@ -11,6 +11,45 @@ describe provider_class do
'/etc/swift/account.builder'
end
it 'should be able to lookup the local ring and build an object 2.2.2+' 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
The overload factor is 0.00% (0.000000)
Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
1 1 1 192.168.101.13 6002 192.168.101.13 6002 1 1.00 262144 0.00
2 1 2 192.168.101.14 6002 192.168.101.14 6002 1 1.00 262144 200.00 m2
0 1 3 192.168.101.15 6002 192.168.101.15 6002 1 1.00 262144-100.00 m2
3 1 1 192.168.101.16 6002 192.168.101.16 6002 1 1.00 262144-100.00
'
)
resources = provider_class.lookup_ring
expect(resources['192.168.101.13:6002/1']).to_not be_nil
expect(resources['192.168.101.14:6002/1']).to_not be_nil
expect(resources['192.168.101.15:6002/1']).to_not be_nil
expect(resources['192.168.101.16:6002/1']).to_not be_nil
expect(resources['192.168.101.13:6002/1'][:id]).to eql '1'
expect(resources['192.168.101.13:6002/1'][:region]).to eql '1'
expect(resources['192.168.101.13:6002/1'][:zone]).to eql '1'
expect(resources['192.168.101.13:6002/1'][:weight]).to eql '1.00'
expect(resources['192.168.101.13:6002/1'][:partitions]).to eql '262144'
expect(resources['192.168.101.13:6002/1'][:balance]).to eql '0.00'
expect(resources['192.168.101.13:6002/1'][:meta]).to eql ''
expect(resources['192.168.101.14:6002/1'][:id]).to eql '2'
expect(resources['192.168.101.14:6002/1'][:region]).to eql '1'
expect(resources['192.168.101.14:6002/1'][:zone]).to eql '2'
expect(resources['192.168.101.14:6002/1'][:weight]).to eql '1.00'
expect(resources['192.168.101.14:6002/1'][:partitions]).to eql '262144'
expect(resources['192.168.101.14:6002/1'][:balance]).to eql '200.00'
expect(resources['192.168.101.14:6002/1'][:meta]).to eql 'm2'
end
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)