puppet 4.4.2-x64-mingw32 → 4.5.0-x64-mingw32

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

Potentially problematic release.


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

Files changed (218) hide show
  1. data/CONTRIBUTING.md +5 -5
  2. data/Gemfile +2 -2
  3. data/LICENSE +2 -2
  4. data/README.md +5 -0
  5. data/ext/project_data.yaml +2 -0
  6. data/lib/hiera_puppet.rb +6 -14
  7. data/lib/puppet/application/agent.rb +2 -3
  8. data/lib/puppet/data_providers/hiera_config.rb +2 -4
  9. data/lib/puppet/data_providers/hiera_interpolate.rb +12 -154
  10. data/lib/puppet/data_providers/json_data_provider_factory.rb +0 -7
  11. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -8
  12. data/lib/puppet/defaults.rb +70 -7
  13. data/lib/puppet/functions.rb +69 -0
  14. data/lib/puppet/functions/dig.rb +39 -0
  15. data/lib/puppet/functions/lest.rb +53 -0
  16. data/lib/puppet/functions/lookup.rb +40 -27
  17. data/lib/puppet/functions/new.rb +502 -0
  18. data/lib/puppet/functions/regsubst.rb +11 -10
  19. data/lib/puppet/functions/then.rb +74 -0
  20. data/lib/puppet/functions/type.rb +4 -4
  21. data/lib/puppet/functions/with.rb +1 -1
  22. data/lib/puppet/indirector/catalog/compiler.rb +2 -0
  23. data/lib/puppet/indirector/resource_type/parser.rb +5 -0
  24. data/lib/puppet/indirector/rest.rb +5 -1
  25. data/lib/puppet/loaders.rb +2 -0
  26. data/lib/puppet/metatype/manager.rb +19 -2
  27. data/lib/puppet/module_tool/applications/application.rb +1 -1
  28. data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +6 -2
  29. data/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +19 -4
  30. data/lib/puppet/module_tool/skeleton/templates/generator/{tests → examples}/init.pp.erb +1 -1
  31. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +0 -1
  32. data/lib/puppet/network/http/api/master/v3/environment.rb +6 -2
  33. data/lib/puppet/parser/ast/pops_bridge.rb +20 -3
  34. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +24 -2
  35. data/lib/puppet/parser/e4_parser_adapter.rb +13 -12
  36. data/lib/puppet/parser/environment_compiler.rb +2 -2
  37. data/lib/puppet/parser/resource.rb +14 -5
  38. data/lib/puppet/parser/scope.rb +18 -15
  39. data/lib/puppet/plugins/data_providers/data_provider.rb +19 -8
  40. data/lib/puppet/pops.rb +6 -0
  41. data/lib/puppet/pops/adapters.rb +5 -1
  42. data/lib/puppet/pops/evaluator/access_operator.rb +52 -14
  43. data/lib/puppet/pops/evaluator/compare_operator.rb +34 -4
  44. data/lib/puppet/pops/evaluator/evaluator_impl.rb +75 -22
  45. data/lib/puppet/pops/evaluator/literal_evaluator.rb +7 -6
  46. data/lib/puppet/pops/evaluator/runtime3_converter.rb +13 -1
  47. data/lib/puppet/pops/evaluator/runtime3_support.rb +14 -4
  48. data/lib/puppet/pops/functions/dispatcher.rb +1 -1
  49. data/lib/puppet/pops/issues.rb +18 -2
  50. data/lib/puppet/pops/loader/base_loader.rb +48 -7
  51. data/lib/puppet/pops/loader/dependency_loader.rb +27 -2
  52. data/lib/puppet/pops/loader/loader.rb +12 -0
  53. data/lib/puppet/pops/loader/predefined_loader.rb +29 -0
  54. data/lib/puppet/pops/loader/runtime3_type_loader.rb +57 -0
  55. data/lib/puppet/pops/loader/static_loader.rb +92 -5
  56. data/lib/puppet/pops/loader/type_definition_instantiator.rb +25 -3
  57. data/lib/puppet/pops/loaders.rb +84 -14
  58. data/lib/puppet/pops/lookup/explainer.rb +38 -1
  59. data/lib/puppet/pops/lookup/interpolation.rb +115 -0
  60. data/lib/puppet/pops/lookup/sub_lookup.rb +86 -0
  61. data/lib/puppet/pops/model/ast_transformer.rb +8 -1
  62. data/lib/puppet/pops/model/factory.rb +31 -8
  63. data/lib/puppet/pops/model/model.rb +8 -0
  64. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  65. data/lib/puppet/pops/model/model_meta.rb +7 -1
  66. data/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
  67. data/lib/puppet/pops/parser/egrammar.ra +24 -7
  68. data/lib/puppet/pops/parser/eparser.rb +863 -798
  69. data/lib/puppet/pops/parser/evaluating_parser.rb +4 -0
  70. data/lib/puppet/pops/parser/locator.rb +8 -4
  71. data/lib/puppet/pops/pcore.rb +30 -0
  72. data/lib/puppet/pops/types/class_loader.rb +2 -4
  73. data/lib/puppet/pops/types/implementation_registry.rb +146 -0
  74. data/lib/puppet/pops/types/iterable.rb +4 -4
  75. data/lib/puppet/pops/types/p_object_type.rb +846 -0
  76. data/lib/puppet/pops/types/p_runtime_type.rb +102 -0
  77. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +164 -0
  78. data/lib/puppet/pops/types/p_sem_ver_type.rb +113 -0
  79. data/lib/puppet/pops/types/puppet_object.rb +21 -0
  80. data/lib/puppet/pops/types/ruby_generator.rb +258 -0
  81. data/lib/puppet/pops/types/string_converter.rb +922 -0
  82. data/lib/puppet/pops/types/type_calculator.rb +29 -5
  83. data/lib/puppet/pops/types/type_conversion_error.rb +15 -0
  84. data/lib/puppet/pops/types/type_factory.rb +49 -16
  85. data/lib/puppet/pops/types/type_formatter.rb +335 -112
  86. data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -29
  87. data/lib/puppet/pops/types/type_parser.rb +205 -197
  88. data/lib/puppet/pops/types/types.rb +481 -103
  89. data/lib/puppet/pops/validation.rb +1 -1
  90. data/lib/puppet/pops/validation/checker4_0.rb +66 -4
  91. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  92. data/lib/puppet/pops/visitor.rb +3 -1
  93. data/lib/puppet/property.rb +1 -1
  94. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  95. data/lib/puppet/provider/package/pip.rb +64 -20
  96. data/lib/puppet/provider/package/rpm.rb +112 -0
  97. data/lib/puppet/provider/package/yum.rb +7 -68
  98. data/lib/puppet/provider/service/daemontools.rb +3 -3
  99. data/lib/puppet/provider/service/init.rb +4 -2
  100. data/lib/puppet/provider/service/runit.rb +3 -3
  101. data/lib/puppet/provider/service/smf.rb +6 -3
  102. data/lib/puppet/provider/service/systemd.rb +59 -73
  103. data/lib/puppet/reference/providers.rb +1 -2
  104. data/lib/puppet/resource.rb +54 -37
  105. data/lib/puppet/resource/catalog.rb +31 -29
  106. data/lib/puppet/resource/type_collection.rb +23 -8
  107. data/lib/puppet/settings.rb +4 -2
  108. data/lib/puppet/settings/base_setting.rb +9 -3
  109. data/lib/puppet/settings/symbolic_enum_setting.rb +17 -0
  110. data/lib/puppet/test/test_helper.rb +0 -1
  111. data/lib/puppet/type.rb +9 -3
  112. data/lib/puppet/type/exec.rb +17 -17
  113. data/lib/puppet/type/file.rb +12 -0
  114. data/lib/puppet/type/file/content.rb +6 -6
  115. data/lib/puppet/type/file/ensure.rb +4 -4
  116. data/lib/puppet/type/file/source.rb +4 -4
  117. data/lib/puppet/type/file/target.rb +2 -2
  118. data/lib/puppet/type/mount.rb +18 -1
  119. data/lib/puppet/type/package.rb +3 -3
  120. data/lib/puppet/type/schedule.rb +4 -4
  121. data/lib/puppet/type/service.rb +15 -0
  122. data/lib/puppet/type/sshkey.rb +5 -3
  123. data/lib/puppet/type/tidy.rb +3 -3
  124. data/lib/puppet/type/zone.rb +5 -5
  125. data/lib/puppet/util/feature.rb +1 -1
  126. data/lib/puppet/util/monkey_patches.rb +8 -0
  127. data/lib/puppet/util/network_device/cisco/device.rb +16 -6
  128. data/lib/puppet/util/network_device/cisco/interface.rb +5 -6
  129. data/lib/puppet/util/plist.rb +3 -3
  130. data/lib/puppet/version.rb +1 -1
  131. data/spec/fixtures/unit/application/environments/production/data/common.yaml +13 -0
  132. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +2 -1
  133. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/manifests/init.pp +2 -1
  134. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/data/empty_key.json +1 -0
  135. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/hiera.yaml +5 -0
  136. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/manifests/init.pp +2 -0
  137. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/metadata.json +9 -0
  138. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/data/empty_key.yaml +1 -0
  139. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/hiera.yaml +5 -0
  140. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/manifests/init.pp +2 -0
  141. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/metadata.json +9 -0
  142. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
  143. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/type/usee_type.rb +5 -0
  144. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +6 -0
  145. data/spec/fixtures/unit/provider/service/smf/svcs.out +4 -3
  146. data/spec/integration/module_tool/tar/mini_spec.rb +27 -27
  147. data/spec/integration/parser/catalog_spec.rb +14 -2
  148. data/spec/integration/parser/compiler_spec.rb +94 -3
  149. data/spec/integration/parser/resource_expressions_spec.rb +1 -1
  150. data/spec/integration/resource/type_collection_spec.rb +8 -0
  151. data/spec/lib/puppet_spec/compiler.rb +11 -4
  152. data/spec/shared_contexts/types_setup.rb +4 -0
  153. data/spec/unit/application/lookup_spec.rb +91 -9
  154. data/spec/unit/appmgmt_spec.rb +44 -35
  155. data/spec/unit/capability_spec.rb +33 -53
  156. data/spec/unit/data_providers/function_data_provider_spec.rb +19 -1
  157. data/spec/unit/data_providers/hiera_data_provider_spec.rb +1 -1
  158. data/spec/unit/defaults_spec.rb +18 -0
  159. data/spec/unit/functions/assert_type_spec.rb +1 -1
  160. data/spec/unit/functions/dig_spec.rb +58 -0
  161. data/spec/unit/functions/lest_spec.rb +34 -0
  162. data/spec/unit/functions/lookup_spec.rb +108 -2
  163. data/spec/unit/functions/new_spec.rb +543 -0
  164. data/spec/unit/functions/regsubst_spec.rb +8 -0
  165. data/spec/unit/functions/then_spec.rb +40 -0
  166. data/spec/unit/functions4_spec.rb +78 -10
  167. data/spec/unit/hiera_puppet_spec.rb +49 -8
  168. data/spec/unit/indirector/resource_type/parser_spec.rb +5 -0
  169. data/spec/unit/indirector/rest_spec.rb +12 -0
  170. data/spec/unit/network/http/api/master/v3/environment_spec.rb +60 -0
  171. data/spec/unit/node/environment_spec.rb +10 -0
  172. data/spec/unit/parser/compiler_spec.rb +20 -1
  173. data/spec/unit/parser/functions/create_resources_spec.rb +2 -2
  174. data/spec/unit/parser/functions/shared.rb +1 -1
  175. data/spec/unit/parser/resource_spec.rb +8 -1
  176. data/spec/unit/parser/scope_spec.rb +45 -0
  177. data/spec/unit/pops/evaluator/access_ops_spec.rb +14 -0
  178. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +13 -5
  179. data/spec/unit/pops/loaders/static_loader_spec.rb +92 -1
  180. data/spec/unit/{data_providers/hiera_interpolation_spec.rb → pops/lookup/interpolation_spec.rb} +7 -5
  181. data/spec/unit/pops/parser/lexer2_spec.rb +2 -9
  182. data/spec/unit/pops/parser/parse_application_spec.rb +3 -8
  183. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +19 -0
  184. data/spec/unit/pops/parser/parse_capabilities_spec.rb +3 -10
  185. data/spec/unit/pops/parser/parse_site_spec.rb +19 -10
  186. data/spec/unit/pops/parser/parser_rspec_helper.rb +0 -4
  187. data/spec/unit/pops/types/enumeration_spec.rb +13 -12
  188. data/spec/unit/pops/types/iterable_spec.rb +2 -2
  189. data/spec/unit/pops/types/p_object_type_spec.rb +1060 -0
  190. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +285 -0
  191. data/spec/unit/pops/types/recursion_guard_spec.rb +19 -17
  192. data/spec/unit/pops/types/ruby_generator_spec.rb +261 -0
  193. data/spec/unit/pops/types/string_converter_spec.rb +904 -0
  194. data/spec/unit/pops/types/type_calculator_spec.rb +430 -406
  195. data/spec/unit/pops/types/type_factory_spec.rb +119 -104
  196. data/spec/unit/pops/types/type_formatter_spec.rb +73 -6
  197. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +2 -2
  198. data/spec/unit/pops/types/type_parser_spec.rb +54 -15
  199. data/spec/unit/pops/types/types_spec.rb +113 -8
  200. data/spec/unit/pops/validator/validator_spec.rb +84 -10
  201. data/spec/unit/provider/package/pip3_spec.rb +9 -270
  202. data/spec/unit/provider/package/pip_spec.rb +85 -30
  203. data/spec/unit/provider/package/rpm_spec.rb +160 -3
  204. data/spec/unit/provider/package/yum_spec.rb +23 -134
  205. data/spec/unit/provider/service/smf_spec.rb +14 -2
  206. data/spec/unit/provider/service/systemd_spec.rb +33 -41
  207. data/spec/unit/resource/capability_finder_spec.rb +10 -2
  208. data/spec/unit/settings/file_setting_spec.rb +6 -0
  209. data/spec/unit/transaction/additional_resource_generator_spec.rb +80 -65
  210. data/spec/unit/type/mount_spec.rb +51 -10
  211. data/spec/unit/type/service_spec.rb +16 -0
  212. data/spec/unit/type_spec.rb +14 -0
  213. data/spec/unit/util/feature_spec.rb +1 -1
  214. data/spec/unit/util/monkey_patches_spec.rb +60 -0
  215. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  216. metadata +63 -11
  217. data/lib/puppet/pops/types/types_meta.rb +0 -0
  218. data/spec/integration/provider/package_spec.rb +0 -35
