diff options
author | Christopher Brown <cb@opscode.com> | 2010-02-26 21:24:36 -0800 |
---|---|---|
committer | Christopher Brown <cb@opscode.com> | 2010-02-26 21:24:36 -0800 |
commit | 727a097ee6bb3639daca1052d9fbd299c885a6b3 (patch) | |
tree | 04db98d82cf833ecc287cb3c168ac640f5cb8a4b | |
parent | 9f94b3f92e15efd3742d621a230f23315a07f401 (diff) | |
parent | 794611d39a2b9d7fa69a8676d6b974d9daa399f2 (diff) | |
download | chef-727a097ee6bb3639daca1052d9fbd299c885a6b3.tar.gz |
PL-433 retry on 500 concurrency fixes
-rw-r--r-- | chef/lib/chef/config.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/rest.rb | 35 |
2 files changed, 20 insertions, 16 deletions
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb index 5365518713..9e72b7ba15 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 c491e7a3c5..50b3f10074 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, File::WRONLY|File::EXCL|File::CREAT, 0600) - 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] || 5 + 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 Net::HTTPFatalError => e + raise unless e.response.code == "500" + end + end end true |