Skip to content

Commit f0884b3

Browse files
committed
Merge pull request #1915 from kylog/issue/stable/22535-new-agent-old-master-file-ignore-list-is-ignored
(#22535) Use a response header for version
2 parents 34b5add + 70a18ef commit f0884b3

File tree

9 files changed

+54
-41
lines changed

9 files changed

+54
-41
lines changed

lib/puppet/agent.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,9 @@ def run_in_fork(forking = true)
105105

106106
private
107107

108-
def check_master_version
109-
110-
prev_terminus = Puppet::Status.indirection.terminus_class
111-
Puppet::Status.indirection.terminus_class = :rest
112-
master_version = Puppet::Status.indirection.find('*').version
113-
Puppet::Status.indirection.terminus_class = prev_terminus
114-
115-
if !master_version
116-
Puppet.notice "Using less secure serialization of reports and query parameters for compatibility"
117-
Puppet.notice "with older puppet master. To remove this notice, please upgrade your master(s) "
118-
Puppet.notice "to Puppet 3.3 or newer."
119-
Puppet.notice "See http://links.puppetlabs.com/deprecate_yaml_on_network for more information."
120-
Puppet[:legacy_query_parameter_serialization] = true
121-
Puppet[:report_serialization_format] = "yaml"
122-
end
123-
end
124-
125108
# Create and yield a client instance, keeping a reference
126109
# to it during the yield.
127110
def with_client
128-
check_master_version
129111
begin
130112
@client = client_class.new
131113
rescue SystemExit,NoMemoryError

lib/puppet/indirector/rest.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def find(request)
9898
end
9999

100100
if is_http_200?(response)
101+
check_master_version(response)
101102
content_type, body = parse_response(response)
102103
result = deserialize_find(content_type, body)
103104
result.name = request.key if result.respond_to?(:name=)
@@ -112,7 +113,12 @@ def head(request)
112113
http_head(request, indirection2uri(request), headers)
113114
end
114115

115-
!!is_http_200?(response)
116+
if is_http_200?(response)
117+
check_master_version(response)
118+
true
119+
else
120+
false
121+
end
116122
end
117123

118124
def search(request)
@@ -121,6 +127,7 @@ def search(request)
121127
end
122128

123129
if is_http_200?(response)
130+
check_master_version(response)
124131
content_type, body = parse_response(response)
125132
deserialize_search(content_type, body) || []
126133
else
@@ -136,6 +143,7 @@ def destroy(request)
136143
end
137144

138145
if is_http_200?(response)
146+
check_master_version(response)
139147
content_type, body = parse_response(response)
140148
deserialize_destroy(content_type, body)
141149
else
@@ -151,6 +159,7 @@ def save(request)
151159
end
152160

153161
if is_http_200?(response)
162+
check_master_version(response)
154163
content_type, body = parse_response(response)
155164
deserialize_save(content_type, body)
156165
else
@@ -191,6 +200,18 @@ def convert_to_http_error(response)
191200
Net::HTTPError.new(message, response)
192201
end
193202

203+
def check_master_version response
204+
if !response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION] &&
205+
(Puppet[:legacy_query_parameter_serialization] == false || Puppet[:report_serialization_format] != "yaml")
206+
Puppet.notice "Using less secure serialization of reports and query parameters for compatibility"
207+
Puppet.notice "with older puppet master. To remove this notice, please upgrade your master(s) "
208+
Puppet.notice "to Puppet 3.3 or newer."
209+
Puppet.notice "See http://links.puppetlabs.com/deprecate_yaml_on_network for more information."
210+
Puppet[:legacy_query_parameter_serialization] = true
211+
Puppet[:report_serialization_format] = "yaml"
212+
end
213+
end
214+
194215
# Returns the content_type, stripping any appended charset, and the
195216
# body, decompressed if necessary (content-encoding is checked inside
196217
# uncompress_body)

lib/puppet/network/http.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module Puppet::Network::HTTP
22
HEADER_ENABLE_PROFILING = "X-Puppet-Profiling"
3+
HEADER_PUPPET_VERSION = "X-Puppet-Version"
34
end

lib/puppet/network/http/handler.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def process(request, response)
8484
request_method = http_method(request)
8585
request_path = path(request)
8686

