puppet 7.9.0-x64-mingw32 → 7.10.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -6
  3. data/{ext → examples/enc}/regexp_nodes/classes/databases +0 -0
  4. data/{ext → examples/enc}/regexp_nodes/classes/webservers +0 -0
  5. data/{ext → examples/enc}/regexp_nodes/environment/development +0 -0
  6. data/{ext → examples/enc}/regexp_nodes/parameters/service/prod +0 -0
  7. data/{ext → examples/enc}/regexp_nodes/parameters/service/qa +0 -0
  8. data/{ext → examples/enc}/regexp_nodes/parameters/service/sandbox +0 -0
  9. data/{ext → examples/enc}/regexp_nodes/regexp_nodes.rb +0 -0
  10. data/{ext → examples}/nagios/check_puppet.rb +2 -2
  11. data/ext/README.md +13 -0
  12. data/lib/puppet/configurer.rb +155 -46
  13. data/lib/puppet/defaults.rb +51 -26
  14. data/lib/puppet/environments.rb +66 -26
  15. data/lib/puppet/file_serving/configuration.rb +2 -0
  16. data/lib/puppet/file_serving/configuration/parser.rb +2 -0
  17. data/lib/puppet/file_serving/mount/scripts.rb +24 -0
  18. data/lib/puppet/functions/find_template.rb +2 -2
  19. data/lib/puppet/http/service/compiler.rb +6 -1
  20. data/lib/puppet/indirector/catalog/compiler.rb +21 -3
  21. data/lib/puppet/indirector/catalog/rest.rb +1 -0
  22. data/lib/puppet/indirector/terminus.rb +4 -0
  23. data/lib/puppet/module/plan.rb +0 -1
  24. data/lib/puppet/module/task.rb +1 -1
  25. data/lib/puppet/module_tool/applications/installer.rb +8 -4
  26. data/lib/puppet/network/http/api/indirected_routes.rb +1 -1
  27. data/lib/puppet/node/environment.rb +10 -11
  28. data/lib/puppet/pops/serialization/to_data_converter.rb +18 -6
  29. data/lib/puppet/provider/package/pkg.rb +8 -1
  30. data/lib/puppet/provider/service/launchd.rb +1 -1
  31. data/lib/puppet/provider/service/systemd.rb +1 -1
  32. data/lib/puppet/provider/user/useradd.rb +42 -9
  33. data/lib/puppet/transaction/persistence.rb +11 -1
  34. data/lib/puppet/transaction/report.rb +15 -1
  35. data/lib/puppet/type.rb +1 -1
  36. data/lib/puppet/type/exec.rb +10 -1
  37. data/lib/puppet/type/file.rb +6 -6
  38. data/lib/puppet/type/filebucket.rb +2 -2
  39. data/lib/puppet/version.rb +1 -1
  40. data/locales/puppet.pot +134 -94
  41. data/man/man5/puppet.conf.5 +65 -25
  42. data/man/man8/puppet-agent.8 +1 -1
  43. data/man/man8/puppet-apply.8 +1 -1
  44. data/man/man8/puppet-catalog.8 +1 -1
  45. data/man/man8/puppet-config.8 +1 -1
  46. data/man/man8/puppet-describe.8 +1 -1
  47. data/man/man8/puppet-device.8 +1 -1
  48. data/man/man8/puppet-doc.8 +1 -1
  49. data/man/man8/puppet-epp.8 +1 -1
  50. data/man/man8/puppet-facts.8 +1 -1
  51. data/man/man8/puppet-filebucket.8 +1 -1
  52. data/man/man8/puppet-generate.8 +1 -1
  53. data/man/man8/puppet-help.8 +1 -1
  54. data/man/man8/puppet-lookup.8 +1 -1
  55. data/man/man8/puppet-module.8 +3 -3
  56. data/man/man8/puppet-node.8 +1 -1
  57. data/man/man8/puppet-parser.8 +1 -1
  58. data/man/man8/puppet-plugin.8 +1 -1
  59. data/man/man8/puppet-report.8 +1 -1
  60. data/man/man8/puppet-resource.8 +1 -1
  61. data/man/man8/puppet-script.8 +1 -1
  62. data/man/man8/puppet-ssl.8 +1 -1
  63. data/man/man8/puppet.8 +2 -2
  64. data/spec/fixtures/integration/application/agent/lib/facter/agent_spec_role.rb +3 -0
  65. data/spec/fixtures/integration/l10n/envs/prod/modules/demo/Gemfile +4 -0
  66. data/spec/fixtures/integration/l10n/envs/prod/modules/demo/Rakefile +3 -0
  67. data/spec/fixtures/integration/l10n/envs/prod/modules/demo/lib/puppet/functions/l10n.rb +8 -0
  68. data/spec/fixtures/integration/l10n/envs/prod/modules/demo/locales/config.yaml +25 -0
  69. data/spec/fixtures/integration/l10n/envs/prod/modules/demo/locales/ja/puppet-l10n.po +19 -0
  70. data/spec/fixtures/integration/l10n/envs/prod/modules/demo/locales/puppet-l10n.pot +20 -0
  71. data/spec/fixtures/integration/l10n/envs/prod/modules/demo/metadata.json +8 -0
  72. data/spec/integration/application/agent_spec.rb +102 -52
  73. data/spec/integration/application/filebucket_spec.rb +5 -0
  74. data/spec/integration/configurer_spec.rb +17 -1
  75. data/spec/integration/l10n/compiler_spec.rb +37 -0
  76. data/spec/lib/puppet_spec/modules.rb +13 -2
  77. data/spec/lib/puppet_spec/puppetserver.rb +15 -0
  78. data/spec/shared_behaviours/documentation_on_faces.rb +0 -2
  79. data/spec/shared_contexts/l10n.rb +27 -0
  80. data/spec/spec_helper.rb +1 -10
  81. data/spec/unit/configurer_spec.rb +265 -54
  82. data/spec/unit/environments_spec.rb +150 -1
  83. data/spec/unit/file_serving/configuration/parser_spec.rb +23 -0
  84. data/spec/unit/file_serving/configuration_spec.rb +12 -4
  85. data/spec/unit/file_serving/mount/scripts_spec.rb +69 -0
  86. data/spec/unit/functions/logging_spec.rb +1 -0
  87. data/spec/unit/http/service/compiler_spec.rb +8 -0
  88. data/spec/unit/indirector/catalog/compiler_spec.rb +87 -0
  89. data/spec/unit/indirector/catalog/rest_spec.rb +8 -0
  90. data/spec/unit/interface/action_spec.rb +0 -9
  91. data/spec/unit/module_spec.rb +14 -0
  92. data/spec/unit/module_tool/applications/installer_spec.rb +39 -12
  93. data/spec/unit/pops/parser/parse_containers_spec.rb +0 -11
  94. data/spec/unit/pops/serialization/to_from_hr_spec.rb +58 -0
  95. data/spec/unit/provider/package/pkg_spec.rb +19 -5
  96. data/spec/unit/provider/service/launchd_spec.rb +11 -0
  97. data/spec/unit/provider/service/systemd_spec.rb +1 -1
  98. data/spec/unit/provider/user/useradd_spec.rb +3 -2
  99. metadata +34 -94
  100. data/ext/README.environment +0 -8
  101. data/ext/dbfix.sql +0 -132
  102. data/ext/debian/README.Debian +0 -8
  103. data/ext/debian/README.source +0 -2
  104. data/ext/debian/TODO.Debian +0 -1
  105. data/ext/debian/changelog.erb +0 -1122
  106. data/ext/debian/compat +0 -1
  107. data/ext/debian/control +0 -144
  108. data/ext/debian/copyright +0 -339
  109. data/ext/debian/docs +0 -1
  110. data/ext/debian/fileserver.conf +0 -41
  111. data/ext/debian/puppet-common.dirs +0 -13
  112. data/ext/debian/puppet-common.install +0 -3
  113. data/ext/debian/puppet-common.lintian-overrides +0 -5
  114. data/ext/debian/puppet-common.manpages +0 -28
  115. data/ext/debian/puppet-common.postinst +0 -35
  116. data/ext/debian/puppet-common.postrm +0 -33
  117. data/ext/debian/puppet-el.dirs +0 -1
  118. data/ext/debian/puppet-el.emacsen-install +0 -25
  119. data/ext/debian/puppet-el.emacsen-remove +0 -11
  120. data/ext/debian/puppet-el.emacsen-startup +0 -9
  121. data/ext/debian/puppet-el.install +0 -1
  122. data/ext/debian/puppet-testsuite.install +0 -2
  123. data/ext/debian/puppet-testsuite.lintian-overrides +0 -4
  124. data/ext/debian/puppet.lintian-overrides +0 -3
  125. data/ext/debian/puppet.logrotate +0 -20
  126. data/ext/debian/puppet.postinst +0 -20
  127. data/ext/debian/puppet.postrm +0 -20
  128. data/ext/debian/puppet.preinst +0 -20
  129. data/ext/debian/puppetmaster-common.install +0 -2
  130. data/ext/debian/puppetmaster-common.manpages +0 -2
  131. data/ext/debian/puppetmaster-common.postinst +0 -6
  132. data/ext/debian/puppetmaster-passenger.dirs +0 -4
  133. data/ext/debian/puppetmaster-passenger.postinst +0 -162
  134. data/ext/debian/puppetmaster-passenger.postrm +0 -61
  135. data/ext/debian/puppetmaster.README.debian +0 -17
  136. data/ext/debian/puppetmaster.default +0 -14
  137. data/ext/debian/puppetmaster.init +0 -137
  138. data/ext/debian/puppetmaster.lintian-overrides +0 -3
  139. data/ext/debian/puppetmaster.postinst +0 -20
  140. data/ext/debian/puppetmaster.postrm +0 -5
  141. data/ext/debian/puppetmaster.preinst +0 -22
  142. data/ext/debian/rules +0 -132
  143. data/ext/debian/source/format +0 -1
  144. data/ext/debian/source/options +0 -1
  145. data/ext/debian/vim-puppet.README.Debian +0 -13
  146. data/ext/debian/vim-puppet.dirs +0 -5
  147. data/ext/debian/vim-puppet.yaml +0 -7
  148. data/ext/debian/watch +0 -2
  149. data/ext/freebsd/puppetd +0 -26
  150. data/ext/freebsd/puppetmasterd +0 -26
  151. data/ext/gentoo/conf.d/puppet +0 -5
  152. data/ext/gentoo/conf.d/puppetmaster +0 -12
  153. data/ext/gentoo/init.d/puppet +0 -38
  154. data/ext/gentoo/init.d/puppetmaster +0 -51
  155. data/ext/gentoo/puppet/fileserver.conf +0 -41
  156. data/ext/ips/puppet-agent +0 -44
  157. data/ext/ips/puppet-master +0 -44
  158. data/ext/ips/puppet.p5m.erb +0 -12
  159. data/ext/ips/puppetagent.xml +0 -42
  160. data/ext/ips/puppetmaster.xml +0 -42
  161. data/ext/ips/rules +0 -19
  162. data/ext/ips/transforms +0 -34
  163. data/ext/ldap/puppet.schema +0 -24
  164. data/ext/logcheck/puppet +0 -23
  165. data/ext/osx/file_mapping.yaml +0 -28
  166. data/ext/osx/postflight.erb +0 -109
  167. data/ext/osx/preflight.erb +0 -52
  168. data/ext/osx/prototype.plist.erb +0 -38
  169. data/ext/redhat/fileserver.conf +0 -41
  170. data/ext/redhat/logrotate +0 -21
  171. data/ext/redhat/puppet.spec.erb +0 -841
  172. data/ext/redhat/server.init +0 -128
  173. data/ext/redhat/server.sysconfig +0 -13
  174. data/ext/solaris/pkginfo +0 -6
  175. data/ext/solaris/smf/puppetd.xml +0 -77
  176. data/ext/solaris/smf/puppetmasterd.xml +0 -77
  177. data/ext/solaris/smf/svc-puppetd +0 -71
  178. data/ext/solaris/smf/svc-puppetmasterd +0 -67
  179. data/ext/suse/puppet.spec +0 -310
  180. data/ext/suse/server.init +0 -173
  181. data/ext/yaml_nodes.rb +0 -105
  182. data/spec/unit/indirector/store_configs_spec.rb +0 -7
