From 2627f0444f33e3d71f160fd880458bdef86cd8d5 Mon Sep 17 00:00:00 2001 From: "Peter C. Norton" Date: Mon, 19 Dec 2011 15:19:49 -0500 Subject: [PATCH] When an AWS security group has the wrong case, recover and keep going. --- lib/cluster_chef/security_group.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/cluster_chef/security_group.rb b/lib/cluster_chef/security_group.rb index bbee34fa..e85d5be3 100644 --- a/lib/cluster_chef/security_group.rb +++ b/lib/cluster_chef/security_group.rb @@ -39,8 +39,30 @@ def self.get_or_create group_name, description group = all[group_name] || ClusterChef.fog_connection.security_groups.get(group_name) if ! group self.step(group_name, "creating (#{description})", :blue) - group = all[group_name] = ClusterChef.fog_connection.security_groups.new(:name => group_name, :description => description, :connection => ClusterChef.fog_connection) - group.save + begin + group = ClusterChef.fog_connection.security_groups.new(:name => group_name, :description => description, :connection => ClusterChef.fog_connection) + group.save + rescue Fog::Service::Error => fog_err + # I'm worried that in the future other exception types may be + # returned by the group.save() call, however at this time + # the only error returned by + # Fog::AWS::Compute::Real::create_security_group.rb currently + # (fog 0.8.2) is the call to + # Fog::AWS::Compute::Error.new("InvalidGroup.Duplicate => The security group '#{name}' already exists") + # So I'm going to just accomodate the case where Fog::Service::Error is + # due to the prior existence of the group. + ClusterChef.fog_connection.security_groups.all().each do |g| + if g.name.downcase == group_name.downcase then + self.step(group_name, "group_name isn't matching in a case-sensitive manner. Use #{g.name} instead") + group = g + break + end + end + if not group then + raise fog_err + end + end + all[group_name] = group end group end