bolt 0.11.0 → 0.12.0

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

Potentially problematic release.


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

Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bolt/cli.rb +127 -31
  3. data/lib/bolt/config.rb +39 -6
  4. data/lib/bolt/execution_result.rb +109 -0
  5. data/lib/bolt/executor.rb +4 -1
  6. data/lib/bolt/node.rb +6 -1
  7. data/lib/bolt/node/orch.rb +20 -2
  8. data/lib/bolt/node/winrm.rb +22 -10
  9. data/lib/bolt/node_uri.rb +5 -7
  10. data/lib/bolt/outputter/human.rb +60 -1
  11. data/lib/bolt/outputter/json.rb +11 -0
  12. data/lib/bolt/target.rb +32 -0
  13. data/lib/bolt/version.rb +1 -1
  14. data/modules/boltlib/lib/puppet/datatypes/executionresult.rb +30 -0
  15. data/modules/boltlib/lib/puppet/datatypes/target.rb +12 -0
  16. data/modules/boltlib/lib/puppet/functions/file_upload.rb +3 -3
  17. data/modules/boltlib/lib/puppet/functions/run_command.rb +3 -3
  18. data/modules/boltlib/lib/puppet/functions/run_script.rb +3 -3
  19. data/modules/boltlib/lib/puppet/functions/run_task.rb +10 -2
  20. data/vendored/puppet/lib/puppet/application/describe.rb +0 -1
  21. data/vendored/puppet/lib/puppet/configurer.rb +1 -1
  22. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +15 -9
  23. data/vendored/puppet/lib/puppet/datatypes.rb +213 -0
  24. data/vendored/puppet/lib/puppet/datatypes/error.rb +19 -0
  25. data/vendored/puppet/lib/puppet/datatypes/impl/error.rb +42 -0
  26. data/vendored/puppet/lib/puppet/error.rb +1 -1
  27. data/vendored/puppet/lib/puppet/face/catalog.rb +1 -1
  28. data/vendored/puppet/lib/puppet/face/epp.rb +3 -3
  29. data/vendored/puppet/lib/puppet/face/help.rb +12 -14
  30. data/vendored/puppet/lib/puppet/face/man.rb +1 -0
  31. data/vendored/puppet/lib/puppet/face/module/search.rb +1 -1
  32. data/vendored/puppet/lib/puppet/face/node.rb +1 -0
  33. data/vendored/puppet/lib/puppet/face/parser.rb +0 -1
  34. data/vendored/puppet/lib/puppet/face/status.rb +1 -0
  35. data/vendored/puppet/lib/puppet/feature/base.rb +1 -1
  36. data/vendored/puppet/lib/puppet/file_bucket/dipper.rb +0 -1
  37. data/vendored/puppet/lib/puppet/file_system/uniquefile.rb +2 -2
  38. data/vendored/puppet/lib/puppet/forge/errors.rb +21 -29
  39. data/vendored/puppet/lib/puppet/functions.rb +64 -84
  40. data/vendored/puppet/lib/puppet/functions/defined.rb +0 -3
  41. data/vendored/puppet/lib/puppet/functions/find_file.rb +0 -1
  42. data/vendored/puppet/lib/puppet/functions/map.rb +0 -1
  43. data/vendored/puppet/lib/puppet/functions/regsubst.rb +1 -1
  44. data/vendored/puppet/lib/puppet/graph/simple_graph.rb +6 -10
  45. data/vendored/puppet/lib/puppet/indirector/catalog/compiler.rb +37 -25
  46. data/vendored/puppet/lib/puppet/indirector/file_server.rb +1 -1
  47. data/vendored/puppet/lib/puppet/indirector/indirection.rb +0 -2
  48. data/vendored/puppet/lib/puppet/indirector/rest.rb +9 -8
  49. data/vendored/puppet/lib/puppet/info_service/class_information_service.rb +1 -1
  50. data/vendored/puppet/lib/puppet/interface/option_manager.rb +1 -1
  51. data/vendored/puppet/lib/puppet/loaders.rb +1 -0
  52. data/vendored/puppet/lib/puppet/module.rb +6 -2
  53. data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  54. data/vendored/puppet/lib/puppet/module_tool/errors/installer.rb +29 -41
  55. data/vendored/puppet/lib/puppet/module_tool/errors/shared.rb +63 -138
  56. data/vendored/puppet/lib/puppet/module_tool/errors/uninstaller.rb +15 -37
  57. data/vendored/puppet/lib/puppet/module_tool/errors/upgrader.rb +18 -30
  58. data/vendored/puppet/lib/puppet/module_tool/installed_modules.rb +1 -1
  59. data/vendored/puppet/lib/puppet/module_tool/metadata.rb +0 -1
  60. data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +1 -1
  61. data/vendored/puppet/lib/puppet/network/rights.rb +1 -1
  62. data/vendored/puppet/lib/puppet/node.rb +1 -1
  63. data/vendored/puppet/lib/puppet/node/environment.rb +1 -1
  64. data/vendored/puppet/lib/puppet/parameter/value_collection.rb +4 -17
  65. data/vendored/puppet/lib/puppet/parser/compiler.rb +1 -0
  66. data/vendored/puppet/lib/puppet/parser/functions.rb +0 -1
  67. data/vendored/puppet/lib/puppet/parser/functions/scanf.rb +1 -1
  68. data/vendored/puppet/lib/puppet/parser/scope.rb +4 -3
  69. data/vendored/puppet/lib/puppet/parser/script_compiler.rb +1 -0
  70. data/vendored/puppet/lib/puppet/parser/templatewrapper.rb +3 -2
  71. data/vendored/puppet/lib/puppet/parser/type_loader.rb +1 -1
  72. data/vendored/puppet/lib/puppet/pops.rb +1 -0
  73. data/vendored/puppet/lib/puppet/pops/evaluator/access_operator.rb +3 -2
  74. data/vendored/puppet/lib/puppet/pops/evaluator/closure.rb +1 -1
  75. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +2 -2
  76. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +6 -5
  77. data/vendored/puppet/lib/puppet/pops/functions/function.rb +2 -2
  78. data/vendored/puppet/lib/puppet/pops/loader/loader.rb +1 -1
  79. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +40 -4
  80. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +6 -2
  81. data/vendored/puppet/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +8 -8
  82. data/vendored/puppet/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +40 -0
  83. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +6 -26
  84. data/vendored/puppet/lib/puppet/pops/loaders.rb +11 -2
  85. data/vendored/puppet/lib/puppet/pops/lookup/data_dig_function_provider.rb +1 -1
  86. data/vendored/puppet/lib/puppet/pops/lookup/lookup_adapter.rb +4 -14
  87. data/vendored/puppet/lib/puppet/pops/model/model_tree_dumper.rb +1 -1
  88. data/vendored/puppet/lib/puppet/pops/parser/code_merger.rb +2 -2
  89. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +1471 -1501
  90. data/vendored/puppet/lib/puppet/pops/parser/epp_support.rb +0 -2
  91. data/vendored/puppet/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
  92. data/vendored/puppet/lib/puppet/pops/parser/interpolation_support.rb +1 -1
  93. data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +2 -26
  94. data/vendored/puppet/lib/puppet/pops/parser/locator.rb +5 -7
  95. data/vendored/puppet/lib/puppet/pops/parser/parser_support.rb +2 -2
  96. data/vendored/puppet/lib/puppet/pops/parser/slurp_support.rb +0 -3
  97. data/vendored/puppet/lib/puppet/pops/pcore.rb +0 -11
  98. data/vendored/puppet/lib/puppet/pops/serialization/object.rb +3 -4
  99. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +1 -1
  100. data/vendored/puppet/lib/puppet/pops/time/timespan.rb +1 -1
  101. data/vendored/puppet/lib/puppet/pops/types/iterable.rb +14 -7
  102. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +38 -7
  103. data/vendored/puppet/lib/puppet/pops/types/p_object_type_extension.rb +21 -22
  104. data/vendored/puppet/lib/puppet/pops/types/p_sem_ver_range_type.rb +0 -1
  105. data/vendored/puppet/lib/puppet/pops/types/p_type_set_type.rb +0 -1
  106. data/vendored/puppet/lib/puppet/pops/types/p_uri_type.rb +0 -1
  107. data/vendored/puppet/lib/puppet/pops/types/puppet_object.rb +1 -1
  108. data/vendored/puppet/lib/puppet/pops/types/string_converter.rb +5 -1
  109. data/vendored/puppet/lib/puppet/pops/types/type_calculator.rb +5 -1
  110. data/vendored/puppet/lib/puppet/pops/types/type_factory.rb +1 -5
  111. data/vendored/puppet/lib/puppet/pops/types/type_formatter.rb +21 -0
  112. data/vendored/puppet/lib/puppet/pops/types/types.rb +2 -7
  113. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +1 -3
  114. data/vendored/puppet/lib/puppet/property.rb +1 -1
  115. data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +3 -4
  116. data/vendored/puppet/lib/puppet/provider/exec.rb +0 -2
  117. data/vendored/puppet/lib/puppet/provider/nameservice.rb +6 -1
  118. data/vendored/puppet/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
  119. data/vendored/puppet/lib/puppet/provider/package/appdmg.rb +0 -1
  120. data/vendored/puppet/lib/puppet/provider/package/apple.rb +0 -1
  121. data/vendored/puppet/lib/puppet/provider/package/macports.rb +2 -2
  122. data/vendored/puppet/lib/puppet/provider/package/pkgdmg.rb +0 -1
  123. data/vendored/puppet/lib/puppet/provider/package/portage.rb +0 -1
  124. data/vendored/puppet/lib/puppet/provider/package/zypper.rb +2 -2
  125. data/vendored/puppet/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +2 -2
  126. data/vendored/puppet/lib/puppet/provider/service/init.rb +1 -0
  127. data/vendored/puppet/lib/puppet/provider/service/launchd.rb +3 -3
  128. data/vendored/puppet/lib/puppet/provider/user/aix.rb +1 -1
  129. data/vendored/puppet/lib/puppet/provider/user/openbsd.rb +1 -1
  130. data/vendored/puppet/lib/puppet/provider/user/pw.rb +1 -1
  131. data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +2 -4
  132. data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +1 -1
  133. data/vendored/puppet/lib/puppet/provider/zpool/zpool.rb +1 -1
  134. data/vendored/puppet/lib/puppet/reference/type.rb +0 -1
  135. data/vendored/puppet/lib/puppet/resource.rb +1 -2
  136. data/vendored/puppet/lib/puppet/resource/status.rb +0 -1
  137. data/vendored/puppet/lib/puppet/resource/type.rb +3 -3
  138. data/vendored/puppet/lib/puppet/resource/type_collection.rb +1 -1
  139. data/vendored/puppet/lib/puppet/settings/environment_conf.rb +0 -1
  140. data/vendored/puppet/lib/puppet/ssl/host.rb +1 -1
  141. data/vendored/puppet/lib/puppet/syntax_checkers/base64.rb +1 -1
  142. data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
  143. data/vendored/puppet/lib/puppet/type.rb +17 -4
  144. data/vendored/puppet/lib/puppet/type/file.rb +3 -3
  145. data/vendored/puppet/lib/puppet/type/mount.rb +9 -0
  146. data/vendored/puppet/lib/puppet/type/schedule.rb +25 -13
  147. data/vendored/puppet/lib/puppet/type/tidy.rb +2 -2
  148. data/vendored/puppet/lib/puppet/type/user.rb +1 -1
  149. data/vendored/puppet/lib/puppet/util.rb +19 -14
  150. data/vendored/puppet/lib/puppet/util/filetype.rb +2 -2
  151. data/vendored/puppet/lib/puppet/util/json_lockfile.rb +1 -1
  152. data/vendored/puppet/lib/puppet/util/log.rb +5 -3
  153. data/vendored/puppet/lib/puppet/util/log/destinations.rb +0 -1
  154. data/vendored/puppet/lib/puppet/util/monkey_patches.rb +1 -1
  155. data/vendored/puppet/lib/puppet/util/network_device/config.rb +2 -2
  156. data/vendored/puppet/lib/puppet/util/plist.rb +6 -4
  157. data/vendored/puppet/lib/puppet/util/rdoc/generators/puppet_generator.rb +1 -1
  158. data/vendored/puppet/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +1 -1
  159. data/vendored/puppet/lib/puppet/util/storage.rb +2 -2
  160. data/vendored/puppet/lib/puppet/util/windows/registry.rb +2 -2
  161. data/vendored/puppet/lib/puppet/util/windows/sid.rb +0 -2
  162. data/vendored/puppet/lib/puppet/version.rb +1 -1
  163. data/vendored/puppet/lib/puppet_pal.rb +30 -17
  164. metadata +28 -7
  165. data/vendored/puppet/lib/puppet/pops/types/execution_result.rb +0 -137