@@ -36,7 +36,7 @@ module PuppetSpec::Modules
36
36
  end
37
37
  end
38
38
 
39
- if plans = options[:plans]
39
+ if (plans = options[:plans])
40
40
  plans_dir = File.join(module_dir, 'plans')
41
41
  FileUtils.mkdir_p(plans_dir)
42
42
  plans.each do |plan_file|
@@ -48,6 +48,17 @@ module PuppetSpec::Modules
48
48
  end
49
49
  end
50
50
 
51
+ if (scripts = options[:scripts])
52
+ scripts_dir = File.join(module_dir, 'scripts')
53
+ FileUtils.mkdir_p(scripts_dir)
54
+ scripts.each do |script_file|
55
+ if script_file.is_a?(String)
56
+ script_file = { :name => script_file, :content => "" }
57
+ end
58
+ File.write(File.join(scripts_dir, script_file[:name]), script_file[:content])
59
+ end
60
+ end
61
+
51
62
  (options[:files] || {}).each do |fname, content|
52
63
  path = File.join(module_dir, fname)
53
64
  FileUtils.mkdir_p(File.dirname(path))
@@ -61,7 +72,7 @@ module PuppetSpec::Modules
61
72
  module_dir = File.join(dir, name)
62
73
  FileUtils.mkdir_p(module_dir)
