|
9 | 9 | Puppet[:report] = true
|
10 | 10 |
|
11 | 11 | catalog.add_resource(resource)
|
12 |
| - allow_any_instance_of(described_class).to( |
13 |
| - receive(:valid_server_environment?).and_return(true) |
14 |
| - ) |
15 | 12 |
|
16 | 13 | Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
|
17 | 14 | ---
|
|
78 | 75 | end
|
79 | 76 | end
|
80 | 77 |
|
| 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 | + |
81 | 109 | describe "when executing a catalog run" do
|
82 | 110 | before do
|
83 | 111 | Puppet::Resource::Catalog.indirection.terminus_class = :rest
|
84 | 112 | 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 | + ) |
85 | 116 | end
|
86 | 117 |
|
87 | 118 | it "downloads plugins when told" do
|
|
0 commit comments