puppet 7.13.1 → 7.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +1 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +13 -13
  5. data/lib/puppet/application/lookup.rb +22 -16
  6. data/lib/puppet/configurer.rb +2 -12
  7. data/lib/puppet/defaults.rb +11 -0
  8. data/lib/puppet/face/generate.rb +2 -0
  9. data/lib/puppet/generate/type.rb +9 -0
  10. data/lib/puppet/node.rb +1 -1
  11. data/lib/puppet/resource/type_collection.rb +21 -17
  12. data/lib/puppet/type/user.rb +1 -1
  13. data/lib/puppet/util/yaml.rb +5 -1
  14. data/lib/puppet/version.rb +1 -1
  15. data/locales/puppet.pot +5 -9763
  16. data/man/man5/puppet.conf.5 +13 -2
  17. data/man/man8/puppet-agent.8 +1 -1
  18. data/man/man8/puppet-apply.8 +1 -1
  19. data/man/man8/puppet-catalog.8 +1 -1
  20. data/man/man8/puppet-config.8 +1 -1
  21. data/man/man8/puppet-describe.8 +1 -1
  22. data/man/man8/puppet-device.8 +1 -1
  23. data/man/man8/puppet-doc.8 +1 -1
  24. data/man/man8/puppet-epp.8 +1 -1
  25. data/man/man8/puppet-facts.8 +1 -1
  26. data/man/man8/puppet-filebucket.8 +1 -1
  27. data/man/man8/puppet-generate.8 +1 -1
  28. data/man/man8/puppet-help.8 +1 -1
  29. data/man/man8/puppet-lookup.8 +1 -1
  30. data/man/man8/puppet-module.8 +1 -1
  31. data/man/man8/puppet-node.8 +1 -1
  32. data/man/man8/puppet-parser.8 +1 -1
  33. data/man/man8/puppet-plugin.8 +1 -1
  34. data/man/man8/puppet-report.8 +1 -1
  35. data/man/man8/puppet-resource.8 +1 -1
  36. data/man/man8/puppet-script.8 +1 -1
  37. data/man/man8/puppet-ssl.8 +1 -1
  38. data/man/man8/puppet.8 +2 -2
  39. data/spec/integration/application/lookup_spec.rb +4 -1
  40. data/spec/unit/configurer_spec.rb +90 -58
  41. data/spec/unit/face/generate_spec.rb +64 -0
  42. data/spec/unit/node_spec.rb +6 -0
  43. data/spec/unit/type/user_spec.rb +67 -0
  44. metadata +3 -3
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPETCONF" "5" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPETCONF" "5" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  \fBThis page is autogenerated; any changes will get overwritten\fR
6
6
  .
7
7
  .SH "Configuration settings"
@@ -929,7 +929,7 @@ The time to wait for data to be read from an HTTP connection\. If nothing is rea
929
929
  The HTTP User\-Agent string to send when making network requests\.
930
930
  .
931
931
  .IP "\(bu" 4
932
- \fIDefault\fR: \fBPuppet/7\.13\.0 Ruby/2\.5\.1\-p57 (x86_64\-linux)\fR
932
+ \fIDefault\fR: \fBPuppet/7\.14\.0 Ruby/2\.7\.1\-p83 (x86_64\-linux)\fR
933
933
  .
934
934
  .IP "" 0
935
935
  .
@@ -2045,6 +2045,17 @@ Whether to only use the cached catalog rather than compiling a new catalog on ev
2045
2045
  .
2046
2046
  .IP "" 0
2047
2047
  .
2048
+ .SS "use_last_environment"
2049
+ Puppet saves both the initial and converged environment in the last_run_summary file\. If they differ, and this setting is set to true, we will use the last converged environment and skip the node request\.
2050
+ .
2051
+ .P
2052
+ When set to false, we will do the node request and ignore the environment data from the last_run_summary file\.
2053
+ .
2054
+ .IP "\(bu" 4
2055
+ \fIDefault\fR: \fBtrue\fR
2056
+ .
2057
+ .IP "" 0
2058
+ .
2048
2059
  .SS "use_srv_records"
2049
2060
  Whether the server will search for SRV records in DNS for the current domain\.