63
74
 
64
- if metadata = options[:metadata]
75
+ if (metadata = options[:metadata])
65
76
  File.open(File.join(module_dir, 'metadata.json'), 'w') do |f|
66
77
  f.write(metadata.to_json)
67
78
  end
@@ -31,6 +31,19 @@ class PuppetSpec::Puppetserver
31
31
  end
32
32
  end
33
33
 
34
+ class FileMetadataServlet < WEBrick::HTTPServlet::AbstractServlet
35
+ def do_GET request, response
36
+ response['Content-Type'] = 'application/json'
37
+ response.body = "{\"path\":\"/etc/puppetlabs/code/environments/production/modules\",\"relative_path\":\".\",\"links\":\"follow\",\"owner\":0,\"group\":0,\"mode\":493,\"checksum\":{\"type\":\"ctime\",\"value\":\"{ctime}2020-03-06 20:14:25 UTC\"},\"type\":\"directory\",\"destination\":null}"
38
+ end
39
+ end
40
+
41
+ class FileContentServlet < WEBrick::HTTPServlet::AbstractServlet
42
+ def do_GET request, response
43
+ response.status = 404
44
+ end
45
+ end
46
+
34
47
  class ReportServlet < WEBrick::HTTPServlet::AbstractServlet
35
48
  def do_PUT request, response
