puppet 7.11.0-universal-darwin → 7.14.0-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +1 -1
  3. data/Gemfile +2 -2
  4. data/Gemfile.lock +24 -19
  5. data/ext/project_data.yaml +1 -1
  6. data/lib/puppet/application/lookup.rb +78 -24
  7. data/lib/puppet/concurrent/thread_local_singleton.rb +5 -3
  8. data/lib/puppet/configurer.rb +74 -25
  9. data/lib/puppet/defaults.rb +20 -1
  10. data/lib/puppet/face/generate.rb +2 -0
  11. data/lib/puppet/file_serving/metadata.rb +3 -0
  12. data/lib/puppet/file_system/file_impl.rb +7 -7
  13. data/lib/puppet/file_system/jruby.rb +1 -1
  14. data/lib/puppet/file_system/path_pattern.rb +10 -15
  15. data/lib/puppet/file_system/uniquefile.rb +1 -1
  16. data/lib/puppet/file_system/windows.rb +4 -4
  17. data/lib/puppet/file_system.rb +3 -2
  18. data/lib/puppet/functions/versioncmp.rb +6 -2
  19. data/lib/puppet/generate/type.rb +9 -0
  20. data/lib/puppet/graph/simple_graph.rb +2 -1
  21. data/lib/puppet/http/client.rb +1 -1
  22. data/lib/puppet/http/redirector.rb +5 -0
  23. data/lib/puppet/node.rb +1 -1
  24. data/lib/puppet/parser/resource.rb +1 -1
  25. data/lib/puppet/pops/evaluator/closure.rb +7 -5
  26. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +1 -0
  27. data/lib/puppet/pops/parser/code_merger.rb +4 -4
  28. data/lib/puppet/pops/parser/egrammar.ra +2 -0
  29. data/lib/puppet/pops/parser/eparser.rb +574 -558
  30. data/lib/puppet/pops/serialization/to_data_converter.rb +6 -18
  31. data/lib/puppet/pops/validation/checker4_0.rb +7 -2
  32. data/lib/puppet/provider/package/pkg.rb +10 -0
  33. data/lib/puppet/provider/service/init.rb +5 -4
  34. data/lib/puppet/provider/user/useradd.rb +20 -0
  35. data/lib/puppet/resource/catalog.rb +1 -1
  36. data/lib/puppet/resource/type_collection.rb +21 -17
  37. data/lib/puppet/resource.rb +38 -5
  38. data/lib/puppet/ssl/verifier.rb +3 -1
  39. data/lib/puppet/transaction/persistence.rb +22 -12
  40. data/lib/puppet/type/file/data_sync.rb +1 -1
  41. data/lib/puppet/type/file/group.rb +8 -1
  42. data/lib/puppet/type/file/owner.rb +8 -1
  43. data/lib/puppet/type/service.rb +8 -3
  44. data/lib/puppet/type/user.rb +41 -39
  45. data/lib/puppet/util/autoload.rb +1 -1
  46. data/lib/puppet/util/json.rb +20 -0
  47. data/lib/puppet/util/log.rb +7 -2
  48. data/lib/puppet/util/monkey_patches.rb +26 -2
  49. data/lib/puppet/util/package.rb +25 -16
  50. data/lib/puppet/util/windows/service.rb +0 -5
  51. data/lib/puppet/util/windows.rb +3 -0
  52. data/lib/puppet/util/yaml.rb +16 -1
  53. data/lib/puppet/version.rb +1 -1
  54. data/lib/puppet.rb +1 -0
  55. data/locales/puppet.pot +5 -9737
  56. data/man/man5/puppet.conf.5 +21 -2
  57. data/man/man8/puppet-agent.8 +1 -1
  58. data/man/man8/puppet-apply.8 +1 -1
  59. data/man/man8/puppet-catalog.8 +1 -1
  60. data/man/man8/puppet-config.8 +1 -1
  61. data/man/man8/puppet-describe.8 +1 -1
  62. data/man/man8/puppet-device.8 +1 -1
  63. data/man/man8/puppet-doc.8 +1 -1
  64. data/man/man8/puppet-epp.8 +1 -1
  65. data/man/man8/puppet-facts.8 +1 -1
  66. data/man/man8/puppet-filebucket.8 +1 -1
  67. data/man/man8/puppet-generate.8 +1 -1
  68. data/man/man8/puppet-help.8 +1 -1
  69. data/man/man8/puppet-lookup.8 +9 -6
  70. data/man/man8/puppet-module.8 +1 -1
  71. data/man/man8/puppet-node.8 +1 -1
  72. data/man/man8/puppet-parser.8 +1 -1
  73. data/man/man8/puppet-plugin.8 +1 -1
  74. data/man/man8/puppet-report.8 +1 -1
  75. data/man/man8/puppet-resource.8 +1 -1
  76. data/man/man8/puppet-script.8 +1 -1
  77. data/man/man8/puppet-ssl.8 +1 -1
  78. data/man/man8/puppet.8 +2 -2
  79. data/spec/fixtures/integration/application/agent/cached_deferred_catalog.json +2 -1
  80. data/spec/fixtures/unit/forge/bacula.json +1 -1
  81. data/spec/integration/application/agent_spec.rb +28 -0
  82. data/spec/integration/application/lookup_spec.rb +32 -6
  83. data/spec/integration/parser/pcore_resource_spec.rb +20 -0
  84. data/spec/shared_contexts/l10n.rb +5 -0
  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 +167 -60
  88. data/spec/unit/face/generate_spec.rb +64 -0
  89. data/spec/unit/file_system/uniquefile_spec.rb +7 -1
  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 +58 -1
  94. data/spec/unit/network/formats_spec.rb +6 -0
  95. data/spec/unit/node_spec.rb +6 -0
  96. data/spec/unit/pops/parser/parse_containers_spec.rb +2 -2
  97. data/spec/unit/pops/serialization/to_from_hr_spec.rb +0 -58
  98. data/spec/unit/pops/validator/validator_spec.rb +5 -0
  99. data/spec/unit/provider/package/pkg_spec.rb +15 -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/provider/user/useradd_spec.rb +40 -0
  105. data/spec/unit/resource/catalog_spec.rb +14 -1
  106. data/spec/unit/resource_spec.rb +58 -2
  107. data/spec/unit/transaction/persistence_spec.rb +51 -0
  108. data/spec/unit/type/file/group_spec.rb +7 -0
  109. data/spec/unit/type/file/owner_spec.rb +7 -0
  110. data/spec/unit/type/service_spec.rb +27 -0
  111. data/spec/unit/type/user_spec.rb +67 -45
  112. data/spec/unit/util/autoload_spec.rb +25 -8
  113. data/spec/unit/util/json_spec.rb +126 -0
  114. data/spec/unit/util/yaml_spec.rb +37 -13
  115. metadata +15 -5
