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
@@ -99,7 +99,6 @@ Puppet::Face.define(:parser, '0.0.1') do
99
99
  raise Puppet::Error, _("No input to parse given on command line or stdin")
100
100
  end
101
101
  else
102
- missing_files = []
103
102
  files = args
104
103
  available_files = files.select do |file|
105
104
  Puppet::FileSystem.exist?(file)
@@ -13,6 +13,7 @@ Puppet::Indirector::Face.define(:status, '0.0.1') do
13
13
  find = get_action(:find)
14
14
  find.default = true
15
15
  find.summary _("Check status of puppet master server.")
16
+ #TRANSLATORS the string 'Puppet::Status' is a Puppet language object and should not be translated
16
17
  find.returns _(<<-'EOT')
17
18
  A "true" response or a low-level connection error. When used from the Ruby
18
19
  API: returns a Puppet::Status object.
@@ -83,7 +83,7 @@ Puppet.features.add(:manages_symlinks) do
83
83
  attach_function :CreateSymbolicLinkW, [:lpwstr, :lpwstr, :dword], :boolean
84
84
 
85
85
  true
86
- rescue LoadError => err
86
+ rescue LoadError
87
87
  Puppet.debug("CreateSymbolicLink is not available")
88
88
  false
89
89
  end
@@ -17,7 +17,6 @@ class Puppet::FileBucket::Dipper
17
17
  # Emulate the XMLRPC client
18
18
  server = hash[:Server]
19
19
  port = hash[:Port] || Puppet[:masterport]
20
- environment = Puppet[:environment]
21
20
 
22
21
  if hash.include?(:Path)
23
22
  @local_path = hash[:Path]
@@ -144,7 +144,7 @@ class Puppet::FileSystem::Uniquefile < DelegateClass(File)
144
144
  def try_convert_to_hash(h)
145
145
  begin
146
146
  h.to_hash
147
- rescue NoMethodError => e
147
+ rescue NoMethodError
148
148
  nil
149
149
  end
150
150
  end
@@ -154,7 +154,7 @@ class Puppet::FileSystem::Uniquefile < DelegateClass(File)
154
154
  def tmpdir
155
155
  tmp = '.'
156
156
  if $SAFE > 0
157
- tmp = @@systmpdir
157
+ @@systmpdir
158
158
  else
159
159
  for dir in [ Puppet::Util.get_env('TMPDIR'), Puppet::Util.get_env('TMP'), Puppet::Util.get_env('TEMP'), @@systmpdir, '/tmp']
160
160
  if dir and stat = File.stat(dir) and stat.directory? and stat.writable?
@@ -32,12 +32,12 @@ module Puppet::Forge::Errors
32
32
  #
33
33
  # @return [String] the multiline version of the error message
34
34
  def multiline
35
- _(<<-EOS).chomp % { uri: @uri }
36
- Could not connect via HTTPS to %{uri}
37
- Unable to verify the SSL certificate
38
- The certificate may not be signed by a valid CA
39
- The CA bundle included with OpenSSL may not be valid or up to date
40
- EOS
35
+ message = []
36
+ message << _('Could not connect via HTTPS to %{uri}') % { uri: @uri }
37
+ message << _(' Unable to verify the SSL certificate')
38
+ message << _(' The certificate may not be signed by a valid CA')
39
+ message << _(' The CA bundle included with OpenSSL may not be valid or up to date')
40
+ message.join("\n")
41
41
  end
42
42
  end
43
43
 
@@ -59,12 +59,12 @@ Could not connect via HTTPS to %{uri}
59
59
  #
60
60
  # @return [String] the multiline version of the error message
61
61
  def multiline
62
- _(<<-EOS).chomp % { uri: @uri, detail: @detail }
63
- Could not connect to %{uri}
64
- There was a network communications problem
65
- The error we caught said '%{detail}'
66
- Check your network connection and try again
67
- EOS
62
+ message = []
63
+ message << _('Could not connect to %{uri}') % { uri: @uri }
64
+ message << _(' There was a network communications problem')
65
+ message << _(" The error we caught said '%{detail}'") % { detail: @detail }
66
+ message << _(' Check your network connection and try again')
67
+ message.join("\n")
68
68
  end