36
49
  response['Content-Type'] = 'application/json'
@@ -106,7 +119,9 @@ class PuppetSpec::Puppetserver
106
119
  register_mount('/status/v1/simple/server', proc { |req, res| }, nil)
107
120
  register_mount('/puppet/v3/node', mounts[:node], NodeServlet)
108
121
  register_mount('/puppet/v3/catalog', mounts[:catalog], CatalogServlet)
122
+ register_mount('/puppet/v3/file_metadata', mounts[:file_metadata], FileMetadataServlet)
109
123
  register_mount('/puppet/v3/file_metadatas', mounts[:file_metadatas], FileMetadatasServlet)
124
+ register_mount('/puppet/v3/file_content', mounts[:file_content], FileContentServlet)
110
125
  register_mount('/puppet/v3/static_file_content', mounts[:static_file_content], StaticFileContentServlet)
111
126
  register_mount('/puppet/v3/report', mounts[:report], ReportServlet)
112
127
  register_mount('/puppet/v3/file_bucket_file', mounts[:filebucket], FilebucketServlet)
@@ -176,8 +176,6 @@ shared_examples_for "documentation on faces" do
176
176
  subject.license = "foo"
177
177
  expect(subject.license).to eq("foo")
178
178
  end
179
-
180
- it "should accept symbols to specify existing licenses..."
181
179
  end
182
180
 
183
181
  describe "#copyright" do
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.shared_context('l10n') do |locale|
4
+ before :all do
5
+ @old_locale = Locale.current
6
+ Locale.current = locale
7
+ Puppet::GettextConfig.setup_locale
8
+
9
+ # overwrite stubs with real implementation
10
+ ::Object.send(:remove_method, :_)
11
+ ::Object.send(:remove_method, :n_)
12
+ class ::Object
13
+ include FastGettext::Translation
14
+ end
15
+ end
16
+
17
+ after :all do
18
+ Locale.current = @old_locale
19
+
20
+ # restore stubs
21
+ load File.expand_path(File.join(__dir__, '../../lib/puppet/gettext/stubs.rb'))
22
+ end
23
+
24
+ before :each do
25
+ Puppet[:disable_i18n] = false
26
+ end
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -68,16 +68,7 @@ VCR.turn_off!
68
68
  RSpec.configure do |config|
69
69
  include PuppetSpec::Fixtures
70
70
 
71
- # Examples or groups can selectively tag themselves as broken.
72
- # For example;
73
- #
74
- # rbv = "#{RUBY_VERSION}-p#{RbConfig::CONFIG['PATCHLEVEL']}"
75
- # describe "mostly working", :broken => false unless rbv == "1.9.3-p327" do
76
- # it "parses a valid IP" do
77
- # IPAddr.new("::2:3:4:5:6:7:8")
78
- # end
79
- # end
80
- exclude_filters = {:broken => true}
71
+ exclude_filters = {}
81
72
  exclude_filters[:benchmark] = true unless ENV['BENCHMARK']
82
73
  config.filter_run_excluding exclude_filters
83
74
 
@@ -7,6 +7,9 @@ describe Puppet::Configurer do
7
7
  Puppet[:report] = true
8
8
 
9
9
  catalog.add_resource(resource)
10
+ allow_any_instance_of(described_class).to(
11
+ receive(:valid_server_environment?).and_return(true)
12
+ )
10
13
  end