@@ -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
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
  require 'puppet/configurer'
3
3
 
4
4
  describe Puppet::Configurer do
5
+ include PuppetSpec::Files
6
+
5
7
  before do
6
8
  Puppet[:server] = "puppetmaster"
7
9
  Puppet[:report] = true
@@ -10,6 +12,17 @@ describe Puppet::Configurer do
10
12
  allow_any_instance_of(described_class).to(
11
13
  receive(:valid_server_environment?).and_return(true)
12
14
  )
15
+
16
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
17
+ ---
18
+ version:
19
+ config: 1624882680
20
+ puppet: #{Puppet.version}
21
+ application:
22
+ initial_environment: #{Puppet[:environment]}
23
+ converged_environment: #{Puppet[:environment]}
24
+ run_mode: agent
25
+ SUMMARY
13
26
  end
14
27
 
15
28
  let(:node_name) { Puppet[:node_name_value] }
@@ -866,7 +879,7 @@ describe Puppet::Configurer do
866
879
  expect(configurer.run).to be_nil
867
880
  end
868
881
 
869
- it "should proceed with the cached catalog if its environment matchs the local environment" do
882
+ it "should proceed with the cached catalog if its environment matches the local environment" do
870
883
  expects_cached_catalog_only(catalog)
871
884
 
