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:
@@ -15,7 +15,8 @@ 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]
|
||||||
|
rows.each do |row|
|
||||||
if row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/
|
if row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/
|
||||||
object_hash["#{$3}:#{$4}"] = {
|
object_hash["#{$3}:#{$4}"] = {
|
||||||
:id => $1,
|
:id => $1,
|
||||||
@@ -31,6 +32,7 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
object_hash
|
object_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user