Skip to content

Commit 2ffa729

Browse files
(maint) Merge up 4202cda to main
Generated by CI * commit '4202cda120b7e3698feea1b6f8f55f6c65ebb3d5': (packaging) Updating manpage file for 6.x (PUP-11440) If no env found, and strict env mode cancel puppet run (maint) Fix resources_spec for Ruby versions < 2.5 Conflicts: man/man8/puppet-key.8 man/man8/puppet-man.8 man/man8/puppet-status.8
2 parents 849f133 + 4202cda commit 2ffa729

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lib/puppet/configurer.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def run_internal(options)
418418
temp_value = options[:pluginsync]
419419

420420
# only validate server environment if pluginsync is requested
421-
options[:pluginsync] = valid_server_environment? if options[:pluginsync] == true
421+
options[:pluginsync] = valid_server_environment? if options[:pluginsync]
422422

423423
query_options, facts = get_facts(options) unless query_options
424424
options[:pluginsync] = temp_value
@@ -531,7 +531,11 @@ def valid_server_environment?
531531
true
532532
rescue Puppet::HTTP::ResponseError => detail
533533
if detail.response.code == 404
534-
Puppet.notice(_("Environment '%{environment}' not found on server, skipping initial pluginsync.") % { environment: @environment })
534+
if Puppet[:strict_environment_mode]
535+
raise Puppet::Error.new(_("Environment '%{environment}' not found on server, aborting run.") % { environment: @environment })
536+
else
537+
Puppet.notice(_("Environment '%{environment}' not found on server, skipping initial pluginsync.") % { environment: @environment })
538+
end
535539
else
536540
Puppet.log_exception(detail, detail.message)
537541
end

spec/integration/application/resource_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
end
2929

3030
it 'lists types from the default environment' do
31+
begin
3132
modulepath = File.join(Puppet[:codedir], 'modules', 'test', 'lib', 'puppet', 'type')
3233
FileUtils.mkdir_p(modulepath)
3334
File.write(File.join(modulepath, 'test_resource_spec.rb'), 'Puppet::Type.newtype(:test_resource_spec)')
@@ -38,6 +39,7 @@
3839
}.to exit_with(0).and output(/test_resource_spec/).to_stdout
3940
ensure
4041
Puppet::Type.rmtype(:test_resource_spec)
42+
end
4143
end
4244
end
4345

spec/unit/configurer_spec.rb

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
Puppet[:report] = true
1010

1111
catalog.add_resource(resource)
12-
allow_any_instance_of(described_class).to(
13-
receive(:valid_server_environment?).and_return(true)
14-
)
1512

1613
Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1714
---
@@ -78,10 +75,44 @@
7875
end
7976
end
8077

78+
describe "when executing a catalog run without stubbing valid_server_environment?" do
79+
before do
80+
Puppet::Resource::Catalog.indirection.terminus_class = :rest
81+
allow(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(catalog)
82+
end
83+
84+
it 'skips initial plugin sync if environment is not found and no strict_environment_mode' do
85+
body = "{\"message\":\"Not Found: Could not find environment 'fasdfad'\",\"issue_kind\":\"RUNTIME_ERROR\"}"
86+
stub_request(:get, %r{/puppet/v3/file_metadatas/plugins?}).to_return(
87+
status: 404, body: body, headers: {'Content-Type' => 'application/json'}
88+
)
89+
90+
configurer.run(:pluginsync => true)
91+
92+
expect(@logs).to include(an_object_having_attributes(level: :notice, message: %r{Environment 'production' not found on server, skipping initial pluginsync.}))
93+
expect(@logs).to include(an_object_having_attributes(level: :notice, message: /Applied catalog in .* seconds/))
94+
end
95+
96+
it 'if strict_environment_mode is set and environment is not found, aborts the puppet run' do
97+
Puppet[:strict_environment_mode] = true
98+
body = "{\"message\":\"Not Found: Could not find environment 'fasdfad'\",\"issue_kind\":\"RUNTIME_ERROR\"}"
99+
stub_request(:get, %r{/puppet/v3/file_metadatas/plugins?}).to_return(
100+
status: 404, body: body, headers: {'Content-Type' => 'application/json'}
101+
)
102+
103+
configurer.run(:pluginsync => true)
104+
105+
expect(@logs).to include(an_object_having_attributes(level: :err, message: %r{Failed to apply catalog: Environment 'production' not found on server, aborting run.}))
106+
end
107+
end
108+
81109
describe "when executing a catalog run" do
82110
before do
83111
Puppet::Resource::Catalog.indirection.terminus_class = :rest
84112
allow(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(catalog)
113+
allow_any_instance_of(described_class).to(
114+
receive(:valid_server_environment?).and_return(true)
115+
)
85116
end
86117

87118
it "downloads plugins when told" do

0 commit comments

Comments
 (0)