summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-03-27 17:51:36 -0700
committerdanielsdeleo <dan@getchef.com>2015-04-01 13:35:01 -0700
commit8b42ac0374fb075fbcb21df73742e81e69d9bf6f (patch)
tree89866faf81354bab896ea964751b46b81458540e /lib
parent5581644c881e34f16d3f82d40636e88bb6a2ea97 (diff)
downloadchef-8b42ac0374fb075fbcb21df73742e81e69d9bf6f.tar.gz
Extract Chef Zero code out to chef zero, re-enable socket listening
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/http.rb2
-rw-r--r--lib/chef/local_mode.rb27
-rw-r--r--lib/chef/rest.rb30
3 files changed, 17 insertions, 42 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 0e0bc2988e..bfdc2b5e42 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -296,7 +296,7 @@ class Chef
http_attempts += 1
response, request, return_value = yield
# handle HTTP 50X Error
- if response.kind_of?(Net::HTTPServerError)
+ if response.kind_of?(Net::HTTPServerError) && !Chef::Config.local_mode
if http_retry_count - http_attempts + 1 > 0
sleep_time = 1 + (2 ** http_attempts) + rand(2 ** http_attempts)
Chef::Log.error("Server returned error #{response.code} for #{url}, retrying #{http_attempts}/#{http_retry_count} in #{sleep_time}s")
diff --git a/lib/chef/local_mode.rb b/lib/chef/local_mode.rb
index 13782ce3d8..c6c5685e3f 100644
--- a/lib/chef/local_mode.rb
+++ b/lib/chef/local_mode.rb
@@ -19,8 +19,6 @@ require 'chef/config'
class Chef
module LocalMode
- LOCAL_MODE_URL = "chefzero://localhost"
-
# Create a chef local server (if the configuration requires one) for the
# duration of the given block.
#
@@ -63,16 +61,16 @@ class Chef
server_options[:data_store] = data_store
server_options[:log_level] = Chef::Log.level
- # TODO: there needs to be an option to force Chef Zero to operate in socket-ful mode
- # server_options[:host] = Chef::Config.chef_zero.host
- # server_options[:port] = parse_port(Chef::Config.chef_zero.port)
- # @chef_zero_server = ChefZero::Server.new(server_options)
- # @chef_zero_server.start_background
+ server_options[:host] = Chef::Config.chef_zero.host
+ server_options[:port] = parse_port(Chef::Config.chef_zero.port)
+ @chef_zero_server = ChefZero::Server.new(server_options)
+
+ @chef_zero_server.start_background
- ChefZero::Socketless.instance.reset!(server_options)
+ local_mode_url = @chef_zero_server.local_mode_url
- Chef::Log.info("Started chef-zero at #{LOCAL_MODE_URL} with #{@chef_fs.fs_description}")
- Chef::Config.chef_server_url = LOCAL_MODE_URL
+ Chef::Log.info("Started chef-zero at #{local_mode_url} with #{@chef_fs.fs_description}")
+ Chef::Config.chef_server_url = local_mode_url
end
end
@@ -88,11 +86,10 @@ class Chef
# If chef_zero_server is non-nil, stop it and remove references to it.
def self.destroy_server_connectivity
- return nil
- # if @chef_zero_server
- # @chef_zero_server.stop
- # @chef_zero_server = nil
- # end
+ if @chef_zero_server
+ @chef_zero_server.stop
+ @chef_zero_server = nil
+ end
end
def self.parse_port(port)
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
index 2b1f2044c4..855608385d 100644
--- a/lib/chef/rest.rb
+++ b/lib/chef/rest.rb
@@ -38,29 +38,6 @@ require 'chef/exceptions'
require 'chef/platform/query_helpers'
require 'chef/http/remote_request_id'
-module ChefZero
- # TODO: this needs to wrap all the things in a mutex
- class Socketless
-
- include Singleton
-
- def initialize()
- reset!
- end
-
- def reset!(options={})
- @server = ChefZero::Server.new(options)
- # TODO: make this public or whatever we need to do so we don't need #send
- @app = @server.send(:app)
- end
-
- def request(rack_env)
- @app.call(rack_env)
- end
-
- end
-end
-
class Chef
class SocketlessChefZeroClient
@@ -149,7 +126,7 @@ class Chef
end
def port
- "no port"
+ @url.port
end
# request, response = client.request(method, url, body, headers) {|r| r.read_body }
@@ -162,11 +139,12 @@ class Chef
r["PATH_INFO"] = url.path
r["QUERY_STRING"] = url.query
r["SERVER_NAME"] = "localhost"
- r["SERVER_PORT"] = ""
+ r["SERVER_PORT"] = url.port
+ r["HTTP_HOST"] = "localhost:#{url.port}"
r["rack.url_scheme"] = "chefzero"
r["rack.input"] = StringIO.new(body_str)
- res = ChefZero::Socketless.instance.request(r)
+ res = ChefZero::SocketlessServerMap.request(port, r)
net_http_response = to_net_http(res[0], res[1], res[2])