2050
2061
  .
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-AGENT" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-AGENT" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-agent\fR \- The puppet agent daemon
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-APPLY" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-APPLY" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-apply\fR \- Apply Puppet manifests locally
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-CATALOG" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-CATALOG" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-catalog\fR \- Compile, save, view, and convert catalogs\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-CONFIG" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-CONFIG" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-config\fR \- Interact with Puppet\'s settings\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-DESCRIBE" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-DESCRIBE" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-describe\fR \- Display help about resource types
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-DEVICE" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-DEVICE" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-device\fR \- Manage remote network devices
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-DOC" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-DOC" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-doc\fR \- Generate Puppet references
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-EPP" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-EPP" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-epp\fR \- Interact directly with the EPP template parser/renderer\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-FACTS" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-FACTS" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-facts\fR \- Retrieve and store facts\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-FILEBUCKET" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-FILEBUCKET" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-filebucket\fR \- Store and retrieve files in a filebucket
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-GENERATE" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-GENERATE" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-generate\fR \- Generates Puppet code from Ruby definitions\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-HELP" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-HELP" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-help\fR \- Display Puppet help\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-LOOKUP" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-LOOKUP" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-lookup\fR \- Interactive Hiera lookup
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-MODULE" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-MODULE" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-module\fR \- Creates, installs and searches for modules on the Puppet Forge\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-NODE" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-NODE" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-node\fR \- View and manage node definitions\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-PARSER" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-PARSER" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-parser\fR \- Interact directly with the parser\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-PLUGIN" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-PLUGIN" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-plugin\fR \- Interact with the Puppet plugin system\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-REPORT" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-REPORT" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-report\fR \- Create, display, and submit reports\.
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-RESOURCE" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-RESOURCE" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-resource\fR \- The resource abstraction layer shell
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-SCRIPT" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-SCRIPT" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-script\fR \- Run a puppet manifests as a script without compiling a catalog
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET\-SSL" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET\-SSL" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\-ssl\fR \- Manage SSL keys and certificates for puppet SSL clients
data/man/man8/puppet.8 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "PUPPET" "8" "December 2021" "Puppet, Inc." "Puppet manual"
4
+ .TH "PUPPET" "8" "January 2022" "Puppet, Inc." "Puppet manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBpuppet\fR
@@ -25,4 +25,4 @@ Specialized:
25
25
  catalog Compile, save, view, and convert catalogs\. describe Display help about resource types device Manage remote network devices doc Generate Puppet references epp Interact directly with the EPP template parser/renderer\. facts Retrieve and store facts\. filebucket Store and retrieve files in a filebucket generate Generates Puppet code from Ruby definitions\. node View and manage node definitions\. parser Interact directly with the parser\. plugin Interact with the Puppet plugin system\. script Run a puppet manifests as a script without compiling a catalog ssl Manage SSL keys and certificates for puppet SSL clients
26
26
  .
27
27
  .P
28
- See \'puppet help \fIsubcommand\fR \fIaction\fR\' for help on a specific subcommand action\. See \'puppet help \fIsubcommand\fR\' for help on a specific subcommand\. Puppet v7\.13\.0
28
+ See \'puppet help \fIsubcommand\fR \fIaction\fR\' for help on a specific subcommand action\. See \'puppet help \fIsubcommand\fR\' for help on a specific subcommand\. Puppet v7\.14\.0
@@ -48,6 +48,7 @@ describe 'lookup' do
48
48
  let(:facts) { Puppet::Node::Facts.new("facts", {'my_fact' => 'my_fact_value'}) }
49
49
  let(:cert) { pem_content('oid.pem') }
50
50
 
51
+ let(:node) { Puppet::Node.new('testnode', :facts => facts, :environment => env) }
51
52
  let(:populated_env_dir) do
52
53
  dir_contained_in(env_dir, environment_files)
53
54
  env_dir
@@ -104,7 +105,9 @@ describe 'lookup' do
104
105
  certname: fqdn,
105
106
  extensions: { "1.3.6.1.4.1.34380.1.2.1.1" => "somevalue" }))
106
107
 
107
- lookup('a')
108
+ Puppet.settings[:node_terminus] = 'exec'
109
+ expect_any_instance_of(Puppet::Node::Exec).to receive(:find).and_return(node)
110
+ lookup('a', :compile => true)
108
111
  end
109
112
 
110
113
  it 'loads external facts when running without --node' do