@@ -442,9 +442,9 @@ class Puppet::Resource::Type
442
442
  def convert_from_ast(name)
443
443
  value = name.value
444
444
  if value.is_a?(Puppet::Parser::AST::Regex)
445
- name = value.value
445
+ value.value
446
446
  else
447
- name = value
447
+ value
448
448
  end
449
449
  end
450
450
 
@@ -476,7 +476,7 @@ class Puppet::Resource::Type
476
476
  # Note we're doing something somewhat weird here -- we're setting
477
477
  # the class's namespace to its fully qualified name. This means
478
478
  # anything inside that class starts looking in that namespace first.
479
- @namespace, ignored_shortname = @type == :hostclass ? [@name, ''] : namesplit(@name)
479
+ @namespace, _ = @type == :hostclass ? [@name, ''] : namesplit(@name)
480
480
  end
481
481
  end
482
482
 
@@ -58,7 +58,7 @@ class Puppet::Resource::TypeCollection
58
58
 
59
59
  def add(instance)
60
60
  # return a merged instance, or the given
61
- result = catch(:merged) {
61
+ catch(:merged) {
62
62
  send("add_#{instance.type}", instance)
63
63
  instance.resource_type_collection = self
64
64
  instance
@@ -22,7 +22,6 @@ class Puppet::Settings::EnvironmentConf
22
22
  def self.load_from(path_to_env, global_module_path)
23
23
  path_to_env = File.expand_path(path_to_env)
24
24
  conf_file = File.join(path_to_env, 'environment.conf')
25
- config = nil
26
25
 
27
26
  begin
28
27
  config = Puppet.settings.parse_file(conf_file)
@@ -211,7 +211,7 @@ DOC
211
211
  raise Puppet::Error, _("No private key with which to validate certificate with fingerprint: %{fingerprint}") % { fingerprint: certificate.fingerprint } unless key
212
212
  unless certificate.content.check_private_key(key.content)
213
213
  raise Puppet::Error, _(<<ERROR_STRING) % { fingerprint: certificate.fingerprint, cert_name: Puppet[:certname], ssl_dir: Puppet[:ssldir], cert_dir: Puppet[:certdir].gsub('/', '\\') }
214
- The certificate retrieved from the master does not match the agent's private key.
214
+ The certificate retrieved from the master does not match the agent's private key. Did you forget to run as root?
215
215
  Certificate fingerprint: %{fingerprint}
216
216
  To fix this, remove the certificate from both the master and the agent and then start a puppet run, which will automatically regenerate a certificate.
217
217
  On the master:
@@ -23,7 +23,7 @@ class Puppet::SyntaxCheckers::Base64 < Puppet::Plugins::SyntaxCheckers::SyntaxCh
23
23
  # Do a strict decode64 on text with all whitespace stripped since the non strict version
24
24
  # simply skips all non base64 characters
25
25
  Base64.strict_decode64(cleaned_text)
26
- rescue => e
26
+ rescue
27
27
  msg = if (cleaned_text.bytes.to_a.size * 8) % 6 != 0
28
28
  _("Base64 syntax checker: Cannot parse invalid Base64 string - padding is not correct")
29
29
  else
@@ -52,7 +52,7 @@ class Puppet::Transaction::Persistence
52
52
  end
53
53
 
54
54
  result = nil
55
- Puppet::Util.benchmark(:debug, _("Loaded transaction store file")) do
55
+ Puppet::Util.benchmark(:debug, _("Loaded transaction store file in %{seconds} seconds")) do
56
56
  begin
57
57
  result = Puppet::Util::Yaml.load_file(filename, false, true)
58
58
  rescue Puppet::Util::Yaml::YamlLoadError => detail
@@ -1336,9 +1336,9 @@ class Type
1336
1336
 
1337
1337
  def properties_to_audit(list)
1338
1338
  if !list.kind_of?(Array) && list.to_sym == :all
1339
- list = all_properties
1339
+ all_properties
1340
1340
  else
1341
- list = Array(list).collect { |p| p.to_sym }
1341
+ Array(list).collect { |p| p.to_sym }
1342
1342
  end
1343
1343
  end
1344
1344
  end
@@ -1537,12 +1537,25 @@ class Type
1537
1537
  :event => self.class.events,
1538
1538
  :callback => method
1539
1539
  }
1540
- self.debug { "subscribes to #{related_resource.ref}" }
1541
1540
  else
1542
1541
  # If there's no callback, there's no point in even adding
1543
1542
  # a label.
1544
1543
  subargs = nil
1545
- self.debug { "subscribes to #{related_resource.ref}" }
1544
+ end
1545
+
1546
+ ## Corrected syntax of debug statement to reflect the way this was called.
1547
+ # i.e. before, after, subscribe, notify
1548
+ self.debug do
1549
+ relation = case self.class.name
1550
+ when "subscribe"
1551
+ "subscribes"
1552
+ when "notify"
1553
+ "notifies"
1554
+ else
1555
+ self.class.name
1556
+ end
1557
+
1558
+ "#{relation} to #{related_resource.ref}"
1546
1559
  end
1547
1560
 
1548
1561
  Puppet::Relationship.new(source, target, subargs)
@@ -828,11 +828,11 @@ Puppet::Type.newtype(:file) do
828
828
 
829
829
  @stat = begin
830
830
  Puppet::FileSystem.send(method, self[:path])
831
- rescue Errno::ENOENT => error
831
+ rescue Errno::ENOENT
832
832
  nil
833
- rescue Errno::ENOTDIR => error
833
+ rescue Errno::ENOTDIR
834
834
  nil
835
- rescue Errno::EACCES => error
835
+ rescue Errno::EACCES
836
836
  warning _("Could not stat; permission denied")
837
837
  nil
838
838
  end
@@ -16,6 +16,9 @@ module Puppet
16
16
  that is, other mount points higher up in the filesystem --- the child
17
17
  mount will autorequire them.
18
18
 
19
+ **Autorequires:** If Puppet is managing a `File` resource for the mount
20
+ point of a mount resource, the mount will autorequire it.
21
+
19
22
  **Autobefores:** If Puppet is managing any child file paths of a mount
20
23
  point, the mount resource will autobefore them."
21
24
 
@@ -300,6 +303,12 @@ module Puppet
300
303
  dependencies[0..-2]
301
304
  end
302
305
 
306
+ # Ensure that the mountpoint is created first
307
+ autorequire(:file) do
308
+ dependencies = []
309
+ dependencies.unshift @parameters[:name].value
310
+ end
311
+
303
312
  # Autobefore the mount point's child file paths
304
313
  autobefore(:file) do
305
314
  dependencies = []
@@ -346,9 +346,9 @@ module Puppet
346
346
  newparam(:weekday) do
347
347
  desc <<-EOT
348
348
  The days of the week in which the schedule should be valid.
349
- You may specify the full day name (Tuesday), the three character
350
- abbreviation (Tue), or a number corresponding to the day of the
351
- week where 0 is Sunday, 1 is Monday, etc. Multiple days can be specified
349
+ You may specify the full day name 'Tuesday', the three character
350
+ abbreviation 'Tue', or a number (as a string or as an integer) corresponding to the day of the
351
+ week where 0 is Sunday, 1 is Monday, and so on. Multiple days can be specified
352
352
  as an array. If not specified, the day of the week will not be
353
353
  considered in the schedule.
354
354
 
@@ -369,13 +369,22 @@ module Puppet
369
369
  validate do |values|
370
370
  values = [values] unless values.is_a?(Array)
371
371
  values.each { |value|
372
- unless value.is_a?(String) and
373
- (value =~ /^[0-6]$/ or value =~ /^(Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur)?|Sun)(day)?$/i)
372
+ if weekday_integer?(value) || weekday_string?(value)
373
+ value
374
+ else
374
375
  raise ArgumentError, _("%{value} is not a valid day of the week") % { value: value }
375
376
  end
376
377
  }