11
14
 
12
15
  let(:node_name) { Puppet[:node_name_value] }
@@ -78,10 +81,10 @@ describe Puppet::Configurer do
78
81
  configurer.run(:pluginsync => false)
79
82
  end
80
83
 
81
- it "should carry on when it can't fetch its node definition" do
82
- error = Net::HTTPError.new(400, 'dummy server communication error')
83
- expect(Puppet::Node.indirection).to receive(:find).and_raise(error)
84
- expect(configurer.run).to eq(0)
84
+ it "does not download plugins when specified environment is not vaild on server" do
85
+ expect(configurer).to receive(:valid_server_environment?).and_return(false)
86
+ expect(configurer).not_to receive(:download_plugins)
87
+ configurer.run(:pluginsync => true)
85
88
  end
86
89
 
87
90
  it "fails the run if pluginsync fails when usecacheonfailure is false" do
@@ -125,7 +128,6 @@ describe Puppet::Configurer do
125
128
  it "applies a cached catalog when it can't connect to the master" do
126
129
  error = Errno::ECONNREFUSED.new('Connection refused - connect(2)')
127
130
 
128
- expect(Puppet::Node.indirection).to receive(:find).and_raise(error)
129
131
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_cache => true)).and_raise(error)
130
132
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_terminus => true)).and_return(catalog)
131
133
 
@@ -149,6 +151,126 @@ describe Puppet::Configurer do
149
151
  expect(report.host).to eq('node_name_from_fact')
150
152
  end
151
153
 
154
+ it "should warn the user when the fact value length limits are exceeded" do
155
+ Puppet[:fact_name_length_soft_limit] = 0
156
+ Puppet[:fact_value_length_soft_limit] = 1
157
+ Puppet[:top_level_facts_soft_limit] = 0
158
+ Puppet[:number_of_facts_soft_limit] = 0
159
+ Puppet[:payload_soft_limit] = 0
160
+
161
+ facts.values = { 'processors' => {
162
+ 'cores' => 1,
163
+ 'count' => 2,
164
+ 'isa' => "i386",
165
+ 'models' => [
166
+ "CPU1 @ 2.80GHz"
167
+ ],
168
+ 'physicalcount' => 4 }
169
+ }
170
+ Puppet::Node::Facts.indirection.save(facts)
171
+
172
+ expect(Puppet).to receive(:warning).with(/Fact value '.+' with the value length: '[1-9]*' exceeds the value length limit: [1-9]*/).twice
173
+ configurer.run
174
+ end
175
+
176
+ it "should warn the user when the payload limits are exceeded" do
177
+ Puppet[:fact_name_length_soft_limit] = 0
178
+ Puppet[:fact_value_length_soft_limit] = 0
179
+ Puppet[:top_level_facts_soft_limit] = 0
180
+ Puppet[:number_of_facts_soft_limit] = 0
181
+ Puppet[:payload_soft_limit] = 1
182
+
183
+ facts.values = { 'processors' => {
184
+ 'cores' => 1,
185
+ 'count' => 2,
186
+ 'isa' => "i386",
187
+ 'models' => [
188
+ "CPU1 @ 2.80GHz"
189
+ ],
190
+ 'physicalcount' => 4 }
191
+ }
192
+ Puppet::Node::Facts.indirection.save(facts)
193
+
194
+ expect(Puppet).to receive(:warning).with(/Payload with the current size of: '[1-9]*' exceeds the payload size limit: [1-9]*/)
195
+ configurer.run
196
+ end
197
+
198
+ it "should warn the user when the total number of facts limit is exceeded" do
199
+ Puppet[:fact_name_length_soft_limit] = 0
200
+ Puppet[:fact_value_length_soft_limit] = 0
201
+ Puppet[:top_level_facts_soft_limit] = 0
202
+ Puppet[:number_of_facts_soft_limit] = 1
203
+ Puppet[:payload_soft_limit] = 0
204
+
205
+ facts.values = {
206
+ 'processors' => {
207
+ 'cores' => 1,
208
+ 'count' => 2,
209
+ 'isa' => "i386",
210
+ 'models' => [
211
+ "CPU1 @ 2.80GHz",
212
+ "CPU1 @ 2.80GHz",
213
+ "CPU1 @ 2.80GHz",
214
+ "CPU1 @ 2.80GHz",
215
+ "CPU1 @ 2.80GHz",
216
+ {
217
+ 'processors' => {
218
+ 'cores' => [1,2]
219
+ }
220
+ }
221
+ ],
222
+ 'physicalcount' => 4
223
+ }
224
+ }
225
+ Puppet::Node::Facts.indirection.save(facts)
226
+
227
+ expect(Puppet).to receive(:warning).with(/The current total number of facts: [1-9]* exceeds the number of facts limit: [1-9]*/)
228
+ configurer.run
229
+ end
230
+
231
+ it "should warn the user when the top level facts size limits are exceeded" do
232
+ Puppet[:fact_name_length_soft_limit] = 0
233
+ Puppet[:fact_value_length_soft_limit] = 0
234
+ Puppet[:top_level_facts_soft_limit] = 1
235
+ Puppet[:number_of_facts_soft_limit] = 0
236
+ Puppet[:payload_soft_limit] = 0
237
+
238
+ facts.values = {'my_new_fact_name' => 'my_new_fact_value',
239
+ 'my_new_fact_name2' => 'my_new_fact_value2'}
240
+ Puppet::Node::Facts.indirection.save(facts)
241
+
242
+ expect(Puppet).to receive(:warning).with(/The current number of top level facts: [1-9]* exceeds the top facts limit: [1-9]*/)
243
+ configurer.run
244
+ end
245
+
246
+ it "should warn the user when the fact name length limits are exceeded" do
247
+ Puppet[:fact_name_length_soft_limit] = 1
248
+ Puppet[:fact_value_length_soft_limit] = 0
249
+ Puppet[:top_level_facts_soft_limit] = 0
250
+ Puppet[:number_of_facts_soft_limit] = 0
251
+ Puppet[:payload_soft_limit] = 0
252
+
253
+ facts.values = {'my_new_fact_name' => 'my_new_fact_value'}
254
+ Puppet::Node::Facts.indirection.save(facts)
255
+
256
+ expect(Puppet).to receive(:warning).with(/Fact .+ with length: '[1-9]*' exceeds the length limit: [1-9]*/)
257
+ configurer.run
258
+ end
259
+
260
+ it "shouldn't warn the user when the fact limit settings are set to 0" do
261
+ Puppet[:fact_name_length_soft_limit] = 0
262
+ Puppet[:fact_value_length_soft_limit] = 0
263
+ Puppet[:top_level_facts_soft_limit] = 0
264
+ Puppet[:number_of_facts_soft_limit] = 0
265
+ Puppet[:payload_soft_limit] = 0
266
+
267
+ facts.values = {'my_new_fact_name' => 'my_new_fact_value'}
268
+ Puppet::Node::Facts.indirection.save(facts)
269
+
270
+ expect(Puppet).not_to receive(:warning)
271
+ configurer.run
272
+ end
273
+
152
274
  it "creates a new report when applying the catalog" do