@@ -16,9 +16,10 @@
16
16
  # @param regexp [String|Regexp|Type[Regexp]]
17
17
  # The regular expression matching the target string. If you want it anchored at the start
18
18
  # and or end of the string, you must do that with ^ and $ yourself.
19
- # @param replacement [String]
19
+ # @param replacement [String|Hash[String, String]]
20
20
  # Replacement string. Can contain backreferences to what was matched using \\0 (whole match),
21
21
  # \\1 (first set of parentheses), and so on.
22
+ # If the second argument is a Hash, and the matched text is one of its keys, the corresponding value is the replacement string.
22
23
  # @param flags [String]
23
24
  # Optional. String of single letter flags for how the regexp is interpreted (E, I, and M cannot be used
24
25
  # if pattern is a precompiled regexp):
@@ -37,18 +38,18 @@
37
38
  #
38
39
  Puppet::Functions.create_function(:regsubst) do
39
40
  dispatch :regsubst_string do
40
- param 'Variant[Array[String],String]', :target
41
- param 'String', :pattern
42
- param 'String', :replacement
43
- optional_param 'Optional[Pattern[/^[GEIM]*$/]]', :flags
44
- optional_param "Enum['N','E','S','U']", :encoding
41
+ param 'Variant[Array[String],String]', :target
42
+ param 'String', :pattern
43
+ param 'Variant[String,Hash[String,String]]', :replacement
44
+ optional_param 'Optional[Pattern[/^[GEIM]*$/]]', :flags
45
+ optional_param "Enum['N','E','S','U']", :encoding
45
46
  end