872
885
  expect(configurer.run).to eq(0)
@@ -1222,7 +1235,6 @@ describe Puppet::Configurer do
1222
1235
  end
1223
1236
 
1224
1237
  describe "when selecting an environment" do
1225
- include PuppetSpec::Files
1226
1238
  include PuppetSpec::Settings
1227
1239
 
1228
1240
  describe "when the last used environment is available" do
@@ -1241,104 +1253,199 @@ describe Puppet::Configurer do
1241
1253
  SUMMARY
1242
1254
  end
1243
1255
 
1244
- it "prefers the environment set via cli" do
1245
- Puppet.settings.handlearg('--environment', 'usethis')
1246
- configurer.run
1256
+ describe "when the use_last_environment is set to true" do
1257
+ before do
1258
+ expect(Puppet::Node.indirection).not_to receive(:find)
1259
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1260
+ end
1247
1261
 
1248
- expect(configurer.environment).to eq('usethis')
1249
- end
1262
+ it "prefers the environment set via cli" do
1263
+ Puppet.settings.handlearg('--environment', 'usethis')
1264
+ configurer.run
1250
1265
 
1251
- it "prefers the environment set via config" do
1252
- FileUtils.mkdir_p(Puppet[:confdir])
1253
- set_puppet_conf(Puppet[:confdir], <<~CONF)
1254
- [main]
1255
- environment = usethis
1256
- CONF
1266
+ expect(configurer.environment).to eq('usethis')
1267
+ end
1257
1268
 
1258
- Puppet.initialize_settings
1259
- configurer.run
1269
+ it "prefers the environment set via lastrunfile over config" do
1270
+ FileUtils.mkdir_p(Puppet[:confdir])
1271
+ set_puppet_conf(Puppet[:confdir], <<~CONF)
1272
+ [main]
1273
+ environment = usethis
1274
+ lastrunfile = #{Puppet[:lastrunfile]}
1275
+ CONF
1260
1276
 
1261
- expect(configurer.environment).to eq('usethis')
1262
- end
1277
+ Puppet.initialize_settings
1278
+ configurer.run
1279
+
1280
+ expect(configurer.environment).to eq(last_server_specified_environment)
1281
+ end
1263
1282
 
1264
- it "uses environment from Puppet[:environment] if given a catalog" do
1265
- configurer.run(catalog: catalog)
1283
+ it "uses the environment from Puppet[:environment] if given a catalog" do
1284
+ configurer.run(catalog: catalog)
1266
1285
 
1267
- expect(configurer.environment).to eq(Puppet[:environment])
1268
- end
1286
+ expect(configurer.environment).to eq(Puppet[:environment])
1287
+ end
1269
1288
 
1270
- it "uses environment from Puppet[:environment] if use_cached_catalog = true" do
1271
- Puppet[:use_cached_catalog] = true
1272
- expects_cached_catalog_only(catalog)
1273
- configurer.run
1289
+ it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1290
+ Puppet[:use_cached_catalog] = true
1291
+ expects_cached_catalog_only(catalog)
1292
+ configurer.run
1293
+
1294
+ expect(configurer.environment).to eq(Puppet[:environment])
1295
+ end
1274
1296
 