153
275
  options = {}
154
276
  configurer.run(options)
@@ -553,24 +675,6 @@ describe Puppet::Configurer do
553
675
  end
554
676
  end
555
677
 
556
- describe "when requesting a node" do
557
- it "uses the transaction uuid in the request" do
558
- expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(transaction_uuid: anything)).twice
559
- configurer.run
560
- end
561
-
562
- it "sends an explicitly configured environment request" do
563
- expect(Puppet.settings).to receive(:set_by_config?).with(:environment).and_return(true)
564
- expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: Puppet[:environment])).twice
565
- configurer.run
566
- end
567
-
568
- it "does not send a configured_environment when using the default" do
569
- expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: nil)).twice
570
- configurer.run
571
- end
572
- end
573
-
574
678
  def expects_pluginsync
575
679
  metadata = "[{\"path\":\"/etc/puppetlabs/code\",\"relative_path\":\".\",\"links\":\"follow\",\"owner\":0,\"group\":0,\"mode\":420,\"checksum\":{\"type\":\"ctime\",\"value\":\"{ctime}2020-07-10 14:00:00 -0700\"},\"type\":\"directory\",\"destination\":null}]"
576
680
  stub_request(:get, %r{/puppet/v3/file_metadatas/(plugins|locales)}).to_return(status: 200, body: metadata, headers: {'Content-Type' => 'application/json'})
@@ -581,7 +685,7 @@ describe Puppet::Configurer do
581
685
  end
582
686
 
583
687
  def expects_new_catalog_only(catalog)
584
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(catalog)
688
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true, check_environment: true)).and_return(catalog)
585
689
  expect(Puppet::Resource::Catalog.indirection).not_to receive(:find).with(anything, hash_including(ignore_terminus: true))
586
690
  end
587
691
 
@@ -598,7 +702,7 @@ describe Puppet::Configurer do
598
702
  def expects_fallback_to_new_catalog(catalog)
599
703
  expects_pluginsync