69
69
  end
70
70
 
@@ -90,10 +90,9 @@ Could not connect to %{uri}
90
90
  end
91
91
 
92
92
  message = if @message
93
- _("Request to Puppet Forge failed. Detail: %{error_message} / %{http_response}.") %
94
- { error_message: @message, http_response: @response }
93
+ _("Request to Puppet Forge failed.") + ' ' + _("Detail: %{detail}.") % { detail: "#{@message} / #{@response}" }
95
94
  else
96
- _("Request to Puppet Forge failed. Detail: %{http_response}.") % { http_response: @response }
95
+ _("Request to Puppet Forge failed.") + ' ' + _("Detail: %{detail}.") % { detail: @response }
97
96
  end
98
97
  super(message, original)
99
98
  end
@@ -102,20 +101,13 @@ Could not connect to %{uri}
102
101
  #
103
102
  # @return [String] the multiline version of the error message
104
103
  def multiline
105
- if @message
106
- _(<<-EOS).chomp % { uri: @uri, response: @response, message: @message }
107
- Request to Puppet Forge failed.
108
- The server being queried was %{uri}
109
- The HTTP response we received was '%{response}'
110
- The message we received said '%{message}'
111
- EOS
112
- else
113
- _(<<-EOS).chomp % { uri: @uri, response: @response }
114
- Request to Puppet Forge failed.
115
- The server being queried was %{uri}
116
- The HTTP response we received was '%{response}'
117
- EOS
118
- end
104
+
105
+ message = []
106
+ message << _('Request to Puppet Forge failed.')
107
+ message << _(' The server being queried was %{uri}') % { uri: @uri }
108
+ message << _(" The HTTP response we received was '%{response}'") % { response: @response }
109
+ message << _(" The message we received said '%{message}'") % { message: @message } if @message
110
+ message.join("\n")
119
111
  end
120
112
  end
121
113
 
@@ -186,8 +186,12 @@ module Puppet::Functions
186
186
  # and it will fail unless protected with an if defined? if the local
187
187
  # variable does not exist in the block's binder.
188
188
  #
189
- loader = block.binding.eval('loader_injected_arg if defined?(loader_injected_arg)')
190
- create_loaded_function(func_name, loader, function_base, &block)
189
+ begin
190
+ loader = block.binding.eval('loader_injected_arg if defined?(loader_injected_arg)')
191
+ create_loaded_function(func_name, loader, function_base, &block)
192
+ rescue StandardError => e
193
+ raise ArgumentError, _("Function Load Error for function '%{function_name}': %{message}") % {function_name: func_name, message: e.message}
194
+ end
191
195
  end
192
196
 
193
197
  # Creates a function in, or in a local loader under the given loader.
@@ -573,14 +577,27 @@ module Puppet::Functions
573
577
  # @api private
574
578
  def create_callable(types, block_type, return_type, from, to)
575
579
  mapped_types = types.map do |t|
576
- t.is_a?(Puppet::Pops::Types::PAnyType) ? t : Puppet::Pops::Types::TypeParser.singleton.parse(t, loader)
580
+ t.is_a?(Puppet::Pops::Types::PAnyType) ? t : internal_type_parse(t, loader)
577
581
  end
578
582
  param_types = Puppet::Pops::Types::PTupleType.new(mapped_types, from > 0 && from == to ? nil : Puppet::Pops::Types::PIntegerType.new(from, to))
579
- return_type = Puppet::Pops::Types::TypeParser.singleton.parse(return_type, loader) unless return_type.nil? || return_type.is_a?(Puppet::Pops::Types::PAnyType)
583
+ return_type = internal_type_parse(return_type, loader) unless return_type.nil? || return_type.is_a?(Puppet::Pops::Types::PAnyType)
580
584
  Puppet::Pops::Types::PCallableType.new(param_types, block_type, return_type)
581
585
  end
586
+
587
+ def internal_type_parse(type_string, loader)
588
+ begin
589
+ Puppet::Pops::Types::TypeParser.singleton.parse(type_string, loader)
590
+ rescue StandardError => e
591
+ raise ArgumentError, _("Parsing of type string '\"%{type_string}\"' failed with message: <%{message}>.\n") % {
592
+ type_string: type_string,
593
+ message: e.message
594
+ }
595
+ end
596
+ end
597
+ private :internal_type_parse
582
598
  end