377
378
  end
378
379
 
380
+ def weekday_integer?(value)
381
+ value.is_a?(Integer) && (0..6).include?(value)
382
+ end
383
+
384
+ def weekday_string?(value)
385
+ value.is_a?(String) && (value =~ /^[0-6]$/ || value =~ /^(Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur)?|Sun)(day)?$/i)
386
+ end
387
+
379
388
  weekdays = {
380
389
  'sun' => 0,
381
390
  'mon' => 1,
@@ -390,14 +399,17 @@ module Puppet
390
399
  values = [values] unless values.is_a?(Array)
391
400
  ret = {}
392
401
 
393
- values.each { |value|
394
- if value =~ /^[0-6]$/
395
- index = value.to_i
396
- else
397
- index = weekdays[value[0,3].downcase]
398
- end
399
- ret[index] = true
400
- }
402
+ values.each do |value|
403
+ case value
404
+ when /^[0-6]$/
405
+ index = value.to_i
406
+ when 0..6
407
+ index = value
408
+ else
409
+ index = weekdays[value[0,3].downcase]
410
+ end
411
+ ret[index] = true
412
+ end
401
413
  ret
402
414
  end
403
415
 
@@ -326,10 +326,10 @@ Puppet::Type.newtype(:tidy) do
326
326
  def stat(path)
327
327
  begin
328
328
  Puppet::FileSystem.lstat(path)
329
- rescue Errno::ENOENT => error
329
+ rescue Errno::ENOENT
330
330
  info _("File does not exist")
331
331
  return nil
332
- rescue Errno::EACCES => error
332
+ rescue Errno::EACCES
333
333
  #TRANSLATORS "stat" is a program name and should not be translated
334
334
  warning _("Could not stat; permission denied")
335
335
  return nil
@@ -767,7 +767,7 @@ module Puppet
767
767
  # the name is stored in the 4th capture of the regex
768
768
  name = $4
769
769
  if name.empty?
770
- key = $3.delete("\n")
770
+ $3.delete("\n")
771
771
  # If no comment is specified for this key, generate a unique internal
772
772
  # name. This uses the same rules as
773
773
  # provider/ssh_authorized_key/parsed (PUP-3357)
@@ -197,20 +197,27 @@ module Util
197
197
  }