46
47
 
47
48
  dispatch :regsubst_regexp do
48
- param 'Variant[Array[String],String]', :target
49
- param 'Variant[Regexp,Type[Regexp]]', :pattern
50
- param 'String', :replacement
51
- optional_param 'Pattern[/^G?$/]', :flags
49
+ param 'Variant[Array[String],String]', :target
50
+ param 'Variant[Regexp,Type[Regexp]]', :pattern
51
+ param 'Variant[String,Hash[String,String]]', :replacement
52
+ optional_param 'Pattern[/^G?$/]', :flags
52
53
  end
53
54
 
54
55
  def regsubst_string(target, pattern, replacement, flags = nil, encoding = nil)
@@ -0,0 +1,74 @@
1
+ # Call a [lambda](https://docs.puppet.com/puppet/latest/reference/lang_lambdas.html)
2
+ # with the given argument unless the argument is undef. Return undef if argument is
3
+ # undef, and otherwise the result of giving the argument to the lambda.
4
+ #
5
+ # This is useful to process a sequence of operations where an intermediate
6
+ # result may be undef (which makes the entire sequence undef).
7
+ # The `then` function is especially useful with the function `dig` which
8
+ # performs in a similar way "digging out" a value in a complex structure.
9
+ #
10
+ # @example Using `then`
11
+ #
12
+ # ~~~ puppet
13
+ # $data = {a => { b => [{x => 10, y => 20}, {x => 100, y => 200}]}}
14
+ # notice $data.dig(a, b, 1, x).then |$x| { $x * 2 }
15
+ # ~~~
16
+ #
17
+ # Would notice the value 200
18
+ #
19
+ # Contrast this with:
20
+ #
21
+ # ~~~ puppet
22
+ # $data = {a => { b => [{x => 10, y => 20}, {ex => 100, why => 200}]}}
23
+ # notice $data.dig(a, b, 1, x).then |$x| { $x * 2 }
24
+ # ~~~
25
+ #
26
+ # Which would notice undef since the last lookup of 'x' results in `undef` which
27
+ # is returned (without calling the block).
28
+ #
29
+ # As a result there was no need for conditional logic or a temporary (non local)
30
+ # variable as the result is now either the wanted value (x) multiplied
31
+ # by 2 or `undef`.
32
+ #
33
+ # Calls to `then` can be chained. In the next example, a structure is using an offset that
34
+ # is using 1 as the index to the first element (instead of 0 which is used in the language).
35
+ # We are not sure if user input actually contains an index at all, or if it is
36
+ # outside the range of available names.
37
+ #
38
+ # ~~~ puppet
39
+ # # Names to choose from
40
+ # $names = ['Ringo', 'Paul', 'George', 'John']
41
+ #
42
+ # # structure where 'beatle 2' is wanted (but where the number refers
43
+ # # to 'Paul' because input comes from a source using 1 for the first
44
+ # # element).
45
+ #
46
+ # $data = [202, { beatle => 2 }]
47
+ # $picked = assert_type(String,
48
+ # # the data we are interested in is the second in the array,
49
+ # # a hash, where we want the value of the key 'beatle'
50
+ # $data.dig(1, 'beatle')
51
+ # # and we want the index in $names before the given index
52
+ # .then |$x| { $names[$x-1] }
53
+ # # so we can construct a string with that beatle's name
54
+ # .then |$x| { "Picked Beatle '${x}'" }
55
+ # )
56
+ #
57
+ # ~~~ puppet
58
+ #
59
+ # Would notice "Picked Beatle 'Paul'", and would raise an error if the result
60
+ # was not a String.
61
+ #
62
+ # @since 4.5.0
63
+ #
64
+ Puppet::Functions.create_function(:then) do
65
+ dispatch :then do
66
+ param 'Any', :arg
67
+ block_param 'Callable[1,1]', :block
68
+ end
69
+
70
+ def then(arg)
71
+ return nil if arg.nil?
72
+ yield(arg)
73
+ end
74
+ end
@@ -9,14 +9,14 @@
9
9
  # Would notice true
