Skip to content

Commit

Permalink
Merge pull request puppetlabs#1915 from kylog/issue/stable/22535-new-…
Browse files Browse the repository at this point in the history
…agent-old-master-file-ignore-list-is-ignored

(#22535) Use a response header for version
  • Loading branch information
pcarlisle committed Sep 19, 2013
2 parents 34b5add + 70a18ef commit f0884b3
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 41 deletions.
18 changes: 0 additions & 18 deletions lib/puppet/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,9 @@ def run_in_fork(forking = true)

private

def check_master_version

prev_terminus = Puppet::Status.indirection.terminus_class
Puppet::Status.indirection.terminus_class = :rest
master_version = Puppet::Status.indirection.find('*').version
Puppet::Status.indirection.terminus_class = prev_terminus

if !master_version
Puppet.notice "Using less secure serialization of reports and query parameters for compatibility"
Puppet.notice "with older puppet master. To remove this notice, please upgrade your master(s) "
Puppet.notice "to Puppet 3.3 or newer."
Puppet.notice "See http://links.puppetlabs.com/deprecate_yaml_on_network for more information."
Puppet[:legacy_query_parameter_serialization] = true
Puppet[:report_serialization_format] = "yaml"
end
end

# Create and yield a client instance, keeping a reference
# to it during the yield.
def with_client
check_master_version
begin
@client = client_class.new
rescue SystemExit,NoMemoryError
Expand Down
23 changes: 22 additions & 1 deletion lib/puppet/indirector/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def find(request)
end

if is_http_200?(response)
check_master_version(response)
content_type, body = parse_response(response)
result = deserialize_find(content_type, body)
result.name = request.key if result.respond_to?(:name=)
Expand All @@ -112,7 +113,12 @@ def head(request)
http_head(request, indirection2uri(request), headers)
end

!!is_http_200?(response)
if is_http_200?(response)
check_master_version(response)
true
else
false
end
end

def search(request)
Expand All @@ -121,6 +127,7 @@ def search(request)
end

if is_http_200?(response)
check_master_version(response)
content_type, body = parse_response(response)
deserialize_search(content_type, body) || []
else
Expand All @@ -136,6 +143,7 @@ def destroy(request)
end

if is_http_200?(response)
check_master_version(response)
content_type, body = parse_response(response)
deserialize_destroy(content_type, body)
else
Expand All @@ -151,6 +159,7 @@ def save(request)
end

if is_http_200?(response)
check_master_version(response)
content_type, body = parse_response(response)
deserialize_save(content_type, body)
else
Expand Down Expand Up @@ -191,6 +200,18 @@ def convert_to_http_error(response)
Net::HTTPError.new(message, response)
end

def check_master_version response
if !response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION] &&
(Puppet[:legacy_query_parameter_serialization] == false || Puppet[:report_serialization_format] != "yaml")
Puppet.notice "Using less secure serialization of reports and query parameters for compatibility"
Puppet.notice "with older puppet master. To remove this notice, please upgrade your master(s) "
Puppet.notice "to Puppet 3.3 or newer."
Puppet.notice "See http://links.puppetlabs.com/deprecate_yaml_on_network for more information."
Puppet[:legacy_query_parameter_serialization] = true
Puppet[:report_serialization_format] = "yaml"
end
end

# Returns the content_type, stripping any appended charset, and the
# body, decompressed if necessary (content-encoding is checked inside
# uncompress_body)
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/network/http.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Puppet::Network::HTTP
HEADER_ENABLE_PROFILING = "X-Puppet-Profiling"
HEADER_PUPPET_VERSION = "X-Puppet-Version"
end
2 changes: 2 additions & 0 deletions lib/puppet/network/http/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def process(request, response)
request_method = http_method(request)
request_path = path(request)

response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION] = Puppet.version

configure_profiler(request_headers, request_params)

