diff options
author | Adam Jacob <adam@opscode.com> | 2010-02-27 16:44:23 -0800 |
---|---|---|
committer | Adam Jacob <adam@opscode.com> | 2010-02-27 16:44:23 -0800 |
commit | 5cf77981204b2159926aca8980d3b1a2826d21e3 (patch) | |
tree | aad88c9f47b8d349f695825a7d53f2bf9dfe8857 | |
parent | 8e295c26fdf0f0d03429dcca5736cb5e9148bebd (diff) | |
parent | ae9d419ab9ac4dfab4c2f72fa5296297fc3f58dc (diff) | |
download | chef-5cf77981204b2159926aca8980d3b1a2826d21e3.tar.gz |
Merge branch 'PL-433' of git://github.com/skeptomai/chef into skeptomai/PL-433
-rw-r--r-- | chef/lib/chef/config.rb | 3 | ||||
-rw-r--r-- | chef/lib/chef/rest.rb | 36 |
2 files changed, 22 insertions, 17 deletions
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb index 5365518713..d9b5fa3458 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" @@ -136,7 +137,7 @@ class Chef registration_url "http://localhost:4000" client_url "http://localhost:4042" remotefile_url "http://localhost:4000" - rest_timeout 60 + rest_timeout 300 run_command_stderr_timeout 120 run_command_stdout_timeout 120 search_url "http://localhost:4000" diff --git a/chef/lib/chef/rest.rb b/chef/lib/chef/rest.rb index c491e7a3c5..423cb43c7d 100644 --- a/chef/lib/chef/rest.rb +++ b/chef/lib/chef/rest.rb @@ -66,26 +66,30 @@ 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 + 0.upto(retries) do |n| + 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 + Chef::Log.warn("Failed attempt #{n} of #{retries+1} on client creation") + raise unless e.response.code == "500" + end + end end true |