From ee4a9d48599bce332d0d7bdf4f8c0bbb6d9c6f2e Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 20 May 2013 15:37:45 -0400 Subject: [PATCH] Update swift_ring_builder to support replicator... Updates swift_ring_builder rebalancing parsing to support the latest upstream replicator_id and replicator_port changes. This correspondes with swift 1.8+ upstream development. Fixes LP Bug #1182197. Change-Id: Ibbaf75ca22cad95b22f9b5f03b547db8c47a9ea4 --- lib/puppet/provider/swift_ring_builder.rb | 22 +++++++++++++++-- .../provider/swift_ring_builder_spec.rb | 24 ++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/puppet/provider/swift_ring_builder.rb b/lib/puppet/provider/swift_ring_builder.rb index 91e96613..f4dbadb2 100644 --- a/lib/puppet/provider/swift_ring_builder.rb +++ b/lib/puppet/provider/swift_ring_builder.rb @@ -18,11 +18,29 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider # 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+ output example: + # + # Swift 1.8.0 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*)/ + # + # Swift 1.8+ output example: + # 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: + 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["#{$3}:#{$4}/#{$5}"] = { + :id => $1, + :zone => $2, + :weight => $6, + :partitions => $7, + :balance => $8, + :meta => $10 + } + + # 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["#{$3}:#{$4}/#{$5}"] = { :id => $1, diff --git a/spec/unit/puppet/provider/swift_ring_builder_spec.rb b/spec/unit/puppet/provider/swift_ring_builder_spec.rb index 8fa0adf1..ecb51592 100644 --- a/spec/unit/puppet/provider/swift_ring_builder_spec.rb +++ b/spec/unit/puppet/provider/swift_ring_builder_spec.rb @@ -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 1.8' 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 replication ip replication port name weight partitions balance meta + 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 + 1 1 1 192.168.101.13 6002 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.8.0' 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