10
10
  #
11
11
  # By default, the best possible inference is made where all details are retained.
12
- # This is good when the type is used for futher type calculations but is overwhelmingly
13
- # rich i information if it is used in a error message.
12
+ # This is good when the type is used for further type calculations but is overwhelmingly
13
+ # rich in information if it is used in a error message.
14
14
  #
15
15
  # The optional argument `inference_method` may be given as (from lowest to highest fidelity):
16
16
  #
17
- # * ´generalized` - reduces to common type and drops size constraints
17
+ # * `generalized` - reduces to common type and drops size constraints
18
18
  # * `reduced` - reduces to common type in collections
19
- # * `detailed` - (defaut) all details about inferred types is retained
19
+ # * `detailed` - (default) all details about inferred types is retained
20
20
  #
21
21
  # @example Using `type()` with different qualities:
22
22
  #
@@ -1,4 +1,4 @@
1
- # Call a [lambda](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html)
1
+ # Call a [lambda](https://docs.puppet.com/puppet/latest/reference/lang_lambdas.html)
2
2
  # with the given arguments and return the result. Since a lambda's scope is
3
3
  # [local](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html#lambda-scope)
4
4
  # to the lambda, you can use the `with` function to create private blocks of code within a
@@ -267,6 +267,8 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
267
267
  rescue Puppet::Error => detail