198
198
  end
199
199
 
200
+ # execute a block of work and based on the logging level provided, log the provided message with the seconds taken
201
+ # The message 'msg' should include string ' in %{seconds} seconds' as part of the message and any content should escape
202
+ # any percent signs '%' so that they are not interpreted as formatting commands
203
+ # escaped_str = str.gsub(/%/, '%%')
204
+ #
205
+ # @param msg [String] the message to be formated to assigned the %{seconds} seconds take to execute,
206
+ # other percent signs '%' need to be escaped
207
+ # @param level [Symbol] the logging level for this message
208
+ # @param object [Object] The object use for logging the message
200
209
  def benchmark(*args)
201
210
  msg = args.pop
202
211
  level = args.pop
203
- object = nil
204
-
205
- if args.empty?
206
- if respond_to?(level)
207
- object = self
208
- else
209
- object = Puppet
210
- end
211
- else
212
- object = args.pop
213
- end
212
+ object = if args.empty?
213
+ if respond_to?(level)
214
+ self
215
+ else
216
+ Puppet
217
+ end
218
+ else
219
+ args.pop
220
+ end
214
221
 
215
222
  raise Puppet::DevError, "Failed to provide level to :benchmark" unless level
216
223
 
@@ -223,9 +230,7 @@ module Util
223
230
  seconds = Benchmark.realtime {
224
231
  yield
225
232
  }