583
599
 
600
+
584
601
  # The LocalTypeAliasBuilder is used by the 'local_types' method to collect the individual
585
602
  # type aliases given by the function's author.
586
603
  #
@@ -603,9 +620,31 @@ module Puppet::Functions
603
620
  # @api public
604
621
  #
605
622
  def type(assignment_string)
606
- result = parser.parse_string("type #{assignment_string}", nil) # no file source :-(
623
+ # Get location to use in case of error - this produces ruby filename and where call to 'type' occurred
624
+ # but strips off the rest of the internal "where" as it is not meaningful to user.
625
+ #
626
+ rb_location = caller[0]
627
+
628
+ begin
629
+ result = parser.parse_string("type #{assignment_string}", nil)
630
+ rescue StandardError => e
631
+ rb_location = rb_location.gsub(/:in.*$/, '')
632
+ # Create a meaningful location for parse errors - show both what went wrong with the parsing
633
+ # and in which ruby file it was found.
634
+ raise ArgumentError, _("Parsing of 'type \"%{assignment_string}\"' failed with message: <%{message}>.\n" +
635
+ "Called from <%{ruby_file_location}>") % {
636
+ assignment_string: assignment_string,
637
+ message: e.message,
638
+ ruby_file_location: rb_location
639
+ }
640
+ end
607
641
  unless result.body.kind_of?(Puppet::Pops::Model::TypeAlias)
608
- raise ArgumentError, _("Expected a type alias assignment on the form 'AliasType = T', got '%{assignment_string}'") % { assignment_string: assignment_string }
642
+ rb_location = rb_location.gsub(/:in.*$/, '')
643
+ raise ArgumentError, _("Expected a type alias assignment on the form 'AliasType = T', got '%{assignment_string}'.\n"+
644
+ "Called from <%{ruby_file_location}>") % {
645
+ assignment_string: assignment_string,
646
+ ruby_file_location: rb_location
647
+ }
609
648
  end
610
649
  @local_types << result.body
611
650
  end
@@ -618,30 +657,7 @@ module Puppet::Functions
618
657
  #
619
658
  # This is a private, internal, system for creating functions. It supports
620
659
  # everything that the public function definition system supports as well as a
621
- # few extra features.
622
- #
623
- # Injection Support
624
- # ===
625
- # The Function API supports injection of data and services. It is possible to
626
- # make injection that takes effect when the function is loaded (for services
627
- # and runtime configuration that does not change depending on how/from where
628
- # in what context the function is called. It is also possible to inject and
629
- # weave argument values into a call.
630
- #
631
- # Injection of attributes
632
- # ---
633
- # Injection of attributes is performed by one of the methods `attr_injected`,
634
- # and `attr_injected_producer`. The injected attributes are available via
635
- # accessor method calls.
636
- #
637
- # @example using injected attributes
638
- # Puppet::Functions.create_function('test') do
639
- # attr_injected String, :larger, 'message_larger'
640
- # attr_injected String, :smaller, 'message_smaller'
641
- # def test(a, b)
642
- # a > b ? larger() : smaller()
643
- # end
644
- # end
660
+ # few extra features such as injection of well known parameters.
645
661
  #
646
662
  # @api private
647
663
  class InternalFunction < Function
@@ -665,26 +681,22 @@ module Puppet::Functions
665
681
  end
666
682
  end
667
683
 
668
- # @note WARNING: This style of creating functions is not public. It is a system
669
- # under development that will be used for creating "system" functions.
670
- #
671
684
  # Injection and Weaving of parameters
672
685
  # ---
673
- # It is possible to inject and weave parameters into a call. These extra
674
- # parameters are not part of the parameters passed from the Puppet logic, and
675
- # they can not be overridden by parameters given as arguments in the call.
676
- # They are invisible to the Puppet Language.
686
+ # It is possible to inject and weave a set of well known parameters into a call.
687
+ # These extra parameters are not part of the parameters passed from the Puppet
688
+ # logic, and they can not be overridden by parameters given as arguments in the
689
+ # call. They are invisible to the Puppet Language.
677
690
  #