87+
response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION] = Puppet.version
88+
8789
configure_profiler(request_headers, request_params)
8890

8991
Puppet::Util::Profiler.profile("Processed request #{request_method} #{request_path}") do

spec/unit/agent_spec.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,6 @@ def controlled_run(&block)
7979
@agent.stubs(:disabled?).returns false
8080
end
8181

82-
it "should set backward compatibility settings when talking to an older master" do
83-
# Override the stub above to return a bare status object, i.e. without a version in the hash
84-
Puppet::Status.indirection.expects(:find).returns Puppet::Status.new
85-
86-
@agent.run()
87-
Puppet[:report_serialization_format].should == 'yaml'
88-
Puppet[:legacy_query_parameter_serialization].should == true
89-
end
90-
91-
it "should not set backward compatibility settings when talking to a 3.3.1 master" do
92-
# Override the stub above to return a status object with the first reported version to
93-
# support yaml deprecation
94-
Puppet::Status.indirection.expects(:find).returns Puppet::Status.new("version" => "3.3.1")
95-
96-
@agent.run()
97-
Puppet[:report_serialization_format].should == 'pson'
98-
Puppet[:legacy_query_parameter_serialization].should == false
99-
end
100-
10182
it "should splay" do
10283
@agent.expects(:splay)
10384

spec/unit/indirector/certificate/rest_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
response = stub 'response', :code => "200", :body => cert_string
5252
response.stubs(:[]).with('content-type').returns "text/plain"
5353
response.stubs(:[]).with('content-encoding')
54+
response.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns(Puppet.version)
5455
network.stubs(:verify_callback=)
5556
network.expects(:get).returns response
5657

spec/unit/indirector/report/rest_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def mock_response(code, body, content_type='text/plain', encoding=nil)
3636
obj = stub('http 200 ok', :code => code.to_s, :body => body)
3737
obj.stubs(:[]).with('content-type').returns(content_type)
3838
obj.stubs(:[]).with('content-encoding').returns(encoding)
39+
obj.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns(Puppet.version)
3940
obj
4041
end
4142

spec/unit/indirector/rest_spec.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@
55
require 'puppet/indirector/rest'
66

77
# Just one from each category since the code makes no real distinctions
8-
HTTP_ERROR_CODES = [300, 400, 500]
98
shared_examples_for "a REST terminus method" do |terminus_method|
9+
describe "when talking to an older master" do
10+
it "should set backward compatibility settings" do
11+
response.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns nil
12+
13+
terminus.send(terminus_method, request)
14+
Puppet[:report_serialization_format].should == 'yaml'
15+
Puppet[:legacy_query_parameter_serialization].should == true
16+
end
17+
end
18+
19+
describe "when talking to a 3.3.1 master" do
20+
it "should not set backward compatibility settings" do
21+
response.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns "3.3.1"
22+
23+
terminus.send(terminus_method, request)
24+
Puppet[:report_serialization_format].should == 'pson'
25+
Puppet[:legacy_query_parameter_serialization].should == false
26+
end
27+
end
28+
29+
HTTP_ERROR_CODES = [300, 400, 500]
1030
HTTP_ERROR_CODES.each do |code|
1131
describe "when the response code is #{code}" do
1232
let(:response) { mock_response(code, 'error messaged!!!') }
@@ -115,6 +135,7 @@ def mock_response(code, body, content_type='text/plain', encoding=nil)
115135
obj = stub('http 200 ok', :code => code.to_s, :body => body)
116136
obj.stubs(:[]).with('content-type').returns(content_type)
117137
obj.stubs(:[]).with('content-encoding').returns(encoding)
138+
obj.stubs(:[]).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION).returns(Puppet.version)
118139
obj
119140
end
120141

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

177-
178198
it 'should default to :puppet for the srv_service' do
179199
Puppet::Indirector::REST.srv_service.should == :puppet
180200
end

spec/unit/network/http/handler_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ def a_request_that_searches(key, request = {})
146146
end
147147

148148
describe "when processing a request" do
149-
let(:response) { mock('http response') }
149+
let(:response) do
150+
obj = stub "http 200 ok"
151+
obj.stubs(:[]=).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION, Puppet.version)
152+
obj
153+
end
150154

151155
before do
152156
handler.stubs(:check_authorization)

0 commit comments

Comments
 (0)