226
- #TRANSLATORS forms the end of a string indicating how long a
227
- # given operation took
228
- object.send(level, msg + (_(" in %0.2f seconds") % seconds))
233
+ object.send(level, msg % { seconds: "%0.2f" % seconds })
229
234
  return seconds
230
235
  else
231
236
  yield
@@ -42,7 +42,7 @@ class Puppet::Util::FileType
42
42
  else
43
43
  return ""
44
44
  end
45
- rescue Puppet::Error => detail
45
+ rescue Puppet::Error
46
46
  raise
47
47
  rescue => detail
48
48
  message = _("%{klass} could not read %{path}: %{detail}") % { klass: self.class, path: @path, detail: detail }
@@ -58,7 +58,7 @@ class Puppet::Util::FileType
58
58
  val = real_write(text)
59
59
  @synced = Time.now
60
60
  return val
61
- rescue Puppet::Error => detail
61
+ rescue Puppet::Error
62
62
  raise
63
63
  rescue => detail
64
64
  message = _("%{klass} could not write %{path}: %{detail}") % { klass: self.class, path: @path, detail: detail }
@@ -36,7 +36,7 @@ class Puppet::Util::JsonLockfile < Puppet::Util::Lockfile
36
36
  file_contents = super
37
37
  return nil if file_contents.nil? or file_contents.empty?