678
691
  # @example using injected parameters
679
692
  # Puppet::Functions.create_function('test') do
680
693
  # dispatch :test do
681
694
  # param 'Scalar', 'a'
682
695
  # param 'Scalar', 'b'
683
- # injected_param 'String', 'larger', 'message_larger'
684
- # injected_param 'String', 'smaller', 'message_smaller'
696
+ # scope_param
685
697
  # end
686
- # def test(a, b, larger, smaller)
687
- # a > b ? larger : smaller
698
+ # def test(a, b, scope)
699
+ # a > b ? scope['a'] : scope['b']
688
700
  # end
689
701
  # end
690
702
  #
@@ -692,54 +704,22 @@ module Puppet::Functions
692
704
  #
693
705
  # test(10, 20)
694
706
  #
695
- # Using injected value as default
696
- # ---
697
- # Default value assignment is handled by using the regular Ruby mechanism (a
698
- # value is assigned to the variable). The dispatch simply indicates that the
699
- # value is optional. If the default value should be injected, it can be
700
- # handled different ways depending on what is desired:
701
- #
702
- # * by calling the accessor method for an injected Function class attribute.
703
- # This is suitable if the value is constant across all instantiations of the
704
- # function, and across all calls.
705
- # * by injecting a parameter into the call
706
- # to the left of the parameter, and then assigning that as the default value.
707
- # * One of the above forms, but using an injected producer instead of a
708
- # directly injected value.
709
- #
710
- # @example method with injected default values
711
- # Puppet::Functions.create_function('test') do
712
- # dispatch :test do
713
- # injected_param String, 'b_default', 'b_default_value_key'
714
- # param 'Scalar', 'a'
715
- # param 'Scalar', 'b'
716
- # end
717
- # def test(b_default, a, b = b_default)
718
- # # ...
719
- # end
720
- # end
721
- #
722
707
  # @api private
723
708
  class InternalDispatchBuilder < DispatcherBuilder
724
- def scope_param()
725
- @injections << [:scope, 'scope', '', :dispatcher_internal]
726
- # mark what should be picked for this position when dispatching
727
- @weaving << [@injections.size()-1]
709
+ # Inject parameter for `Puppet::Parser::Scope`
710
+ def scope_param
711
+ inject(:scope)
728
712
  end
729
- # TODO: is param name really needed? Perhaps for error messages? (it is unused now)
730
- #
731
- # @api private
732
- def injected_param(type, name, injection_name = '')
733
- @injections << [type, name, injection_name]
734
- # mark what should be picked for this position when dispatching
735
- @weaving << [@injections.size() -1]
713
+
714
+ # Inject parameter for `Puppet::Pal::ScriptCompiler`
715
+ def script_compiler_param
716
+ inject(:pal_script_compiler)
736
717
  end
737
718
 
738
- # TODO: is param name really needed? Perhaps for error messages? (it is unused now)
739
- #
740
- # @api private
741
- def injected_producer_param(type, name, injection_name = '')
742
- @injections << [type, name, injection_name, :producer]
719
+ private
720
+
721
+ def inject(injection_name)
722
+ @injections << injection_name
743
723
  # mark what should be picked for this position when dispatching
744
724
  @weaving << [@injections.size()-1]
745
725
  end