268
268
  Puppet.err(detail.to_s) if networked?
269
269
  raise
270
+ ensure
271
+ Puppet::Type.clear_misses unless Puppet[:always_retry_plugins]
270
272
  end
271
273
 
272
274
  if checksum_type && config.is_a?(model)
@@ -100,4 +100,9 @@ class Puppet::Indirector::ResourceType::Parser < Puppet::Indirector::Code
100
100
  environment.check_for_reparse
101
101
  environment.known_resource_types
102
102
  end
103
+
104
+ def allow_remote_requests?
105
+ Puppet.deprecation_warning("The resource_type endpoint is deprecated in favor of the environment_classes endpoint. See https://docs.puppet.com/puppetserver/latest/puppet-api/v3/environment_classes.html")
106
+ super
107
+ end
103
108
  end
@@ -43,8 +43,12 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
43
43
 
44
44
  # Provide appropriate headers.
45
45
  def headers
46
+ # yaml is not allowed on the network
47
+ network_formats = model.supported_formats.reject do |format|
48
+ [:yaml, :b64_zlib_yaml].include?(format)
49
+ end
46
50
  common_headers = {
47
- "Accept" => model.supported_formats.join(", "),
51
+ "Accept" => network_formats.join(", "),
48
52
  Puppet::Network::HTTP::HEADER_PUPPET_VERSION => Puppet.version
49
53
  }
50
54
 
@@ -10,11 +10,13 @@ module Puppet
10
10
  require 'puppet/pops/loader/dependency_loader'
11
11
  require 'puppet/pops/loader/null_loader'
12
12
  require 'puppet/pops/loader/static_loader'
13
+ require 'puppet/pops/loader/runtime3_type_loader'
13
14
  require 'puppet/pops/loader/ruby_function_instantiator'
14
15
  require 'puppet/pops/loader/puppet_function_instantiator'
15
16
  require 'puppet/pops/loader/type_definition_instantiator'
16
17
  require 'puppet/pops/loader/loader_paths'
17
18
  require 'puppet/pops/loader/simple_environment_loader'