38
38
  JSON.parse(file_contents)
39
- rescue JSON::ParserError => e
39
+ rescue JSON::ParserError
40
40
  Puppet.warning _("Unable to read lockfile data from %{path}: not in JSON") % { path: @file_path }
41
41
  nil
42
42
  end
@@ -124,7 +124,7 @@ class Puppet::Util::Log
124
124
  return
125
125
  end
126
126
 
127
- name, type = @desttypes.find do |name, klass|
127
+ _, type = @desttypes.find do |name, klass|
128
128
  klass.match?(dest)
129
129
  end
130
130
 
@@ -169,8 +169,10 @@ class Puppet::Util::Log
169
169
  return Puppet::Util::CharacterEncoding.convert_to_utf_8(str) if str.valid_encoding?
170
170
 
171
171
  # We only select the last 10 callers in the stack to avoid being spammy
172
- _("Received a Log attribute with invalid encoding:%{log_message}\nBacktrace:\n%{backtrace}") %
173
- { log_message: Puppet::Util::CharacterEncoding.convert_to_utf_8(str.dump), backtrace: caller[0..10].join("\n") }
172
+ message = _("Received a Log attribute with invalid encoding:%{log_message}") %
173
+ { log_message: Puppet::Util::CharacterEncoding.convert_to_utf_8(str.dump)}
174
+ message += '\n' + _("Backtrace:\n%{backtrace}") % { backtrace: caller[0..10].join("\n") }
175
+ message
174
176
  end
