Handle case where ring_builder has no rows
The code was not robust when no rows were returned from swift_ringbuilder(builder_file_path). The calls to retrieve an array range from the array of this commands output was returning nil which caused the failure: undef method each on nil This change explicitly checks for the case where there are no rows returned by swift-ring-builder.
This commit is contained in:
parent
1be67de6d4
commit
b6b13ce1b2
|
@ -15,19 +15,21 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
||||||
def self.lookup_ring
|
def self.lookup_ring
|
||||||
object_hash = {}
|
object_hash = {}
|
||||||
if File.exists?(builder_file_path)
|
if File.exists?(builder_file_path)
|
||||||
swift_ring_builder(builder_file_path).split("\n")[4..-1].each do |row|
|
if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1]
|
||||||
if row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/
|
rows.each do |row|
|
||||||
object_hash["#{$3}:#{$4}"] = {
|
if row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/
|
||||||
:id => $1,
|
object_hash["#{$3}:#{$4}"] = {
|
||||||
:zone => $2,
|
:id => $1,
|
||||||
:device_name => $5,
|
:zone => $2,
|
||||||
:weight => $6,
|
:device_name => $5,
|
||||||
:partitions => $7,
|
:weight => $6,
|
||||||
:balance => $8,
|
:partitions => $7,
|
||||||
:meta => $9
|
:balance => $8,
|
||||||
}
|
:meta => $9
|
||||||
else
|
}
|
||||||
Puppet.warning("Unexpected line: #{row}")
|
else
|
||||||
|
Puppet.warning("Unexpected line: #{row}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue