puppet 6.25.1-x86-mingw32 → 6.28.0-x86-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 (112) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +1 -1
  3. data/Gemfile +2 -2
  4. data/Gemfile.lock +101 -34
  5. data/lib/puppet/agent.rb +47 -11
  6. data/lib/puppet/application/agent.rb +2 -12
  7. data/lib/puppet/application/lookup.rb +74 -24
  8. data/lib/puppet/concurrent/thread_local_singleton.rb +5 -3
  9. data/lib/puppet/configurer.rb +8 -14
  10. data/lib/puppet/defaults.rb +13 -3
  11. data/lib/puppet/face/generate.rb +2 -0
  12. data/lib/puppet/file_serving/metadata.rb +3 -0
  13. data/lib/puppet/file_system/file_impl.rb +7 -7
  14. data/lib/puppet/file_system/jruby.rb +1 -1
  15. data/lib/puppet/file_system/windows.rb +4 -4
  16. data/lib/puppet/file_system.rb +1 -1
  17. data/lib/puppet/functions/next.rb +18 -1
  18. data/lib/puppet/functions/tree_each.rb +0 -1
  19. data/lib/puppet/functions/versioncmp.rb +6 -2
  20. data/lib/puppet/generate/type.rb +9 -0
  21. data/lib/puppet/http/client.rb +22 -2
  22. data/lib/puppet/node.rb +1 -1
  23. data/lib/puppet/pops/parser/code_merger.rb +4 -4
  24. data/lib/puppet/pops/parser/egrammar.ra +2 -0
  25. data/lib/puppet/pops/parser/eparser.rb +813 -794
  26. data/lib/puppet/pops/serialization/to_data_converter.rb +6 -18
  27. data/lib/puppet/provider/package/puppetserver_gem.rb +7 -16
  28. data/lib/puppet/provider/package/windows/exe_package.rb +30 -1
  29. data/lib/puppet/provider/package/windows/package.rb +2 -1
  30. data/lib/puppet/provider/package/windows.rb +14 -1
  31. data/lib/puppet/provider/service/init.rb +5 -4
  32. data/lib/puppet/provider/user/directoryservice.rb +5 -0
  33. data/lib/puppet/ssl/ssl_provider.rb +75 -19
  34. data/lib/puppet/ssl/state_machine.rb +13 -17
  35. data/lib/puppet/ssl/verifier.rb +6 -0
  36. data/lib/puppet/transaction/persistence.rb +22 -12
  37. data/lib/puppet/type/exec.rb +1 -1
  38. data/lib/puppet/type/file/data_sync.rb +1 -1
  39. data/lib/puppet/type/user.rb +43 -38
  40. data/lib/puppet/util/json.rb +17 -0
  41. data/lib/puppet/util/log.rb +7 -2
  42. data/lib/puppet/util/monkey_patches.rb +6 -2
  43. data/lib/puppet/util/package.rb +25 -16
  44. data/lib/puppet/util/yaml.rb +21 -2
  45. data/lib/puppet/util.rb +1 -2
  46. data/lib/puppet/version.rb +1 -1
  47. data/lib/puppet.rb +2 -14
  48. data/locales/puppet.pot +5 -10454
  49. data/man/man5/puppet.conf.5 +21 -2
  50. data/man/man8/puppet-agent.8 +1 -1
  51. data/man/man8/puppet-apply.8 +1 -1
  52. data/man/man8/puppet-catalog.8 +1 -1
  53. data/man/man8/puppet-config.8 +1 -1
  54. data/man/man8/puppet-describe.8 +1 -1
  55. data/man/man8/puppet-device.8 +1 -1
  56. data/man/man8/puppet-doc.8 +1 -1
  57. data/man/man8/puppet-epp.8 +1 -1
  58. data/man/man8/puppet-facts.8 +1 -1
  59. data/man/man8/puppet-filebucket.8 +1 -1
  60. data/man/man8/puppet-generate.8 +1 -1
  61. data/man/man8/puppet-help.8 +1 -1
  62. data/man/man8/puppet-key.8 +1 -1
  63. data/man/man8/puppet-lookup.8 +9 -6
  64. data/man/man8/puppet-man.8 +1 -1
  65. data/man/man8/puppet-module.8 +1 -1
  66. data/man/man8/puppet-node.8 +1 -1
  67. data/man/man8/puppet-parser.8 +1 -1
  68. data/man/man8/puppet-plugin.8 +1 -1
  69. data/man/man8/puppet-report.8 +1 -1
  70. data/man/man8/puppet-resource.8 +1 -1
  71. data/man/man8/puppet-script.8 +1 -1
  72. data/man/man8/puppet-ssl.8 +1 -1
  73. data/man/man8/puppet-status.8 +1 -1
  74. data/man/man8/puppet.8 +2 -2
  75. data/spec/fixtures/unit/forge/bacula.json +1 -1
  76. data/spec/integration/application/agent_spec.rb +108 -0
  77. data/spec/integration/application/lookup_spec.rb +81 -50
  78. data/spec/integration/application/resource_spec.rb +6 -2
  79. data/spec/integration/http/client_spec.rb +51 -4
  80. data/spec/lib/puppet_spec/https.rb +1 -1
  81. data/spec/lib/puppet_spec/puppetserver.rb +39 -2
  82. data/spec/shared_contexts/l10n.rb +5 -0
  83. data/spec/unit/agent_spec.rb +28 -2
  84. data/spec/unit/application/agent_spec.rb +26 -16
  85. data/spec/unit/application/lookup_spec.rb +131 -10
  86. data/spec/unit/concurrent/thread_local_singleton_spec.rb +39 -0
  87. data/spec/unit/configurer_spec.rb +124 -61
  88. data/spec/unit/daemon_spec.rb +2 -11
  89. data/spec/unit/face/generate_spec.rb +64 -0
  90. data/spec/unit/file_system_spec.rb +34 -4
  91. data/spec/unit/forge/module_release_spec.rb +3 -3
  92. data/spec/unit/functions/versioncmp_spec.rb +40 -4
  93. data/spec/unit/http/client_spec.rb +18 -0
  94. data/spec/unit/node_spec.rb +6 -0
  95. data/spec/unit/pops/parser/parse_containers_spec.rb +2 -2
  96. data/spec/unit/pops/serialization/to_from_hr_spec.rb +0 -58
  97. data/spec/unit/pops/validator/validator_spec.rb +5 -0
  98. data/spec/unit/provider/package/puppetserver_gem_spec.rb +2 -2
  99. data/spec/unit/provider/package/windows/exe_package_spec.rb +17 -0
  100. data/spec/unit/provider/service/gentoo_spec.rb +6 -5
  101. data/spec/unit/provider/service/init_spec.rb +15 -9
  102. data/spec/unit/provider/service/openwrt_spec.rb +21 -29
  103. data/spec/unit/provider/service/redhat_spec.rb +3 -2
  104. data/spec/unit/ssl/ssl_provider_spec.rb +75 -1
  105. data/spec/unit/ssl/state_machine_spec.rb +1 -0
  106. data/spec/unit/transaction/persistence_spec.rb +51 -0
  107. data/spec/unit/type/user_spec.rb +0 -45
  108. data/spec/unit/util/json_spec.rb +126 -0
  109. data/spec/unit/util/windows_spec.rb +23 -0
  110. data/spec/unit/util/yaml_spec.rb +54 -29
  111. data/tasks/generate_cert_fixtures.rake +5 -4
  112. metadata +9 -3