1275
- expect(configurer.environment).to eq(Puppet[:environment])
1297
+ describe "when the environment is not set via CLI" do
1298
+ it "uses the environment found in lastrunfile if the key exists" do
1299
+ configurer.run
1300
+
1301
+ expect(configurer.environment).to eq(last_server_specified_environment)
1302
+ end
1303
+
1304
+ it "pushes the converged environment found in lastrunfile over the existing context" do
1305
+ initial_env = Puppet::Node::Environment.remote('production')
1306
+ Puppet.push_context(
1307
+ current_environment: initial_env,
1308
+ loaders: Puppet::Pops::Loaders.new(initial_env, true))
1309
+
1310
+ expect(Puppet).to receive(:push_context).with(
1311
+ hash_including(:current_environment, :loaders),
1312
+ "Local node environment #{last_server_specified_environment} for configurer transaction"
1313
+ ).once.and_call_original
1314
+
1315
+ configurer.run
1316
+ end
1317
+
1318
+ it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1319
+ Puppet[:strict_environment_mode] = true
1320
+ configurer.run
1321
+
1322
+ expect(configurer.environment).to eq(Puppet[:environment])
1323
+ end
1324
+
1325
+ it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1326
+ Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1327
+ ---
1328
+ version:
1329
+ config: 1624882680
1330
+ puppet: 6.24.0
1331
+ application:
1332
+ initial_environment: development
1333
+ converged_environment: development
1334
+ run_mode: agent
1335
+ SUMMARY
1336
+ configurer.run
1337
+
1338
+ expect(configurer.environment).to eq(Puppet[:environment])
1339
+ end
1340
+ end
1276
1341
  end
1277
1342
 
1278
- describe "when the environment is not set via CLI" do
1279
- it "uses the environment found in lastrunfile if the key exists" do
1280
- configurer.run
1343
+ describe "when the use_last_environment setting is set to false" do
1344
+ let(:node_environment) { Puppet::Node::Environment.remote(:salam) }
1345
+ let(:node) { Puppet::Node.new(Puppet[:node_name_value]) }
1281
1346
 
1282
- expect(configurer.environment).to eq(last_server_specified_environment)
1347
+ before do
1348
+ Puppet[:use_last_environment] = false
1349
+ node.environment = node_environment
1350
+
1351
+ allow(Puppet::Node.indirection).to receive(:find)
1352
+ allow(Puppet::Node.indirection).to receive(:find)
1353
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1354
+ .and_return(node)
1283
1355
  end
1284
1356
 
1285
- it "uses environment from Puppet[:environment] if strict_environment_mode is set" do
1286
- Puppet[:strict_environment_mode] = true
1357
+ it "does a node request" do
1358
+ expect(Puppet::Node.indirection).to receive(:find)
1359
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1360
+
1287
1361
  configurer.run
1362
+ end
1288
1363
 
1289
- expect(configurer.environment).to eq(Puppet[:environment])
1364
+ it "uses the node environment from the node request" do
1365
+ configurer.run
1366
+
1367
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1368
+ end
1369
+ end
1370
+ end
1371
+
1372
+ describe "when the last used environment is not available" do
1373
+ describe "when the node request succeeds" do
1374
+ let(:node_environment) { Puppet::Node::Environment.remote(:salam) }
1375
+ let(:node) { Puppet::Node.new(Puppet[:node_name_value]) }
1376
+ let(:last_server_specified_environment) { 'development' }
1377
+
1378
+ before do
1379
+ node.environment = node_environment
1380
+
1381
+ allow(Puppet::Node.indirection).to receive(:find)
1382
+ allow(Puppet::Node.indirection).to receive(:find)
1383
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1384
+ .and_return(node)
1290
1385
  end
1291
1386
 
1292
- it "uses environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1387
+ it "uses the environment from the node request if the run mode doesn't match" do
1293
1388
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1294
- ---
1295
- version:
1296
- config: 1624882680
1297
- puppet: 6.24.0
1298
- application:
1299
- initial_environment: development
1300
- converged_environment: development
1301
- run_mode: agent
1389
+ ---
1390
+ version:
1391
+ config: 1624882680
1392
+ puppet: 6.24.0
1393
+ application:
1394
+ initial_environment: #{Puppet[:environment]}
1395
+ converged_environment: #{last_server_specified_environment}
1396
+ run_mode: user
1302
1397
  SUMMARY
1303
1398
  configurer.run
1304
1399
 
