From dcc8ca54ee1d0a19d68eff5cfacc14f40a46f2ab Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Thu, 11 Aug 2016 21:35:54 -0400 Subject: [PATCH] Add support for Swift Ring Builder 2.9.1+ This patch: https://review.openstack.org/#/c/319387 modified the output of rings, so we need to add the case where this regex is found and how to use it. Change-Id: Id9f1a478670e7b618ce9d222c5bc9739e3dd6286 --- lib/puppet/provider/swift_ring_builder.rb | 22 ++++++++++- .../provider/swift_ring_builder_spec.rb | 39 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/swift_ring_builder.rb b/lib/puppet/provider/swift_ring_builder.rb index e5eeb851..f6fa94bd 100644 --- a/lib/puppet/provider/swift_ring_builder.rb +++ b/lib/puppet/provider/swift_ring_builder.rb @@ -61,8 +61,28 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider # 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 2.9.1+ 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 2.9.1+ output example: + if row =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S+):(\d+)\s+\S+:\d+\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s*((-|\s-?)?\d+\.\d+)\s*(\S*)/ + address = address_string("#{$4}") + object_hash["#{address}:#{$5}/#{$6}"] = { + :id => $1, + :region => $2, + :zone => $3, + :weight => $7, + :partitions => $8, + :balance => $9, + :meta => $11 + } + # 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*)/ + elsif 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*)/ address = address_string("#{$4}") object_hash["#{address}:#{$5}/#{$6}"] = { diff --git a/spec/unit/puppet/provider/swift_ring_builder_spec.rb b/spec/unit/puppet/provider/swift_ring_builder_spec.rb index cad198e9..586357de 100644 --- a/spec/unit/puppet/provider/swift_ring_builder_spec.rb +++ b/spec/unit/puppet/provider/swift_ring_builder_spec.rb @@ -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.9.1+' do + File.expects(:exists?).with(builder_file_path).returns(true) + provider_class.expects(:builder_file_path).twice.returns(builder_file_path) + # Swift 2.9.1+ 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 2.2.2+' do File.expects(:exists?).with(builder_file_path).returns(true) provider_class.expects(:builder_file_path).twice.returns(builder_file_path)