@@ -1251,88 +1251,120 @@ describe Puppet::Configurer do
1251
1251
  converged_environment: #{last_server_specified_environment}
1252
1252
  run_mode: agent
1253
1253
  SUMMARY
1254
+ end
1254
1255
 
1255
- expect(Puppet::Node.indirection).not_to receive(:find)
1256
+ describe "when the use_last_environment is set to true" do
1257
+ before do
1258
+ expect(Puppet::Node.indirection).not_to receive(:find)
1256
1259
  .with(anything, hash_including(:ignore_cache => true, :fail_on_404 => true))
1257
- end
1260
+ end
1258
1261
 
1259
- it "prefers the environment set via cli" do
1260
- Puppet.settings.handlearg('--environment', 'usethis')
1261
- configurer.run
1262
+ it "prefers the environment set via cli" do
1263
+ Puppet.settings.handlearg('--environment', 'usethis')
1264
+ configurer.run
1262
1265
 
1263
- expect(configurer.environment).to eq('usethis')
1264
- end
1266
+ expect(configurer.environment).to eq('usethis')
1267
+ end
1265
1268
 
1266
- it "prefers the environment set via lastrunfile over config" do
1267
- FileUtils.mkdir_p(Puppet[:confdir])
1268
- set_puppet_conf(Puppet[:confdir], <<~CONF)
1269
- [main]
1270
- environment = usethis
1271
- lastrunfile = #{Puppet[:lastrunfile]}
1272
- CONF
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
1273
1276
 
1274
- Puppet.initialize_settings
1275
- configurer.run
1277
+ Puppet.initialize_settings
1278
+ configurer.run
1276
1279
 
1277
- expect(configurer.environment).to eq(last_server_specified_environment)
1278
- end
1280
+ expect(configurer.environment).to eq(last_server_specified_environment)
1281
+ end
1279
1282
 
1280
- it "uses the environment from Puppet[:environment] if given a catalog" do
1281
- configurer.run(catalog: catalog)
1283
+ it "uses the environment from Puppet[:environment] if given a catalog" do
1284
+ configurer.run(catalog: catalog)
1282
1285
 
1283
- expect(configurer.environment).to eq(Puppet[:environment])
1284
- end
1286
+ expect(configurer.environment).to eq(Puppet[:environment])
1287
+ end
1285
1288
 
1286
- it "uses the environment from Puppet[:environment] if use_cached_catalog = true" do
1287
- Puppet[:use_cached_catalog] = true
1288
- expects_cached_catalog_only(catalog)
1289
- 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
1290
1293
 
1291
- expect(configurer.environment).to eq(Puppet[:environment])
1292
- end
1294
+ expect(configurer.environment).to eq(Puppet[:environment])
1295
+ end
1293
1296
 
1294
- describe "when the environment is not set via CLI" do
1295
- it "uses the environment found in lastrunfile if the key exists" do
1296
- configurer.run
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
1297
1300
 
1298
- expect(configurer.environment).to eq(last_server_specified_environment)
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
1299
1340
  end
1341
+ end
1300
1342
 
1301
- it "pushes the converged environment found in lastrunfile over the existing context" do
1302
- initial_env = Puppet::Node::Environment.remote('production')
1303
- Puppet.push_context(
1304
- current_environment: initial_env,
1305
- loaders: Puppet::Pops::Loaders.new(initial_env, true))
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]) }
1306
1346
 
1307
- expect(Puppet).to receive(:push_context).with(
1308
- hash_including(:current_environment, :loaders),
1309
- "Local node environment #{last_server_specified_environment} for configurer transaction"
1310
- ).once.and_call_original
1347
+ before do
1348
+ Puppet[:use_last_environment] = false
1349
+ node.environment = node_environment
1311
1350
 
1312
- configurer.run
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)
1313
1355
  end
1314
1356
 
1315
- it "uses the environment from Puppet[:environment] if strict_environment_mode is set" do
1316
- Puppet[:strict_environment_mode] = true
1317
- configurer.run
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))
1318
1360
 
1319
- expect(configurer.environment).to eq(Puppet[:environment])
1361
+ configurer.run
1320
1362
  end
1321
1363
 