@@ -518,34 +518,155 @@ Searching for "a"
518
518
  end
519
519
 
520
520
  it 'receives extra facts in top scope' do
521
- file_path = tmpdir('lookup_spec')
522
- filename = File.join(file_path, "facts.yaml")
523
- File.open(filename, "w+") { |f| f.write(<<-YAML.unindent) }
521
+ file_path = file_containing('facts.yaml', <<~CONTENT)
524
522
  ---
525
523
  cx: ' C from facts'
526
- YAML
524
+ CONTENT
527
525
 
528
526
  lookup.options[:node] = node
529
- lookup.options[:fact_file] = filename
527
+ lookup.options[:fact_file] = file_path
530
528
  lookup.options[:render_as] = :s
531
529
  allow(lookup.command_line).to receive(:args).and_return(['c'])
532
530
  expect(run_lookup(lookup)).to eql("This is C from facts")
533
531
  end
534
532
 
535
533
  it 'receives extra facts in the facts hash' do
536
- file_path = tmpdir('lookup_spec')
537
- filename = File.join(file_path, "facts.yaml")
538
- File.open(filename, "w+") { |f| f.write(<<-YAML.unindent) }
534
+ file_path = file_containing('facts.yaml', <<~CONTENT)
539
535
  ---
540
536
  cx: ' G from facts'