175
177
 
176
178
  public
@@ -125,7 +125,6 @@ Puppet::Util::Log.newdesttype :logstash_event do
125
125
  # logstash_event format is documented at
126
126
  # https://logstash.jira.com/browse/LOGSTASH-675
127
127
 
128
- data = {}
129
128
  data = msg.to_hash
130
129
  data['version'] = 1
131
130
  data['@timestamp'] = data['time']
@@ -69,7 +69,7 @@ if Puppet::Util::Platform.windows?
69
69
  Puppet::Util::Windows::RootCerts.instance.to_a.uniq { |cert| cert.to_der }.each do |x509|
70
70
  begin
71
71
  add_cert(x509)
72
- rescue OpenSSL::X509::StoreError => e
72
+ rescue OpenSSL::X509::StoreError
73
73
  warn "Failed to add #{x509.subject.to_s}"
74
74
  end
75
75
  end
@@ -67,10 +67,10 @@ class Puppet::Util::NetworkDevice::Config
67
67
  count += 1
68
68
  }
69
69
  }
70
- rescue Errno::EACCES => detail
70
+ rescue Errno::EACCES
71
71
  Puppet.err _("Configuration error: Cannot read %{file}; cannot serve") % { file: @file }
72
72
  #raise Puppet::Error, "Cannot read #{@config}"
73
- rescue Errno::ENOENT => detail
73
+ rescue Errno::ENOENT
74
74
  Puppet.err _("Configuration error: '%{file}' does not exit; cannot serve") % { file: @file }