1305
- expect(configurer.environment).to eq(Puppet[:environment])
1400
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1306
1401
  end
1307
1402
 
1308
- it "uses environment from Puppet[:environment] if the run mode doesn't match" do
1403
+ it "uses the environment from the node request if lastrunfile does not contain the expected keys" do
1309
1404
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1310
- ---
1311
- version:
1312
- config: 1624882680
1313
- puppet: 6.24.0
1314
- application:
1315
- initial_environment: #{Puppet[:environment]}
1316
- converged_environment: #{last_server_specified_environment}
1317
- run_mode: user
1405
+ ---
1406
+ version:
1407
+ config: 1624882680
1408
+ puppet: 6.24.0
1318
1409
  SUMMARY
1319
1410
  configurer.run
1320
1411
 
1321
- expect(configurer.environment).to eq(Puppet[:environment])
1412
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1322
1413
  end
1323
1414
 
1324
- it "uses environment from Puppet[:environment] if lastrunfile is invalid YAML" do
1415
+ it "uses the environment from the node request if lastrunfile is invalid YAML" do
1325
1416
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1326
- Key: 'this is my very very very ' +
1327
- 'long string'
1417
+ Key: 'this is my very very very ' +
1418
+ 'long string'
1328
1419
  SUMMARY
1329
1420
  configurer.run
1330
1421
 
1331
- expect(configurer.environment).to eq(Puppet[:environment])
1422
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1332
1423
  end
1333
1424
 
1334
- it "uses environment from Puppet[:environment] if lastrunfile exists but is empty" do
1425
+ it "uses the environment from the node request if lastrunfile exists but is empty" do
1335
1426
  Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', '')
1336
1427
  configurer.run
1337
1428
 
1338
- expect(configurer.environment).to eq(Puppet[:environment])
1429
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1430
+ end
1431
+
1432
+ it "uses the environment from the node request if the last used one cannot be found" do
1433
+ Puppet[:lastrunfile] = tmpfile('last_run_summary.yaml')
1434
+ configurer.run
1435
+
1436
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1437
+ end
1438
+ end
1439
+
1440
+ describe "when the node request fails" do
1441
+ before do
1442
+ allow(Puppet::Node.indirection).to receive(:find).and_call_original
1443
+ allow(Puppet::Node.indirection).to receive(:find)
1444
+ .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1445
+ .and_raise(Puppet::Error)
1339
1446
  end
1340
1447
 
1341
- it "uses environment from Puppet[:environment] if the last used one cannot be found" do
1448
+ it "uses the environment from Puppet[:environment] if the last used one cannot be found" do
1342
1449
  Puppet[:lastrunfile] = tmpfile('last_run_summary.yaml')
1343
1450
  configurer.run
1344
1451
 
@@ -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
@@ -80,7 +80,7 @@ describe Puppet::FileSystem::Uniquefile do
80
80
  lock = File.join(dir, 'path', 'to', 'lock')
81
81
 
82
82
  expect {
83
- Puppet::FileSystem::Uniquefile.open_tmp(lock) { |tmp| }
83
+ Puppet::FileSystem::Uniquefile.new('foo', lock) { |tmp| }
84
84
  }.to raise_error(Errno::ENOENT, %r{No such file or directory - A directory component in .* does not exist or is a dangling symbolic link})
85
85
  end
86
86
 
@@ -102,6 +102,12 @@ describe Puppet::FileSystem::Uniquefile do
102
102
  expect(filename).to eq(temp_rune_utf8)
103
103
  end
104
104
 
105
+ it "preserves tilde characters" do
106
+ Puppet::FileSystem::Uniquefile.open_tmp('~foo') do |file|
107
+ expect(File.basename(file.path)).to start_with('~foo')
108
+ end
109
+ end
110
+
105
111
  context "Ruby 1.9.3 Tempfile tests" do
106
112
  # the remaining tests in this file are ported directly from the ruby 1.9.3 source,
107
113
  # since most of this file was ported from there
@@ -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": [