@@ -105,7 +105,6 @@ Puppet::Functions.create_function(:'defined', Puppet::Functions::InternalFunctio
105
105
  end
106
106
 
107
107
  def is_defined(scope, *vals)
108
- env = scope.environment
109
108
  vals.any? do |val|
110
109
  case val
111
110
  when String
@@ -120,7 +119,6 @@ Puppet::Functions.create_function(:'defined', Puppet::Functions::InternalFunctio
120
119
  Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_main_class(scope)
121
120
  else
122
121
  # Find a resource type, definition or class definition
123
- krt = scope.environment.known_resource_types
124
122
  Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(scope, val)
125
123
  end
126
124
  end
@@ -150,7 +148,6 @@ Puppet::Functions.create_function(:'defined', Puppet::Functions::InternalFunctio
150
148
  #
151
149
  raise ArgumentError, _('The given class type is a reference to all classes') if val.type.class_name.nil?
152
150
  Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_hostclass(scope, val.type.class_name)
153
- #scope.environment.known_resource_types.find_hostclass(val.type.class_name)
154
151
  end
155
152
  else
156
153
  raise ArgumentError, _("Invalid argument of type '%{value_class}' to 'defined'") % { value_class: val.class }
@@ -19,7 +19,6 @@ Puppet::Functions.create_function(:find_file, Puppet::Functions::InternalFunctio
19
19
  end
20
20
 
21
21
  def find_file(scope, *args)
22
- path = nil
23
22
  args.each do |file|
24
23
  found = Puppet::Parser::Files.find_file(file, scope.compiler.environment)
25
24
  if found && Puppet::FileSystem.exist?(found)
@@ -107,7 +107,6 @@ Puppet::Functions.create_function(:map) do
107
107
 
108
108
  def map_Enumerable_1(enumerable)
109
109
  result = []
110
- index = 0
111
110
  enum = Puppet::Pops::Types::Iterable.asserted_iterable(self, enumerable)
112
111
  begin
113
112
  loop { result << yield(enum.next) }
@@ -66,7 +66,7 @@ Puppet::Functions.create_function(:regsubst) do
66
66
 
67
67
  def regsubst_regexp(target, pattern, replacement, flags = nil)
68
68
  pattern = (pattern.pattern || '') if pattern.is_a?(Puppet::Pops::Types::PRegexpType)
69
- inner_regsubst(target, pattern, replacement, operation = flags == 'G' ? :gsub : :sub)
69
+ inner_regsubst(target, pattern, replacement, flags == 'G' ? :gsub : :sub)
70
70
  end
71
71
 
72
72
  def inner_regsubst(target, re, replacement, op)
@@ -228,23 +228,19 @@ class Puppet::Graph::SimpleGraph
228
228
  number_of_cycles = cycles.length
229
229
  return if number_of_cycles == 0
230
230
 
231
- cycle_path_list = ''
231
+ message = n_("Found %{num} dependency cycle:\n", "Found %{num} dependency cycles:\n", number_of_cycles) % { num: number_of_cycles }
232
+
232
233
  cycles.each do |cycle|
233
234
  paths = paths_in_cycle(cycle)
234
- cycle_path_list += paths.map{ |path| '(' + path.join(' => ') + ')'}.join('\n')
235
+ message += paths.map{ |path| '(' + path.join(' => ') + ')'}.join('\n') + '\n'
235
236
  end
236
237
 
237
238
  if Puppet[:graph] then
238
239
  filename = write_cycles_to_graph(cycles)
239
- message = n_("Found %{number_of_cycles} dependency cycle:\n%{cycle_path_list}\nCycle graph written to %{filename}.",
240
- "Found %{number_of_cycles} dependency cycles:\n%{cycle_path_list}\nCycle graph written to %{filename}.", number_of_cycles) %
241
- { number_of_cycles: number_of_cycles, cycle_path_list: cycle_path_list, filename: filename }
240
+ message += _("Cycle graph written to %{filename}.") % { filename: filename }
242
241
  else
243
- #TRANSLATORS '--graph' refers to a command line option and should not be translated
244
- #TRANSLATORS OmniGraffle and GraphViz and program names and should not be translated
245
- message = n_("Found %{number_of_cycles} dependency cycle:\n%{cycle_path_list}\nTry the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz",
246
- "Found %{number_of_cycles} dependency cycles:\n%{cycle_path_list}\nTry the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz", number_of_cycles) %
247
- { number_of_cycles: number_of_cycles, cycle_path_list: cycle_path_list }
242
+ #TRANSLATORS '--graph' refers to a command line option and OmniGraffle and GraphViz are program names and should not be translated
243
+ message += _("Try the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz")
248
244
  end
249
245
  Puppet.err(message)
250
246
  cycles
@@ -178,7 +178,6 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
178
178
  # TODO: get property/parameter defaults if entries are nil in the resource
179
179
  # For now they're hard-coded to match the File type.
180
180
 
181
- file_metadata = {}
182
181
  list_of_resources.each do |resource|
183
182
  sources = [resource[:source]].flatten.compact
184
183
  next unless inlineable?(resource, sources)
@@ -277,24 +276,31 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
277
276
  raise Puppet::Error, _("Unable to find a common checksum type between agent '%{agent_type}' and master '%{master_type}'.") % { agent_type: options[:checksum_type], master_type: known_checksum_types } unless checksum_type
278
277
  end
279
278
 
280
- str = if checksum_type
281
- if node.environment
282
- _("Compiled static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
283
- else
284
- _("Compiled static catalog for %{node}") % { node: node.name }
285
- end
286
- else
287
- if node.environment
288
- _("Compiled catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
289
- else
290
- _("Compiled catalog for %{node}") % { node: node.name }
291
- end
292
- end
279
+ escaped_node_name = node.name.gsub(/%/, '%%')
280
+ if checksum_type
281
+ if node.environment
282
+ escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
283
+ benchmark_str = _("Compiled static catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
284
+ profile_str = _("Compiled static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
285
+ else
286
+ benchmark_str = _("Compiled static catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
287
+ profile_str = _("Compiled static catalog for %{node}") % { node: node.name }
288
+ end
289
+ else
290
+ if node.environment
291
+ escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
292
+ benchmark_str = _("Compiled catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
293
+ profile_str = _("Compiled catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
294
+ else
295
+ benchmark_str = _("Compiled catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
296
+ profile_str = _("Compiled catalog for %{node}") % { node: node.name }
297
+ end
298
+ end
293
299
  config = nil
294
300
 
295
- benchmark(:notice, str) do
301
+ benchmark(:notice, benchmark_str) do
296
302
  compile_type = checksum_type ? :static_compile : :compile
297
- Puppet::Util::Profiler.profile(str, [:compiler, compile_type, node.environment, node.name]) do
303
+ Puppet::Util::Profiler.profile(profile_str, [:compiler, compile_type, node.environment, node.name]) do
298
304
  begin
299
305
  config = Puppet::Parser::Compiler.compile(node, options[:code_id])
300
306
  rescue Puppet::Error => detail
@@ -305,15 +311,21 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
305
311
  end
306
312
 
307
313
  if checksum_type && config.is_a?(model)
308
- str = if node.environment
309
- #TRANSLATORS Inlined refers to adding additional metadata
310
- _("Inlined resource metadata into static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
311
- else
312
- #TRANSLATORS Inlined refers to adding additional metadata
313
- _("Inlined resource metadata into static catalog for %{node}") % { node: node.name }
314
- end
315
- benchmark(:notice, str) do
316
- Puppet::Util::Profiler.profile(str, [:compiler, :static_compile_postprocessing, node.environment, node.name]) do
314
+ escaped_node_name = node.name.gsub(/%/, '%%')
315
+ if node.environment
316
+ escaped_node_environment = node.environment.to_s.gsub(/%/, '%%')
317
+ #TRANSLATORS Inlined refers to adding additional metadata
318
+ benchmark_str = _("Inlined resource metadata into static catalog for %{node} in environment %{environment} in %%{seconds} seconds") % { node: escaped_node_name, environment: escaped_node_environment }
319
+ #TRANSLATORS Inlined refers to adding additional metadata
320
+ profile_str = _("Inlined resource metadata into static catalog for %{node} in environment %{environment}") % { node: node.name, environment: node.environment }
321
+ else
322
+ #TRANSLATORS Inlined refers to adding additional metadata
323
+ benchmark_str = _("Inlined resource metadata into static catalog for %{node} in %%{seconds} seconds") % { node: escaped_node_name }
324
+ #TRANSLATORS Inlined refers to adding additional metadata
325
+ profile_str = _("Inlined resource metadata into static catalog for %{node}") % { node: node.name }
326
+ end
327
+ benchmark(:notice, benchmark_str) do
328
+ Puppet::Util::Profiler.profile(profile_str, [:compiler, :static_compile_postprocessing, node.environment, node.name]) do
317
329
  inline_metadata(config, checksum_type)
318
330
  end
319
331
  end