summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Brown <cb@opscode.com>2010-02-25 16:15:33 -0800
committerChristopher Brown <cb@opscode.com>2010-02-25 16:15:33 -0800
commit794611d39a2b9d7fa69a8676d6b974d9daa399f2 (patch)
tree7dd44eda42c4ba02d78e6a503d4fcb29f0dbc7fc
parenta5a32309308c6e6fcc141a0fe97a86e87db6716e (diff)
downloadchef-794611d39a2b9d7fa69a8676d6b974d9daa399f2.tar.gz
retry on 500 from client create
-rw-r--r--chef/lib/chef/config.rb1
-rw-r--r--chef/lib/chef/rest.rb35
2 files changed, 20 insertions, 16 deletions
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb
index 00890f5d66..46e416ae33 100644
--- a/chef/lib/chef/config.rb
+++ b/chef/lib/chef/config.rb
@@ -100,6 +100,7 @@ class Chef
authorized_openid_identifiers nil
authorized_openid_providers nil
+ client_registration_retries 5
cookbook_path [ "/var/chef/cookbooks", "/var/chef/site-cookbooks" ]
cookbook_tarball_path "/var/chef/cookbook-tarballs"
couchdb_database "chef"
diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb
index fab49e32a5..fb18022456 100644
--- a/chef/lib/chef/rest.rb
+++ b/chef/lib/chef/rest.rb
@@ -66,26 +66,29 @@ class Chef
# Register the client
def register(name=Chef::Config[:node_name], destination=Chef::Config[:client_key])
-
- if File.exists?(destination)
- raise Chef::Exceptions::CannotWritePrivateKey, "I cannot write your private key to #{destination} - check permissions?" unless File.writable?(destination)
- end
+ raise Chef::Exceptions::CannotWritePrivateKey, "I cannot write your private key to #{destination} - check permissions?" if (File.exists?(destination) && !File.writable?(destination))
nc = Chef::ApiClient.new
nc.name(name)
- response = nc.save(true, true)
-
- Chef::Log.debug("Registration response: #{response.inspect}")
-
- raise Chef::Exceptions::CannotWritePrivateKey, "The response from the server did not include a private key!" unless response.has_key?("private_key")
- begin
- # Write out the private key
- file = File.open(destination, "w")
- file.print(response["private_key"])
- file.close
- rescue
- raise Chef::Exceptions::CannotWritePrivateKey, "I cannot write your private key to #{destination}"
+ catch(:done) do
+ retries = Chef::Config[:client_registration_retries] || 0
+ retries.downto(0) do
+ begin
+ response = nc.save(true, true)
+ Chef::Log.debug("Registration response: #{response.inspect}")
+ raise Chef::Exceptions::CannotWritePrivateKey, "The response from the server did not include a private key!" unless response.has_key?("private_key")
+ # Write out the private key
+ file = File.open(destination, "w")
+ file.print(response["private_key"])
+ file.close
+ throw :done
+ rescue IOError
+ raise Chef::Exceptions::CannotWritePrivateKey, "I cannot write your private key to #{destination}"
+ rescue NetHTTPServerException => e
+ end
+ end
+ raise Chef::Exceptions::CannotWritePrivateKey, "I failed to register the client, therefore no private key!"
end
true