600
704
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(nil)
601
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(catalog)
705
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true, check_environment: true)).and_return(catalog)
602
706
  end
603
707
 
604
708
  def expects_neither_new_or_cached_catalog
@@ -622,21 +726,13 @@ describe Puppet::Configurer do
622
726
  configurer.run
623
727
  end
624
728
 
625
- it "should not make a node request or pluginsync when a cached catalog is successfully retrieved" do
626
- expect(Puppet::Node.indirection).not_to receive(:find)
729
+ it "should not pluginsync when a cached catalog is successfully retrieved" do
627
730
  expects_cached_catalog_only(catalog)
628
731
  expect(configurer).not_to receive(:download_plugins)
629
732
 
630
733
  configurer.run
631
734
  end
632
735
 
633
- it "should make a node request and pluginsync when a cached catalog cannot be retrieved" do
634
- expect(Puppet::Node.indirection).to receive(:find).and_return(nil)
635
- expects_fallback_to_new_catalog(catalog)
636
-
637
- configurer.run
638
- end
639
-
640
736
  it "should set its cached_catalog_status to 'explicitly_requested'" do
641
737
  expects_cached_catalog_only(catalog)
642
738
 
@@ -672,7 +768,6 @@ describe Puppet::Configurer do
672
768
  it "should not attempt to retrieve a cached catalog again if the first attempt failed" do
673
769
  Puppet[:ignore_plugin_errors] = true
674
770
 
675
- expect(Puppet::Node.indirection).to receive(:find).and_return(nil)
676
771
  expects_neither_new_or_cached_catalog
677
772
  expects_pluginsync
678
773
 
@@ -728,16 +823,6 @@ describe Puppet::Configurer do
728
823
  Puppet.settings[:strict_environment_mode] = true
729
824
  end
730
825
 
731
- it "should not make a node request" do
732
- stub_request(:get, %r{/puppet/v3/file_metadatas?/plugins}).to_return(:status => 404)
733
- stub_request(:get, %r{/puppet/v3/file_metadatas?/pluginfacts}).to_return(:status => 404)
734
- expects_new_catalog_only(catalog)
735
-
736
- expect(Puppet::Node.indirection).not_to receive(:find)
737
-
738
- configurer.run
739
- end
740
-
741
826
  it "should return nil when the catalog's environment doesn't match the agent specified environment" do
742
827
  Puppet[:environment] = 'second_env'
743
828
  configurer = Puppet::Configurer.new
@@ -951,9 +1036,23 @@ describe Puppet::Configurer do
951
1036
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(apple, banana, banana)
952
1037
 
953
1038
  allow(Puppet).to receive(:notice)
1039
+ allow(Puppet).to receive(:push_context)
954
1040
  expect(Puppet).to receive(:notice).with("Local environment: 'production' doesn't match server specified environment 'apple', restarting agent run with environment 'apple'")
955
1041
  expect(Puppet).to receive(:notice).with("Local environment: 'apple' doesn't match server specified environment 'banana', restarting agent run with environment 'banana'")
956
1042
 
1043
+ expect(Puppet).to receive(:push_context).with(
1044
+ hash_including(current_environment: an_object_having_attributes(name: :production)),
1045
+ 'Local node environment production for configurer transaction'
1046
+ )
1047
+ expect(Puppet).to receive(:push_context).with(
1048
+ hash_including(current_environment: an_object_having_attributes(name: :apple)),
1049
+ 'Local node environment apple for configurer transaction'
1050
+ )
1051
+ expect(Puppet).to receive(:push_context).with(
1052
+ hash_including(current_environment: an_object_having_attributes(name: :banana)),
1053
+ 'Local node environment banana for configurer transaction'
1054
+ )
1055
+
957
1056
  configurer.run
958
1057
  end
959
1058
 
@@ -1110,20 +1209,132 @@ describe Puppet::Configurer do
1110
1209
  expect(configurer.run(options)).to eq(0)
1111
1210
  expect(options[:report].server_used).to be_nil
1112
1211
  end
1212
+ end
1113
1213
 
1114
- it "should not make multiple node requests when the server is found" do
1115
- Puppet.settings[:server_list] = ["myserver:123"]
1214
+ describe "when selecting an environment" do
1215
+ include PuppetSpec::Files
1216
+ include PuppetSpec::Settings
1116
1217
 
1117
- Puppet::Node.indirection.terminus_class = :rest
1118
- Puppet::Resource::Catalog.indirection.terminus_class = :rest
1218
+ describe "when the last used environment is available" do
1219
+ let(:last_server_specified_environment) { 'development' }
1119
1220
 