541
- YAML
537
+ CONTENT
542
538
 
543
539
  lookup.options[:node] = node
544
- lookup.options[:fact_file] = filename
540
+ lookup.options[:fact_file] = file_path
545
541
  lookup.options[:render_as] = :s
546
542
  allow(lookup.command_line).to receive(:args).and_return(['g'])
547
543
  expect(run_lookup(lookup)).to eql("This is G from facts in facts hash")
548
544
  end
545
+
546
+ describe 'when retrieving given facts' do
547
+ before do
548
+ lookup.options[:node] = node
549
+ allow(lookup.command_line).to receive(:args).and_return(['g'])
550
+ end
551
+
552
+ it 'loads files with yaml extension as yaml on first try' do
553
+ file_path = file_containing('facts.yaml', <<~CONTENT)
554
+ ---
555
+ cx: ' G from facts'
556
+ CONTENT
557
+ lookup.options[:fact_file] = file_path
558
+
559
+ expect(Puppet::Util::Yaml).to receive(:safe_load_file).with(file_path, []).and_call_original
560
+ run_lookup(lookup)
561
+ end
562
+
563
+ it 'loads files with yml extension as yaml on first try' do
564
+ file_path = file_containing('facts.yml', <<~CONTENT)
565
+ ---
566
+ cx: ' G from facts'
567
+ CONTENT
568
+ lookup.options[:fact_file] = file_path
569
+
570
+ expect(Puppet::Util::Yaml).to receive(:safe_load_file).with(file_path, []).and_call_original
571
+ run_lookup(lookup)
572
+ end
573
+
574
+ it 'loads files with json extension as json on first try' do
575
+ file_path = file_containing('facts.json', <<~CONTENT)
576
+ {
577
+ "cx": " G from facts"
578
+ }
579
+ CONTENT
580
+ lookup.options[:fact_file] = file_path
581
+
582
+ expect(Puppet::Util::Json).to receive(:load_file).with(file_path, {}).and_call_original
583
+ run_lookup(lookup)
584
+ end
585
+
586
+ it 'detects file format accordingly even with random file extension' do
587
+ file_path = file_containing('facts.txt', <<~CONTENT)
588
+ {
589
+ "cx": " G from facts"
590
+ }
591
+ CONTENT
592
+ lookup.options[:fact_file] = file_path
593
+
594
+ expect(Puppet::Util::Json).to receive(:load_file_if_valid).with(file_path).and_call_original
595
+ expect(Puppet::Util::Yaml).not_to receive(:safe_load_file_if_valid).with(file_path)
596
+ run_lookup(lookup)
597
+ end
598
+
599
+ it 'detects file without extension as json due to valid contents' do
600
+ file_path = file_containing('facts', <<~CONTENT)
601
+ {
602
+ "cx": " G from facts"
603
+ }
604
+ CONTENT
605
+ lookup.options[:fact_file] = file_path
606
+
607
+ expect(Puppet::Util::Json).to receive(:load_file_if_valid).with(file_path).and_call_original
608
+ expect(Puppet::Util::Yaml).not_to receive(:safe_load_file_if_valid).with(file_path)
609
+ run_lookup(lookup)
610
+ end
611
+
612
+ it 'detects file without extension as yaml due to valid contents' do
613
+ file_path = file_containing('facts', <<~CONTENT)
614
+ ---
615
+ cx: ' G from facts'
616
+ CONTENT
617
+ lookup.options[:fact_file] = file_path
618
+
619
+ expect(Puppet::Util::Json.load_file_if_valid(file_path)).to be_nil
620
+ expect(Puppet::Util::Yaml).to receive(:safe_load_file_if_valid).with(file_path).and_call_original
621
+ run_lookup(lookup)
622
+ end
623
+
624
+ it 'raises error due to invalid contents' do
625
+ file_path = file_containing('facts.yml', <<~CONTENT)
626
+ INVALID CONTENT
627
+ CONTENT
628
+ lookup.options[:fact_file] = file_path
629
+
630
+ expect {
631
+ lookup.run_command
632
+ }.to raise_error(/Incorrectly formatted data in .+ given via the --facts flag \(only accepts yaml and json files\)/)
633
+ end
634
+
635
+ it "fails when a node doesn't have facts" do
636
+ lookup.options[:node] = "bad.node"
637
+ allow(lookup.command_line).to receive(:args).and_return(['c'])
638
+
639
+ expected_error = "No facts available for target node: #{lookup.options[:node]}"
640
+ expect { lookup.run_command }.to raise_error(RuntimeError, expected_error)
641
+ end
642
+
643
+ it 'raises error due to missing trusted information facts in --facts file' do
644
+ file_path = file_containing('facts.yaml', <<~CONTENT)
645
+ ---
646
+ fqdn: some.fqdn.com
647
+ CONTENT
648
+ lookup.options[:fact_file] = file_path
649
+
650
+ expect {
651
+ lookup.run_command
652
+ }.to raise_error(/When overriding any of the hostname,domain,fqdn,clientcert facts with #{file_path} given via the --facts flag, they must all be overridden./)
653
+ end
654
+
655
+ it 'does not fail when all trusted information facts are provided via --facts file' do
656
+ file_path = file_containing('facts.yaml', <<~CONTENT)
657
+ ---
658
+ fqdn: some.fqdn.com
659
+ hostname: some.hostname
660
+ domain: some.domain
661
+ clientcert: some.clientcert
662
+ CONTENT
663
+ lookup.options[:fact_file] = file_path
664
+
665
+ expect {
666
+ lookup.run_command
667
+ }.to exit_with(0)
668
+ end
669
+ end
549
670
  end
550
671
 
551
672
  context 'using a puppet function as data provider' do
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'puppet/concurrent/thread_local_singleton'
3
+
4
+ class PuppetSpec::Singleton
5
+ extend Puppet::Concurrent::ThreadLocalSingleton
6
+ end
7
+
8
+ # Use the `equal?` matcher to ensure we get the same object
9
+ describe Puppet::Concurrent::ThreadLocalSingleton do
10
+ it 'returns the same object for a single thread' do
11
+ expect(PuppetSpec::Singleton.singleton).to equal(PuppetSpec::Singleton.singleton)
12
+ end
13
+
14
+ it 'is not inherited for a newly created thread' do
15
+ main_thread_local = PuppetSpec::Singleton.singleton
16
+ Thread.new do
17
+ expect(main_thread_local).to_not equal(PuppetSpec::Singleton.singleton)
18
+ end.join
19
+ end
20
+
21
+ it 'does not leak outside a thread' do
22
+ thread_local = nil
23
+ Thread.new do
24
+ thread_local = PuppetSpec::Singleton.singleton
25
+ end.join
26
+ expect(thread_local).to_not equal(PuppetSpec::Singleton.singleton)
27
+ end
28
+
29
+ it 'is different for each thread' do
30
+ locals = []
31
+ Thread.new do
32
+ locals << PuppetSpec::Singleton.singleton
33
+ end.join
34
+ Thread.new do
35
+ locals << PuppetSpec::Singleton.singleton
36
+ end.join
37
+ expect(locals.first).to_not equal(locals.last)
38
+ end
39
+ end
@@ -9,9 +9,6 @@ describe Puppet::Configurer do
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,10 +75,44 @@ describe Puppet::Configurer do
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
@@ -1128,88 +1159,120 @@ describe Puppet::Configurer do
1128
1159
  converged_environment: #{last_server_specified_environment}
1129
1160
  run_mode: agent
1130
1161
  SUMMARY
1162
+ end
1131
1163
 
1132
- expect(Puppet::Node.indirection).not_to receive(:find)
1164
+ describe "when the use_last_environment is set to true" do
1165
+ before do
1166
+ expect(Puppet::Node.indirection).not_to receive(:find)
1133
1167
  .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1134
- end
1168
+ end
1135
1169
 
1136
- it "prefers the environment set via cli" do
1137
- Puppet.settings.handlearg('--environment', 'usethis')
1138
- configurer.run
1170
+ it "prefers the environment set via cli" do
1171
+ Puppet.settings.handlearg('--environment', 'usethis')
1172
+ configurer.run
1139
1173
 
1140
- expect(configurer.environment).to eq('usethis')
1141
- end
1174
+ expect(configurer.environment).to eq('usethis')
1175
+ end
1142
1176
 
1143
- it "prefers the environment set via lastrunfile over config" do
1144
- FileUtils.mkdir_p(Puppet[:confdir])
1145
- set_puppet_conf(Puppet[:confdir], <<~CONF)
1146
- [main]
1147
- environment = usethis
1148
- lastrunfile = #{Puppet[:lastrunfile]}
1149
- CONF
1177
+ it "prefers the environment set via lastrunfile over config" do
1178
+ FileUtils.mkdir_p(Puppet[:confdir])
1179
+ set_puppet_conf(Puppet[:confdir], <<~CONF)
1180
+ [main]
1181
+ environment = usethis
1182
+ lastrunfile = #{Puppet[:lastrunfile]}
1183
+ CONF
1150
1184
 
1151
- Puppet.initialize_settings
1152
- configurer.run
1185
+ Puppet.initialize_settings
1186
+ configurer.run
1153
1187
 
1154
- expect(configurer.environment).to eq(last_server_specified_environment)
1155
- end
1188
+ expect(configurer.environment).to eq(last_server_specified_environment)
1189
+ end
1156
1190
 
1157
- it "uses the environment from Puppet[:environment] if given a catalog" do
1158
- configurer.run(catalog: catalog)
1191
+ it "uses the environment from Puppet[:environment] if given a catalog" do
1192
+ configurer.run(catalog: catalog)
1159
1193
 
1160
- expect(configurer.environment).to eq(Puppet[:environment])
1161
- end
1194
+ expect(configurer.environment).to eq(Puppet[:environment])
1195
+ end
1162
1196
 
1163
- it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1164
- Puppet[:use_cached_catalog] = true
1165
- expects_cached_catalog_only(catalog)
1166
- configurer.run
1197
+ it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1198
+ Puppet[:use_cached_catalog] = true
1199
+ expects_cached_catalog_only(catalog)
1200
+ configurer.run
1167
1201
 
1168
- expect(configurer.environment).to eq(Puppet[:environment])
1169
- end
1202
+ expect(configurer.environment).to eq(Puppet[:environment])
1203
+ end
1170
1204
 
1171
- describe "when the environment is not set via CLI" do
1172
- it "uses the environment found in lastrunfile if the key exists" do
1173
- configurer.run
1205
+ describe "when the environment is not set via CLI" do
1206
+ it "uses the environment found in lastrunfile if the key exists" do
1207
+ configurer.run
1174
1208
 
1175
- expect(configurer.environment).to eq(last_server_specified_environment)
1209
+ expect(configurer.environment).to eq(last_server_specified_environment)
1210
+ end
1211
+
1212
+ it "pushes the converged environment found in lastrunfile over the existing context" do
1213
+ initial_env = Puppet::Node::Environment.remote('production')
1214
+ Puppet.push_context(
1215
+ current_environment: initial_env,
1216
+ loaders: Puppet::Pops::Loaders.new(initial_env, true))
1217
+
1218
+ expect(Puppet).to receive(:push_context).with(
1219
+ hash_including(:current_environment, :loaders),
1220
+ "Local node environment #{last_server_specified_environment} for configurer transaction"
1221
+ ).once.and_call_original
1222
+
1223
+ configurer.run
1224
+ end
1225
+
1226
+ it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1227
+ Puppet[:strict_environment_mode] = true
1228
+ configurer.run
1229
+
1230
+ expect(configurer.environment).to eq(Puppet[:environment])
1231
+ end
1232
+
1233
+ it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1234
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1235
+ ---
1236
+ version:
1237
+ config: 1624882680
1238
+ puppet: 6.24.0
1239
+ application:
1240
+ initial_environment: development
1241
+ converged_environment: development
1242
+ run_mode: agent
1243
+ SUMMARY
1244
+ configurer.run
1245
+
1246
+ expect(configurer.environment).to eq(Puppet[:environment])
1247
+ end
1176
1248
  end
1249
+ end
1177
1250
 
1178
- it "pushes the converged environment found in lastrunfile over the existing context" do
1179
- initial_env = Puppet::Node::Environment.remote('production')
1180
- Puppet.push_context(
1181
- current_environment: initial_env,
1182
- loaders: Puppet::Pops::Loaders.new(initial_env, true))
1251
+ describe "when the use_last_environment setting is set to false" do
1252
+ let(:node_environment) { Puppet::Node::Environment.remote(:salam) }
1253
+ let(:node) { Puppet::Node.new(Puppet[:node_name_value]) }
1183
1254
 
1184
- expect(Puppet).to receive(:push_context).with(
1185
- hash_including(:current_environment, :loaders),
1186
- "Local node environment #{last_server_specified_environment} for configurer transaction"
1187
- ).once.and_call_original
1255
+ before do
1256
+ Puppet[:use_last_environment] = false
1257
+ node.environment = node_environment
1188
1258
 
1189
- configurer.run
1259
+ allow(Puppet::Node.indirection).to receive(:find)
1260
+ allow(Puppet::Node.indirection).to receive(:find)
1261
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1262
+ .and_return(node)
1190
1263
  end
1191
1264
 
1192
- it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1193
- Puppet[:strict_environment_mode] = true
1194
- configurer.run
1265
+ it "does a node request" do
1266
+ expect(Puppet::Node.indirection).to receive(:find)
1267
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1195
1268
 
1196
- expect(configurer.environment).to eq(Puppet[:environment])
1269
+ configurer.run
1197
1270
  end
1198
1271
 
1199
- it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1200
- Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1201
- ---
1202
- version:
1203
- config: 1624882680
1204
- puppet: 6.24.0
1205
- application:
1206
- initial_environment: development
1207
- converged_environment: development
1208
- run_mode: agent
1209
- SUMMARY
1272
+ it "uses the node environment from the node request" do
1210
1273
  configurer.run
1211
1274
 
1212
- expect(configurer.environment).to eq(Puppet[:environment])
1275
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1213
1276
  end
1214
1277
  end
1215
1278
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'puppet/daemon'
3
3
  require 'puppet/agent'
4
+ require 'puppet/configurer'
4
5
 
5
6
  def without_warnings
6
7
  flag = $VERBOSE
@@ -9,12 +10,6 @@ def without_warnings
9
10
  $VERBOSE = flag
10
11
  end
11
12
 
12
- class TestClient
13
- def lockfile_path
14
- "/dev/null"
15
- end
16
- end
17
-
18
13
  describe Puppet::Daemon, :unless => Puppet::Util::Platform.windows? do
19
14
  include PuppetSpec::Files
20
15
 
@@ -26,7 +21,7 @@ describe Puppet::Daemon, :unless => Puppet::Util::Platform.windows? do
26
21
  end
27
22
  end
28
23
 
29
- let(:agent) { Puppet::Agent.new(TestClient.new, false) }
24
+ let(:agent) { Puppet::Agent.new(Puppet::Configurer, false) }
30
25
  let(:server) { double("Server", :start => nil, :wait_for_shutdown => nil) }
31
26
 
32
27
  let(:pidfile) { double("PidFile", :lock => true, :unlock => true, :file_path => 'fake.pid') }
@@ -131,10 +126,6 @@ describe Puppet::Daemon, :unless => Puppet::Util::Platform.windows? do
131
126
  end
132
127
 
133
128
  describe "when reloading" do
134
- it "should do nothing if no agent is configured" do
135
- daemon.reload
136
- end
137
-
138
129
  it "should do nothing if the agent is running" do
139
130
  expect(agent).to receive(:run).with({:splay => false}).and_raise(Puppet::LockError, 'Failed to aquire lock')
140
131
  expect(Puppet).to receive(:notice).with('Not triggering already-running agent')
@@ -221,6 +221,70 @@ describe Puppet::Face[:generate, :current] do
221
221
  end
222
222
 
223
223
  end
224
+
225
+ context "in an environment with a faulty type" do
226
+ let(:dir) do
227
+ dir_containing('environments', { 'testing_generate2' => {
228
+ 'environment.conf' => "modulepath = modules",
229
+ 'manifests' => { 'site.pp' => "" },
230
+ 'modules' => {
231
+ 'm3' => {
232
+ 'lib' => { 'puppet' => { 'type' => {
233
+ 'test3.rb' => <<-EOF
234
+ module Puppet
235
+ Type.newtype(:test3) do
236
+ @doc = "Docs for resource"
237
+ def self.title_patterns
238
+ identity = lambda {|x| x}
239
+ [
240
+ [
241
+ /^(.*)_(.*)$/,
242
+ [
243
+ [:name, identity ]
244
+ ]
245
+ ]
246
+ ]
247
+ end
248
+ newproperty(:message) do
249
+ desc "Docs for 'message' property"
250
+ end
251
+ newparam(:name) do
252
+ desc "Docs for 'name' parameter"
253
+ isnamevar
254
+ end
255
+ end; end
256
+ EOF
257
+ } }
258
+ }
259
+ }
260
+ }}})
261
+ end
262
+
263
+ let(:modulepath) do
264
+ File.join(dir, 'testing_generate2', 'modules')
265
+ end
266
+
267
+ let(:m3) do
268
+ File.join(modulepath, 'm3')
269
+ end
270
+
271
+ around(:each) do |example|
272
+ Puppet.settings.initialize_global_settings
273
+ Puppet[:manifest] = ''
274
+ loader = Puppet::Environments::Directories.new(dir, [])
275
+ Puppet.override(:environments => loader) do
276
+ Puppet.override(:current_environment => loader.get('testing_generate2')) do
277
+ example.run
278
+ end
279
+ end
280
+ end
281
+
282
+ it 'fails when using procs for title patterns' do
283
+ expect {
284
+ genface.types(:format => 'pcore')
285
+ }.to exit_with(1)
286
+ end
287
+ end
224
288
  end
225
289
 
226
290
  def from_an_interactive_terminal
@@ -984,11 +984,12 @@ describe "Puppet::FileSystem" do
984
984
  end
985
985
 
986
986
  it 'preserves file ownership' do
987
- allow(Puppet::FileSystem).to receive(:lstat)
988
- .with(Puppet::FileSystem.pathname(dest))
989
- .and_return(double(uid: 1, gid: 2))
987
+ FileUtils.touch(dest)
988
+ allow(File).to receive(:lstat).and_call_original
989
+ allow(File).to receive(:lstat).with(Pathname.new(dest)).and_return(double(uid: 1, gid: 2, 'directory?': false))
990
990
 
991
- expect(FileUtils).to receive(:chown).with(1, 2, /#{dest}/)
991
+ allow(File).to receive(:chown).and_call_original
992
+ expect(FileUtils).to receive(:chown).with(1, 2, any_args)
992
993
 
993
994
  Puppet::FileSystem.replace_file(dest, 0644) { |f| f.write(content) }
994
995
  end
@@ -1163,4 +1164,33 @@ describe "Puppet::FileSystem" do
1163
1164
  expect(File.mtime(dest)).to be_within(1).of(tomorrow)
1164
1165
  end
1165
1166
  end
1167
+
1168
+ context '#chmod' do
1169
+ let(:dest) { tmpfile('abs_file') }
1170
+
1171
+ it "changes the mode given an absolute string" do
1172
+ Puppet::FileSystem.touch(dest)
1173
+ Puppet::FileSystem.chmod(0644, dest)
1174
+ expect(File.stat(dest).mode & 0777).to eq(0644)
1175
+ end
1176
+
1177
+ it "returns true if given an absolute pathname" do
1178
+ Puppet::FileSystem.touch(dest)
1179
+ Puppet::FileSystem.chmod(0644, Pathname.new(dest))
1180
+ expect(File.stat(dest).mode & 0777).to eq(0644)
1181
+ end
1182
+
1183
+ it "raises if the file doesn't exist" do
1184
+ klass = Puppet::Util::Platform.windows? ? Puppet::Error : Errno::ENOENT
1185
+ expect {
1186
+ Puppet::FileSystem.chmod(0644, dest)
1187
+ }.to raise_error(klass)
1188
+ end
1189
+
1190
+ it "raises ArgumentError if dest is invalid" do
1191
+ expect {
1192
+ Puppet::FileSystem.chmod(0644, nil)
1193
+ }.to raise_error(ArgumentError, /expected Pathname, got: 'NilClass'/)
1194
+ end
1195
+ end
1166
1196
  end
@@ -90,7 +90,7 @@ describe Puppet::Forge::ModuleRelease do
90
90
  "checksums": { },
91
91
  "version": "#{module_version}",
92
92
  "description": "Standard Library for Puppet Modules",
93
- "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
93
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
94
94
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
95
95
  "summary": "Puppet Module Standard Library",
96
96
  "dependencies": [
@@ -204,7 +204,7 @@ describe Puppet::Forge::ModuleRelease do
204
204
  "checksums": { },
205
205
  "version": "#{module_version}",
206
206
  "description": "Standard Library for Puppet Modules",
207
- "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
207
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
208
208
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
209
209
  "summary": "Puppet Module Standard Library",
210
210
  "author": "#{module_author}",
@@ -279,7 +279,7 @@ describe Puppet::Forge::ModuleRelease do
279
279
  "checksums": { },
280
280
  "version": "#{module_version}",
281
281
  "description": "Standard Library for Puppet Modules",
282
- "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
282
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
283
283
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
284
284
  "summary": "Puppet Module Standard Library",
285
285
  "dependencies": [