19
+ require 'puppet/pops/loader/predefined_loader'
18
20
  end
19
21
  end
20
22
 
@@ -20,6 +20,16 @@ module Manager
20
20
  }
21
21
  end
22
22
 
23
+ # Clears any types that were used but absent when types were last loaded.
24
+ # @note Used after each catalog compile when always_retry_plugins is false
25
+ # @api private
26
+ #
27
+ def clear_misses
28
+ unless @types.nil?
29
+ @types.delete_if {|_, v| v.nil? }
30
+ end
31
+ end
32
+
23
33
  # Iterates over all already loaded Type subclasses.
24
34
  # @yield [t] a block receiving each type
25
35
  # @yieldparam t [Puppet::Type] each defined type
@@ -116,6 +126,10 @@ module Manager
116
126
  klass.providerloader.loadall Puppet.lookup(:current_environment)
117
127
  klass.providify unless klass.providers.empty?
118
128
 
129
+ loc = block_given? ? block.source_location : nil
130
+ uri = loc.nil? ? nil : URI("#{Puppet::Util.path_to_uri(loc[0])}?line=#{loc[1]}")
131
+ Puppet::Pops::Loaders.register_runtime3_type(name, uri)
132
+
119
133
  klass
120
134
  end
121
135
 
@@ -146,16 +160,19 @@ module Manager
146
160
  # We are overwhelmingly symbols here, which usually match, so it is worth
147
161
  # having this special-case to return quickly. Like, 25K symbols vs. 300
148
162
  # strings in this method. --daniel 2012-07-17
149
- return @types[name] if @types[name]
163
+ return @types[name] if @types.include? name
150
164
 
151
165
  # Try mangling the name, if it is a string.
152
166
  if name.is_a? String
153
167
  name = name.downcase.intern
154
- return @types[name] if @types[name]
168
+ return @types[name] if @types.include? name
155
169
  end
156
170
  # Try loading the type.
157
171
  if typeloader.load(name, Puppet.lookup(:current_environment))
158
172
  Puppet.warning "Loaded puppet/type/#{name} but no class was created" unless @types.include? name
173
+ elsif !Puppet[:always_retry_plugins]
174
+ # PUP-5482 - Only look for a type once if plugin retry is disabled
175
+ @types[name] = nil
159
176
  end
160
177
 
161
178
  # ...and I guess that is that, eh.
@@ -41,7 +41,7 @@ module Puppet::ModuleTool
41
41
  end
42
42
 
43
43
  if require_metadata && !Puppet::ModuleTool.is_module_root?(@path)
44
- raise ArgumentError, "Unable to find metadata.json in module root at #{@path} See https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html for required file format."
44
+ raise ArgumentError, "Unable to find metadata.json in module root at #{@path} See https://docs.puppet.com/puppet/latest/reference/modules_publishing.html for required file format."
45
45
  end
46
46
 
47
47
  metadata_path = File.join(@path, 'metadata.json')
@@ -1,6 +1,6 @@
1
1
  source ENV['GEM_SOURCE'] || 'https://rubygems.org'
2
2
 
3
- puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['>= 3.3']
3
+ puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3']
4
4
  gem 'metadata-json-lint'
5
5
  gem 'puppet', puppetversion
6
6
  gem 'puppetlabs_spec_helper', '>= 1.0.0'
@@ -9,6 +9,10 @@ gem 'facter', '>= 1.7.0'
9
9
  gem 'rspec-puppet'
10
10
 
11
11
  # rspec must be v2 for ruby 1.8.7
12
- if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
12
+ if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9'
13
13
  gem 'rspec', '~> 2.0'
14
+ gem 'rake', '~> 10.0'
15
+ else
16
+ # rubocop requires ruby >= 1.9
17
+ gem 'rubocop'
14
18
  end
@@ -1,17 +1,32 @@
1
1
  require 'puppetlabs_spec_helper/rake_tasks'
2
2
  require 'puppet-lint/tasks/puppet-lint'
3
+ require 'metadata-json-lint/rake_task'
4
+
5
+ if RUBY_VERSION >= '1.9'
6
+ require 'rubocop/rake_task'
7
+ RuboCop::RakeTask.new
8
+ end
9
+
3
10
  PuppetLint.configuration.send('disable_80chars')
4
- PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
11
+ PuppetLint.configuration.relative = true
12
+ PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp']
5
13
 
6
- desc "Validate manifests, templates, and ruby files"
14
+ desc 'Validate manifests, templates, and ruby files'
7
15
  task :validate do
8
16
  Dir['manifests/**/*.pp'].each do |manifest|
9
17
  sh "puppet parser validate --noop #{manifest}"
10
18
  end
11
- Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
12
- sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
19
+ Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file|
20
+ sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures}
13
21
  end
14
22
  Dir['templates/**/*.erb'].each do |template|