Puppet::Util::Profiler.profile("Processed request #{request_method} #{request_path}") do
Expand Down
19 changes: 0 additions & 19 deletions spec/unit/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,6 @@ def controlled_run(&block)
@agent.stubs(:disabled?).returns false
end

it "should set backward compatibility settings when talking to an older master" do
# Override the stub above to return a bare status object, i.e. without a version in the hash
Puppet::Status.indirection.expects(:find).returns Puppet::Status.new

@agent.run()
Puppet[:report_serialization_format].should == 'yaml'
Puppet[:legacy_query_parameter_serialization].should == true
end

it "should not set backward compatibility settings when talking to a 3.3.1 master" do
# Override the stub above to return a status object with the first reported version to
# support yaml deprecation
Puppet::Status.indirection.expects(:find).returns Puppet::Status.new("version" => "3.3.1")

@agent.run()
Puppet[:report_serialization_format].should == 'pson'
Puppet[:legacy_query_parameter_serialization].should == false
end

it "should splay" do
@agent.expects(:splay)

Expand Down
1 change: 1 addition & 0 deletions spec/unit/indirector/certificate/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
response = stub 'response', :code => "200", :body => cert_string
response.stubs(:[]).with('content-type').returns "text/plain"
response.stubs(:[]).with('content-encoding')
response.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns(Puppet.version)
network.stubs(:verify_callback=)
network.expects(:get).returns response

Expand Down
1 change: 1 addition & 0 deletions spec/unit/indirector/report/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def mock_response(code, body, content_type='text/plain', encoding=nil)
obj = stub('http 200 ok', :code => code.to_s, :body => body)
obj.stubs(:[]).with('content-type').returns(content_type)
obj.stubs(:[]).with('content-encoding').returns(encoding)
obj.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns(Puppet.version)
obj
end

Expand Down
24 changes: 22 additions & 2 deletions spec/unit/indirector/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,28 @@
require 'puppet/indirector/rest'

# Just one from each category since the code makes no real distinctions
HTTP_ERROR_CODES = [300, 400, 500]
shared_examples_for "a REST terminus method" do |terminus_method|
describe "when talking to an older master" do
it "should set backward compatibility settings" do
response.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns nil

terminus.send(terminus_method, request)
Puppet[:report_serialization_format].should == 'yaml'
Puppet[:legacy_query_parameter_serialization].should == true
end
end

describe "when talking to a 3.3.1 master" do
it "should not set backward compatibility settings" do
response.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns "3.3.1"

terminus.send(terminus_method, request)
Puppet[:report_serialization_format].should == 'pson'
Puppet[:legacy_query_parameter_serialization].should == false
end
end

HTTP_ERROR_CODES = [300, 400, 500]
HTTP_ERROR_CODES.each do |code|
describe "when the response code is #{code}" do
let(:response) { mock_response(code, 'error messaged!!!') }
Expand Down Expand Up @@ -115,6 +135,7 @@ def mock_response(code, body, content_type='text/plain', encoding=nil)
obj = stub('http 200 ok', :code => code.to_s, :body => body)
obj.stubs(:[]).with('content-type').returns(content_type)
obj.stubs(:[]).with('content-encoding').returns(encoding)
obj.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns(Puppet.version)
obj
end

Expand Down Expand Up @@ -174,7 +195,6 @@ def save_request(key, instance, options={})
terminus_class.port.should == 543
end


it 'should default to :puppet for the srv_service' do
Puppet::Indirector::REST.srv_service.should == :puppet
end
Expand Down
6 changes: 5 additions & 1 deletion spec/unit/network/http/handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ def a_request_that_searches(key, request = {})
end

describe "when processing a request" do
let(:response) { mock('http response') }
let(:response) do
obj = stub "http 200 ok"
obj.stubs(:[]=).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION, Puppet.version)
obj
end

before do
handler.stubs(:check_authorization)
Expand Down

0 comments on commit f0884b3

Please sign in to comment.