Fix ring data parser to allow for optional dispersion field

Swift was changed to add an option dispersion field to the output
of the swift-ring-builder command.  Also a line was added for the
overload factor, need to handle that as well.
Added a new spec for testing provider methods.

Change-Id: I1ae650e1514d69dc9c26b6054837f00fb4eb7bcb
Closes-Bug: #1444557
This commit is contained in:
Mark Vanderwiel 2015-04-15 12:59:24 -05:00
parent cf6dc4e57c
commit 4f778233cf
3 changed files with 58 additions and 1 deletions

View File

@ -195,6 +195,8 @@ def parse_ring_output(ring_data)
next
elsif line =~ /^Devices:\s+id\s+zone\s+/
next
elsif line =~ /\soverload factor\s/
next
elsif line =~ /^\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\.\d+\.\d+\.\d+)\s+(\d+)\s+(\d+\.\d+\.\d+\.\d+)\s+(\d+)\s+(\S+)\s+([0-9.]+)\s+(\d+)\s+([-0-9.]+)\s*$/
output[:hosts] ||= {}
output[:hosts][$4] ||= {}
@ -241,7 +243,7 @@ def parse_ring_output(ring_data)
output[:hosts][$3][$5][:weight] = $6
output[:hosts][$3][$5][:partitions] = $7
output[:hosts][$3][$5][:balance] = $8
elsif line =~ /(\d+) partitions, (\d+\.\d+) replicas, (\d+) regions, (\d+) zones, (\d+) devices, (\d+\.\d+) balance$/
elsif line =~ /(\d+) partitions, (\d+\.\d+) replicas, (\d+) regions, (\d+) zones, (\d+) devices, (\d+\.\d+) balance/
output[:state][:partitions] = $1
output[:state][:replicas] = $2
output[:state][:regions] = $3

55
spec/ring-script_spec.rb Normal file
View File

@ -0,0 +1,55 @@
# encoding: UTF-8
require_relative 'spec_helper'
describe 'openstack-object-storage::ring-repo' do
describe 'ubuntu' do
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
let(:node) { runner.node }
let(:chef_run) { runner.converge(described_recipe) }
let(:events) { Chef::EventDispatch::Dispatcher.new }
let(:cookbook_collection) { Chef::CookbookCollection.new([]) }
let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) }
describe 'ring_script' do
let(:resource) do
Chef::Resource::OpenstackObjectStorageRingScript.new('script1', run_context)
end
let(:provider) do
Chef::Provider::OpenstackObjectStorageRingScript.new(resource, run_context)
end
it 'parse_ring_output parses ring data for normal ring data' do
ring_data = ['/etc/swift/ring-workspace/rings/account.builder, build version 0',
'262144 partitions, 3.000000 replicas, 0 regions, 0 zones, 0 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)']
expect(
provider.send(:parse_ring_output, ring_data)
).to eq(
state:
{ build_version: '0',
partitions: '262144',
replicas: '3.000000',
regions: '0',
zones: '0',
devices: '0',
balance: '0.00',
min_part_hours: '1'
}
)
end
it 'parse_ring_output parsing fails for bad data' do
ring_data = ['ugly data']
exception = false
begin
provider.send(:parse_ring_output, ring_data)
rescue
exception = true
end
expect(exception).to be true
end
end
end
end

0
spec/setup_spec.rb Executable file → Normal file
View File