15
23
  sh "erb -P -x -T '-' #{template} | ruby -c"
16
24
  end
17
25
  end
26
+
27
+ desc 'Run metadata_lint, lint, validate, and spec tests.'
28
+ task :test do
29
+ [:metadata_lint, :lint, :validate, :spec].each do |test|
30
+ Rake::Task[test].invoke
31
+ end
32
+ end
@@ -7,6 +7,6 @@
7
7
  # environment (to compare the resulting system state to the desired state).
8
8
  #
9
9
  # Learn more about module testing here:
10
- # https://docs.puppetlabs.com/guides/tests_smoke.html
10
+ # https://docs.puppet.com/guides/tests_smoke.html
11
11
  #
12
12
  include ::<%= metadata.name %>
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  describe '<%= metadata.name %>' do
3
-
4
3
  context 'with default values for all parameters' do
5
4
  it { should contain_class('<%= metadata.name %>') }
6
5
  end
@@ -5,14 +5,18 @@ class Puppet::Network::HTTP::API::Master::V3::Environment
5
5
  def call(request, response)
6
6
  env_name = request.routing_path.split('/').last
7
7
  env = Puppet.lookup(:environments).get(env_name)
8
+ code_id = request.params[:code_id]
8
9
 
9
10
  if env.nil?
10
11
  raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new("#{env_name} is not a known environment", Puppet::Network::HTTP::Issues::RESOURCE_NOT_FOUND)
11
12
  end
12
13
 
13
- catalog = Puppet::Parser::EnvironmentCompiler.compile(env).to_resource
14
+ catalog = Puppet::Parser::EnvironmentCompiler.compile(env, code_id).to_resource
14
15
 
15
- env_graph = {:environment => env.name, :applications => {}}
16
+ # This reads code_id off the catalog rather than using the one from the
17
+ # request. There shouldn't really be a case where the two differ, but if
18
+ # they do, the one from the catalog itself is authoritative.
19
+ env_graph = {:environment => env.name, :applications => {}, :code_id => catalog.code_id}
16
20
  applications = catalog.resources.select do |res|
17
21
  type = res.resource_type
18
22
  type.is_a?(Puppet::Resource::Type) && type.application?
@@ -102,6 +102,10 @@ class Puppet::Parser::AST::PopsBridge
102
102
  # The 3x logic calling this will not know what to do with the result, it is compacted away at the end
103
103
  instantiate_TypeAlias(d, modname)
104
104
  next
105
+ when Puppet::Pops::Model::TypeMapping
106
+ # The 3x logic calling this will not know what to do with the result, it is compacted away at the end
107
+ instantiate_TypeMapping(d, modname)
108
+ next
105
109
  when Puppet::Pops::Model::Application
106
110
  instantiate_ApplicationDefinition(d, modname)
107
111
  else
@@ -189,7 +193,9 @@ class Puppet::Parser::AST::PopsBridge
189
193
  end
190
194
 
191
195
  def instantiate_ResourceTypeDefinition(o, modname)
192
- Puppet::Resource::Type.new(:definition, o.name, @context.merge(args_from_definition(o, modname)))
196
+ instance = Puppet::Resource::Type.new(:definition, o.name, @context.merge(args_from_definition(o, modname)))
197
+ Puppet::Pops::Loaders.register_runtime3_type(instance.name, Puppet::Pops::Adapters::SourcePosAdapter.adapt(o).to_uri)
198
+ instance
193
199
  end
194
200
 
195
201
  def instantiate_CapabilityMapping(o, modname)
@@ -262,12 +268,23 @@ class Puppet::Parser::AST::PopsBridge
262
268
  loader = Puppet::Pops::Loaders.find_loader(modname)
263
269
 
264
270
  # Bind the type alias to the loader using the alias
265
- typed_name, t = Puppet::Pops::Loader::TypeDefinitionInstantiator.create_from_model(type_alias, loader)
266
- loader.set_entry(typed_name, t, Puppet::Pops::Adapters::SourcePosAdapter.adapt(type_alias).to_uri)
271
+ Puppet::Pops::Loader::TypeDefinitionInstantiator.create_from_model(type_alias, loader)
267
272
 
268
273
  nil # do not want the type alias to inadvertently leak into 3x
269
274
  end
270
275
 
276
+ # Adds the TypeMapping to the ImplementationRegistry
277
+ # This is for 4x evaluator/loader
278
+ #
279
+ def instantiate_TypeMapping(type_mapping, modname)
280
+ loader = Puppet::Pops::Loaders.find_loader(modname)
281
+ tf = Puppet::Pops::Types::TypeParser.new
282
+ lhs = tf.interpret(type_mapping.type_expr, loader)
283
+ rhs = tf.interpret_any(type_mapping.mapping_expr, loader)
284
+ Puppet::Pops::Loaders.implementation_registry.register_type_mapping(lhs, rhs, loader)
285
+ nil
286
+ end
287
+
271
288
  def code()