1322
- it "uses the environment from Puppet[:environment] if initial_environment is the same as converged_environment" do
1323
- Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY)
1324
- ---
1325
- version:
1326
- config: 1624882680
1327
- puppet: 6.24.0
1328
- application:
1329
- initial_environment: development
1330
- converged_environment: development
1331
- run_mode: agent
1332
- SUMMARY
1364
+ it "uses the node environment from the node request" do
1333
1365
  configurer.run
1334
1366
 
1335
- expect(configurer.environment).to eq(Puppet[:environment])
1367
+ expect(configurer.environment).to eq(node_environment.name.to_s)
1336
1368
  end
1337
1369
  end
1338
1370
  end
@@ -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
@@ -40,6 +40,12 @@ describe Puppet::Node do
40
40
  expect(node.environment.name).to eq(:bar)
41
41
  end
42
42
 
43
+ it "sets environment_name with the correct environment name" do
44
+ node = Puppet::Node.new("foo")
45
+ node.environment = Puppet::Node::Environment.remote('www123')
46
+ expect(node.environment_name).to eq(:www123)
47
+ end
48
+
43
49
  it "allows its environment to be set by parameters after initialization" do
44
50
  node = Puppet::Node.new("foo")
45
51
  node.parameters["environment"] = :bar
@@ -289,6 +289,73 @@ describe Puppet::Type.type(:user) do
289
289
  end
290
290
  end
291
291
 
292
+ describe "when managing the purge_ssh_keys property" do
293
+ context "with valid input" do
294
+ ['true', :true, true].each do |input|
295
+ it "should support #{input} as value" do
296
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => input) }.to_not raise_error
297
+ end
298
+ end
299
+
300
+ ['false', :false, false].each do |input|
301
+ it "should support #{input} as value" do
302
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => input) }.to_not raise_error
303
+ end
304
+ end
305
+
306
+ it "should support a String value" do
307
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => File.expand_path('home/foo/.ssh/authorized_keys')) }.to_not raise_error
308
+ end
309
+
310
+ it "should support an Array value" do
311
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => [File.expand_path('home/foo/.ssh/authorized_keys'),
312
+ File.expand_path('custom/authorized_keys')]) }.to_not raise_error
313
+ end
314
+ end
315
+
316
+ context "with faulty input" do
317
+ it "should raise error for relative path" do
318
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => 'home/foo/.ssh/authorized_keys') }.to raise_error(Puppet::ResourceError,
319
+ /Paths to keyfiles must be absolute/ )
320
+ end
321
+
322
+ it "should raise error for invalid type" do
323
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => :invalid) }.to raise_error(Puppet::ResourceError,
324
+ /purge_ssh_keys must be true, false, or an array of file names/ )
325
+ end
326
+
327
+ it "should raise error for array with relative path" do
328
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => ['home/foo/.ssh/authorized_keys',
329
+ File.expand_path('custom/authorized_keys')]) }.to raise_error(Puppet::ResourceError,
330
+ /Paths to keyfiles must be absolute/ )
331
+ end
332
+
333
+ it "should raise error for array with invalid type" do
334
+ expect { described_class.new(:name => 'foo', :purge_ssh_keys => [:invalid,
335
+ File.expand_path('custom/authorized_keys')]) }.to raise_error(Puppet::ResourceError,
336
+ /Each entry for purge_ssh_keys must be a string/ )
337
+ end
338
+ end
339
+
340
+ context "homedir retrieval" do
341
+ it "should accept the home provided" do
342
+ expect(Puppet).not_to receive(:debug).with("User 'foo' does not exist")
343
+ described_class.new(:name => 'foo', :purge_ssh_keys => true, :home => '/my_home')
344
+ end
345
+
346
+ it "should accept the home provided" do
347
+ expect(Dir).to receive(:home).with('foo').and_return('/my_home')
348
+ expect(Puppet).not_to receive(:debug).with("User 'foo' does not exist")
349
+ described_class.new(:name => 'foo', :purge_ssh_keys => true)
350
+ end
351
+
352
+ it "should output debug message when home directory cannot be retrieved" do
353
+ allow(Dir).to receive(:home).with('foo').and_raise(ArgumentError)
354
+ expect(Puppet).to receive(:debug).with("User 'foo' does not exist")
355
+ described_class.new(:name => 'foo', :purge_ssh_keys => true)
356
+ end
357
+ end
358
+ end
292
359
 
293
360
  describe "when managing expiry" do
294
361
  it "should fail if given an invalid date" do