75
75
  end
76
76
 
@@ -45,7 +45,9 @@ module Puppet::Util::Plist
45
45
  {:failonfail => true, :combine => true})
46
46
  return parse_plist(plist)
47
47
  rescue Puppet::ExecutionFailure => detail
48
- Puppet.warning(_("Cannot read file %{file_path}; Puppet is skipping it.\nDetails: %{detail}") % { file_path: file_path, detail: detail })
48
+ message = _("Cannot read file %{file_path}; Puppet is skipping it.") % { file_path: file_path }
49
+ message += '\n' + _("Details: %{detail}") % { detail: detail }
50
+ Puppet.warning(message)
49
51
  end
50
52
  end
51
53
  return nil
@@ -122,11 +124,11 @@ module Puppet::Util::Plist
122
124
 
123
125
  def to_format(format)
124
126
  if format.to_sym == :xml
125
- plist_format = CFPropertyList::List::FORMAT_XML
127
+ CFPropertyList::List::FORMAT_XML
126
128
  elsif format.to_sym == :binary
127
- plist_format = CFPropertyList::List::FORMAT_BINARY
129
+ CFPropertyList::List::FORMAT_BINARY
128
130
  elsif format.to_sym == :plain
129
- plist_format = CFPropertyList::List::FORMAT_PLAIN
131
+ CFPropertyList::List::FORMAT_PLAIN
130
132
  else
131
133
  raise FormatError.new "Unknown plist format #{format}"
132
134
  end
@@ -896,7 +896,7 @@ module Generators
896
896
 
897
897
  def find_symbol(symbol, method=nil)
898
898
  res = @context.parent.find_symbol(symbol, method)
899
- res &&= res.viewer
899
+ res && res.viewer
900
900
  end
901
901
 
902
902
  end
@@ -8,7 +8,7 @@ module RDoc
8
8
  include PuppetParserCore
9
9
 
10
10
  def create_rdoc_preprocess
11
- preprocess = Markup::PreProcess.new(@input_file_name, @options.rdoc_include)
11
+ Markup::PreProcess.new(@input_file_name, @options.rdoc_include)
12
12
  end
13
13
  end
14
14
  end
@@ -53,7 +53,7 @@ class Puppet::Util::Storage
53
53
  Puppet.warning(_("Checksumfile %{filename} is not a file, ignoring") % { filename: filename })
54
54
  return
55
55
  end
56
- Puppet::Util.benchmark(:debug, "Loaded state") do
56
+ Puppet::Util.benchmark(:debug, "Loaded state in %{seconds} seconds") do
57
57
  begin
58
58
  @@state = Puppet::Util::Yaml.load_file(filename)
59
59
  rescue Puppet::Util::Yaml::YamlLoadError => detail
@@ -82,7 +82,7 @@ class Puppet::Util::Storage
82
82
 
83
83
  Puppet.info _("Creating state file %{file}") % { file: Puppet[:statefile] } unless Puppet::FileSystem.exist?(Puppet[:statefile])
84
84
 
85
- Puppet::Util.benchmark(:debug, "Stored state") do
85
+ Puppet::Util.benchmark(:debug, "Stored state in %{seconds} seconds") do
86
86
  Puppet::Util::Yaml.dump(@@state, Puppet[:statefile])
87
87
  end
88
88
  end
@@ -44,7 +44,7 @@ module Puppet::Util::Windows
44
44
  index = 0
45
45
  subkey = nil
46
46
 
47
- subkey_max_len, value_max_len = reg_query_info_key_max_lengths(key)
47
+ subkey_max_len, _ = reg_query_info_key_max_lengths(key)
48
48
 
49
49
  begin
50
50
  subkey, filetime = reg_enum_key(key, index, subkey_max_len)
@@ -69,7 +69,7 @@ module Puppet::Util::Windows
69
69
  index = 0
70
70
  subkey = nil
71
71
 
72
- subkey_max_len, value_max_len = reg_query_info_key_max_lengths(key)
72
+ _, value_max_len = reg_query_info_key_max_lengths(key)
73
73
 
74
74
  begin
75
75
  subkey, type, data = reg_enum_value(key, index, value_max_len)