272
289
  Expression.new(:value => @value)
273
290
  end
@@ -15,9 +15,31 @@ class Puppet::Parser::Compiler
15
15
 
16
16
  private
17
17
 
18
+ # A hash lookup is 6x avg times faster than find among 3 values.
19
+ CAPABILITY_ACCEPTED_METAPARAMS = {:require => true, :consume => true, :export => true}.freeze
20
+
18
21
  def validate_relationship(param)
19
- unless [:require, :consume, :export].find {|pname| pname == param.name }
20
- raise CatalogValidationError.new("'#{param.name}' is not a valid relationship to a capability", param.file, param.line) if has_capability?(param.value)
22
+ # when relationship is to a capability
23
+ if has_capability?(param.value)
24
+ unless CAPABILITY_ACCEPTED_METAPARAMS[param.name]
25
+ raise CatalogValidationError.new(
26
+ "'#{param.name}' is not a valid relationship to a capability",
27
+ param.file, param.line)
28
+ end
29
+ elsif Puppet[:strict] != :off
30
+ # all other relationships requires the referenced resource to exist when mode is strict
31
+ refs = param.value.is_a?(Array) ? param.value.flatten : [param.value]
32
+ refs.each do |r|
33
+ next if r.nil?
34
+ unless catalog.resource(r.to_s)
35
+ msg = "Could not find resource '#{r.to_s}' in parameter '#{param.name.to_s}'"
36
+ if Puppet[:strict] == :error
37
+ raise CatalogValidationError.new(msg, param.file, param.line)
38
+ else
39
+ Puppet.warn_once(:undefined_resources, r.to_s, msg, param.file, param.line)
40
+ end
41
+ end
42
+ end
21
43
  end
22
44
  end
23
45
 
@@ -1,16 +1,16 @@
1
1
  require 'puppet/pops'
2
2
 
3
- module Puppet; module Parser; end; end;
3
+ module Puppet
4
+ module Parser
4
5
  # Adapts an egrammar/eparser to respond to the public API of the classic parser
5
6
  # and makes use of the new evaluator.
6
7
  #
7
- class Puppet::Parser::E4ParserAdapter
8
+ class E4ParserAdapter
8
9
 
9
10
  def initialize
10
11
  @file = ''
11
12
  @string = ''
12
13
  @use = :unspecified
13
- @@evaluating_parser ||= Puppet::Pops::Parser::EvaluatingParser.new()
14
14
  end
15
15
 
16
16
  def file=(file)
@@ -20,15 +20,15 @@ class Puppet::Parser::E4ParserAdapter
20
20
 
21
21
  def parse(string = nil)
22
22
  self.string= string if string
23
-
23
+ parser = Pops::Parser::EvaluatingParser.singleton
24
24
  parse_result =
25
25
  if @use == :string
26
26
  # Parse with a source_file to set in created AST objects (it was either given, or it may be unknown
27
27
  # if caller did not set a file and the present a string.
28
28
  #
29
- @@evaluating_parser.parse_string(@string, @file || "unknown-source-location")
29
+ parser.parse_string(@string, @file || "unknown-source-location")
30
30
  else
31
- @@evaluating_parser.parse_file(@file)
31
+ parser.parse_file(@file)
32
32
  end
33
33
 
34
34
  # the parse_result may be
@@ -38,19 +38,18 @@ class Puppet::Parser::E4ParserAdapter
38
38
  #
39
39
  model = parse_result.nil? ? nil : parse_result.current
40
40
  args = {}
41
- Puppet::Pops::Model::AstTransformer.new(@file).merge_location(args, model)
41
+ Pops::Model::AstTransformer.new(@file).merge_location(args, model)
42
42
 
43
43
  ast_code =
44
- if model.is_a? Puppet::Pops::Model::Program
45
- Puppet::Parser::AST::PopsBridge::Program.new(model, args)
44
+ if model.is_a? Pops::Model::Program
45
+ AST::PopsBridge::Program.new(model, args)
46
46
  else
47
47
  args[:value] = model
48
- Puppet::Parser::AST::PopsBridge::Expression.new(args)
48
+ AST::PopsBridge::Expression.new(args)
49
49
  end
50
50
 
51
51
  # Create the "main" class for the content - this content will get merged with all other "main" content
52
- Puppet::Parser::AST::Hostclass.new('', :code => ast_code)
53
-
52
+ AST::Hostclass.new('', :code => ast_code)
54
53
  end
55
54
 
56
55
  def string=(string)
@@ -58,3 +57,5 @@ class Puppet::Parser::E4ParserAdapter
58
57
  @use = :string
59
58
  end
60
59
  end
60
+ end
61
+ end