1120
- stub_request(:get, 'https://myserver:123/status/v1/simple/server').to_return(status: 200)
1121
- stub_request(:post, %r{https://myserver:123/puppet/v3/catalog}).to_return(status: 200)
1122
- node_request = stub_request(:get, %r{https://myserver:123/puppet/v3/node/}).to_return(status: 200)
1221
+ before do
1222
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1223
+ ---
1224
+ version:
1225
+ config: 1624882680
1226
+ puppet: 6.24.0
1227
+ application:
1228
+ initial_environment: #{Puppet[:environment]}
1229
+ converged_environment: #{last_server_specified_environment}
1230
+ run_mode: agent
1231
+ SUMMARY
1232
+ end
1123
1233
 
1124
- configurer.run
1234
+ it "prefers the environment set via cli" do
1235
+ Puppet.settings.handlearg('--environment', 'usethis')
1236
+ configurer.run
1237
+
1238
+ expect(configurer.environment).to eq('usethis')
1239
+ end
1240
+
1241
+ it "prefers the environment set via config" do
1242
+ FileUtils.mkdir_p(Puppet[:confdir])
1243
+ set_puppet_conf(Puppet[:confdir], <<~CONF)
1244
+ [main]
1245
+ environment = usethis
1246
+ CONF
1247
+
1248
+ Puppet.initialize_settings
1249
+ configurer.run
1250
+
1251
+ expect(configurer.environment).to eq('usethis')
1252
+ end
1253
+
1254
+ it "uses environment from Puppet[:environment] if given a catalog" do
1255
+ configurer.run(catalog: catalog)
1125
1256
 
1126
- expect(node_request).to have_been_requested.once
1257
+ expect(configurer.environment).to eq(Puppet[:environment])
1258
+ end
1259
+
1260
+ it "uses environment from Puppet[:environment] if use_cached_catalog = true" do
1261
+ Puppet[:use_cached_catalog] = true
1262
+ expects_cached_catalog_only(catalog)
1263
+ configurer.run
1264
+
1265
+ expect(configurer.environment).to eq(Puppet[:environment])
1266
+ end
1267
+
1268
+ describe "when the environment is not set via CLI" do
1269
+ it "uses the environment found in lastrunfile if the key exists" do
1270
+ configurer.run
1271
+
1272
+ expect(configurer.environment).to eq(last_server_specified_environment)
1273
+ end
1274
+
1275
+ it "uses environment from Puppet[:environment] if strict_environment_mode is set" do
1276
+ Puppet[:strict_environment_mode] = true
1277
+ configurer.run
1278
+
1279
+ expect(configurer.environment).to eq(Puppet[:environment])
1280
+ end
1281
+
1282
+ it "uses environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1283
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1284
+ ---
1285
+ version:
1286
+ config: 1624882680
1287
+ puppet: 6.24.0
1288
+ application:
1289
+ initial_environment: development
1290
+ converged_environment: development
1291
+ run_mode: agent
1292
+ SUMMARY
1293
+ configurer.run
1294
+
1295
+ expect(configurer.environment).to eq(Puppet[:environment])
1296
+ end
1297
+
1298
+ it "uses environment from Puppet[:environment] if the run mode doesn't match" do
1299
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1300
+ ---
1301
+ version:
1302
+ config: 1624882680
1303
+ puppet: 6.24.0
1304
+ application:
1305
+ initial_environment: #{Puppet[:environment]}
1306
+ converged_environment: #{last_server_specified_environment}
1307
+ run_mode: user
1308
+ SUMMARY
1309
+ configurer.run
1310
+
1311
+ expect(configurer.environment).to eq(Puppet[:environment])
1312
+ end
1313
+
1314
+ it "uses environment from Puppet[:environment] if lastrunfile is invalid YAML" do
1315
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1316
+ Key: 'this is my very very very ' +
1317
+ 'long string'
1318
+ SUMMARY
1319
+ configurer.run
1320
+
1321
+ expect(configurer.environment).to eq(Puppet[:environment])
1322
+ end
1323
+
1324
+ it "uses environment from Puppet[:environment] if lastrunfile exists but is empty" do
1325
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', '')
1326
+ configurer.run
1327
+
1328
+ expect(configurer.environment).to eq(Puppet[:environment])
1329
+ end
1330
+
1331
+ it "uses environment from Puppet[:environment] if the last used one cannot be found" do
1332
+ Puppet[:lastrunfile] = tmpfile('last_run_summary.yaml')
1333
+ configurer.run
1334
+
1335
+ expect(configurer.environment).to eq(Puppet[:environment])
1336
+ end
1337
+ end
1127
1338
  end
1128
1339
  end
1129
1340
  end