puppet 4.4.2-universal-darwin → 4.5.0-universal-darwin

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
@@ -1,5 +1,5 @@
1
- require 'rgen/ecore/ecore'
2
-
1
+ module Puppet::Pops
2
+ module Evaluator
3
3
  # Literal values for
4
4
  # String (not containing interpolation)
5
5
  # Numbers
@@ -14,14 +14,13 @@ require 'rgen/ecore/ecore'
14
14
  # Not considered literal
15
15
  # QualifiedReference # i.e. File, FooBar
16
16
  #
17
- class Puppet::Pops::Evaluator::LiteralEvaluator
18
- #include Puppet::Pops::Utils
17
+ class LiteralEvaluator
19
18
 
20
19
  EMPTY_STRING = ''.freeze
21
20
  COMMA_SEPARATOR = ', '.freeze
22
21
 
23
22
  def initialize
24
- @@literal_visitor ||= Puppet::Pops::Visitor.new(self, "literal", 0, 0)
23
+ @@literal_visitor ||= Visitor.new(self, "literal", 0, 0)
25
24
  end
26
25
 
27
26
  def literal(ast)
@@ -70,7 +69,7 @@ class Puppet::Pops::Evaluator::LiteralEvaluator
70
69
 
71
70
  def literal_ConcatenatedString(o)
72
71
  # use double quoted string value if there is no interpolation
73
- throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Puppet::Pops::Model::LiteralString)
72
+ throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Model::LiteralString)
74
73
  o.segments[0].value
75
74
  end
76
75
 
@@ -85,3 +84,5 @@ class Puppet::Pops::Evaluator::LiteralEvaluator
85
84
  end
86
85
  end
87
86
  end
87
+ end
88
+ end
@@ -100,6 +100,18 @@ class Runtime3Converter
100
100
  end
101
101
  alias :convert2_Regexp :convert_Regexp
102
102
 
103
+ def convert_SemVer(o, scope, undef_value)
104
+ # Puppet 3x cannot handle SemVers. Use the string form
105
+ o.to_s
106
+ end
107
+ alias :convert2_SemVer :convert_SemVer
108
+
109
+ def convert_SemVerRange(o, scope, undef_value)
110
+ # Puppet 3x cannot handle SemVerRanges. Use the string form
111
+ o.to_s
112
+ end
113
+ alias :convert2_SemVerRange :convert_SemVerRange
114
+
103
115
  def convert_Symbol(o, scope, undef_value)
104
116
  case o
105
117
  # Support :undef since it may come from a 3x structure
@@ -150,7 +162,7 @@ class Runtime3Converter
150
162
  else
151
163
  # Ensure that title is '' if nil
152
164
  # Resources with absolute name always results in error because tagging does not support leading ::
153
- [type_name.nil? ? nil : type_name.sub(/^::/, ''), title.nil? ? '' : title]
165
+ [type_name.nil? ? nil : type_name.sub(/^::/, '').downcase, title.nil? ? '' : title]
154
166
  end
155
167
  else
156
168
  raise ArgumentError, "Cannot split the type #{catalog_type.class}, it represents neither a PHostClassType, nor a PResourceType."
@@ -82,7 +82,7 @@ module Runtime3Support
82
82
  # Must convert :undef back to nil - this can happen when an undefined variable is used in a
83
83
  # parameter's default value expression - there nil must be :undef to work with the rest of 3x.
84
84
  # Now that the value comes back to 4x it is changed to nil.
85
- return (x == :undef) ? nil : x
85
+ return :undef == x ? nil : x
86
86
  }
87
87
  # It is always ok to reference numeric variables even if they are not assigned. They are always undef
88
88
  # if not set by a match expression.
@@ -90,7 +90,7 @@ module Runtime3Support
90
90
  unless name =~ Puppet::Pops::Patterns::NUMERIC_VAR_NAME
91
91
  optionally_fail(Puppet::Pops::Issues::UNKNOWN_VARIABLE, o, {:name => name})
92
92
  end
93
- nil # in case unknown variable is configured as a warning
93
+ nil # in case unknown variable is configured as a warning or ignore
94
94
  end
95
95
 
96
96
  # Returns true if the variable of the given name is set in the given most nested scope. True is returned even if
@@ -497,7 +497,17 @@ module Runtime3Support
497
497
  p[Issues::EMPTY_RESOURCE_SPECIALIZATION] = :ignore
498
498
  end
499
499
 
500
- p[Issues::UNKNOWN_VARIABLE] = Puppet[:strict_variables] ? :error : :warning
500
+ # if strict variables are on, an error is raised
501
+ # if strict variables are off, the Puppet[strict] defines what is done
502
+ #
503
+ if Puppet[:strict_variables]
504
+ p[Issues::UNKNOWN_VARIABLE] = :error
505
+ elsif Puppet[:strict] == :off
506
+ p[Issues::UNKNOWN_VARIABLE] = :ignore
507
+ else
508
+ Puppet[:strict_variables]
509
+ p[Issues::UNKNOWN_VARIABLE] = Puppet[:strict]
510
+ end
501
511
 
502
512
  # Store config issues, ignore or warning
503
513
  p[Issues::RT_NO_STORECONFIGS_EXPORT] = Puppet[:storeconfigs] ? :ignore : :warning
@@ -510,7 +520,7 @@ module Runtime3Support
510
520
  def accept(diagnostic)
511
521
  super
512
522
  IssueReporter.assert_and_report(self, {
513
- :message => "Evaluation Error:",
523
+ :message => "Evaluation Error:",
514
524
  :emit_warnings => true, # log warnings
515
525
  :exception_class => Puppet::PreformattedError
516
526
  })
@@ -49,7 +49,7 @@ class Puppet::Pops::Functions::Dispatcher
49
49
  add(Puppet::Pops::Functions::Dispatch.new(type, method_name, param_names, block_name, injections, weaving, last_captures))
50
50
  end
51
51
 
52
- # Adds a dispatch directly to the set of dispathers.
52
+ # Adds a dispatch directly to the set of dispatchers.
53
53
  # @api private
54
54
  def add(a_dispatch)
55
55
  @dispatchers << a_dispatch
@@ -228,6 +228,10 @@ module Issues
228
228
  "No value for required key '#{key}' in assignment to variables from hash"
229
229
  end
230
230
 
231
+ MISSING_MULTI_ASSIGNMENT_VARIABLE = hard_issue :MISSING_MULTI_ASSIGNMENT_VARIABLE, :name do
232
+ "No value for required variable '$#{name}' in assignment to variables from class reference"
233
+ end
234
+
231
235
  APPENDS_DELETES_NO_LONGER_SUPPORTED = hard_issue :APPENDS_DELETES_NO_LONGER_SUPPORTED, :operator do
232
236
  "The operator '#{operator}' is no longer supported. See http://links.puppetlabs.com/remove-plus-equals"
233
237
  end
@@ -280,6 +284,14 @@ module Issues
280
284
  "Illegal name. The given name '#{name}' does not conform to the naming rule /^((::)?[a-z_]\w*)(::[a-z]\\w*)*$/"
281
285
  end
282
286
 
287
+ ILLEGAL_SINGLE_TYPE_MAPPING = hard_issue :ILLEGAL_TYPE_MAPPING, :expression do
288
+ "Illegal type mapping. Expected a Type on the left side, got #{label.a_an_uc(semantic)}"
289
+ end
290
+
291
+ ILLEGAL_REGEXP_TYPE_MAPPING = hard_issue :ILLEGAL_TYPE_MAPPING, :expression do
292
+ "Illegal type mapping. Expected a Tuple[Regexp,String] on the left side, got #{label.a_an_uc(semantic)}"
293
+ end
294
+
283
295
  ILLEGAL_PARAM_NAME = hard_issue :ILLEGAL_PARAM_NAME, :name do
284
296
  "Illegal parameter name. The given name '#{name}' does not conform to the naming rule /^[a-z_]\\w*$/"
285
297
  end
@@ -494,7 +506,7 @@ module Issues
494
506
  end
495
507
 
496
508
  UNKNOWN_RESOURCE_TYPE = issue :UNKNOWN_RESOURCE_TYPE, :type_name do
497
- "Resource type not found: #{type_name.capitalize}"
509
+ "Resource type not found: #{type_name}"
498
510
  end
499
511
 
500
512
  ILLEGAL_RESOURCE_TYPE = hard_issue :ILLEGAL_RESOURCE_TYPE, :actual do
@@ -526,7 +538,7 @@ module Issues
526
538
  end
527
539
 
528
540
  UNKNOWN_RESOURCE = issue :UNKNOWN_RESOURCE, :type_name, :title do
529
- "Resource not found: #{type_name.capitalize}['#{title}']"
541
+ "Resource not found: #{type_name}['#{title}']"
530
542
  end
531
543
 
532
544
  UNKNOWN_RESOURCE_PARAMETER = issue :UNKNOWN_RESOURCE_PARAMETER, :type_name, :title, :param_name do
@@ -594,6 +606,10 @@ module Issues
594
606
  "The parameter '#{param_name}' is declared more than once in the parameter list"
595
607
  end
596
608
 
609
+ DUPLICATE_KEY = issue :DUPLICATE_KEY, :key do
610
+ "The key '#{key}' is declared more than once"
611
+ end
612
+
597
613
  RESERVED_PARAMETER = hard_issue :RESERVED_PARAMETER, :container, :param_name do
598
614
  "The parameter $#{param_name} redefines a built in parameter in #{label.the(container)}"
599
615
  end
@@ -38,6 +38,18 @@ class Puppet::Pops::Loader::BaseLoader < Puppet::Pops::Loader::Loader
38
38
  end
39
39
  end
40
40
 
41
+ # @api public
42
+ #
43
+ def loaded_entry(typed_name, check_dependencies = false)
44
+ if @named_values.has_key?(typed_name)
45
+ @named_values[typed_name]
46
+ elsif parent
47
+ parent.loaded_entry(typed_name, check_dependencies)
48
+ else
49
+ nil
50
+ end
51
+ end
52
+
41
53
  # This method is final (subclasses should not override it)
42
54
  #
43
55
  # @api private
@@ -49,8 +61,24 @@ class Puppet::Pops::Loader::BaseLoader < Puppet::Pops::Loader::Loader
49
61
  # @api private
50
62
  #
51
63
  def set_entry(typed_name, value, origin = nil)
52
- if entry = @named_values[typed_name] then fail_redefine(entry); end
53
- @named_values[typed_name] = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, value, origin)
64
+
65
+ # It is never ok to redefine in the very same loader unless redefining a 'not found'
66
+ if entry = @named_values[typed_name]
67
+ fail_redefine(entry) unless entry.value.nil?
68
+ end
69
+
70
+ # Check if new entry shadows existing entry and fail
71
+ # (unless special loader allows shadowing)
72
+ if typed_name.type == :type && !allow_shadowing?
73
+ entry = loaded_entry(typed_name)
74
+ if entry
75
+ fail_redefine(entry) unless entry.value.nil? #|| entry.value == value
76
+ end
77
+ end
78
+
79
+ @last_result = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, value, origin)
80
+ @last_name = typed_name
81
+ @named_values[typed_name] = @last_result
54
82
  end
55
83
 
56
84
  # @api private
@@ -69,25 +97,35 @@ class Puppet::Pops::Loader::BaseLoader < Puppet::Pops::Loader::Loader
69
97
  @named_values[typed_name] = named_entry
70
98
  end
71
99
 
100
+ protected
101
+
102
+ def allow_shadowing?
103
+ false
104
+ end
105
+
72
106
  private
73
107
 
74
108
  def fail_redefine(entry)
75
- origin_info = entry.origin ? " Originally set at #{origin_label(entry.origin)}." : "unknown location"
76
- raise ArgumentError, "Attempt to redefine entity '#{entry.typed_name}' originally set at #{origin_info}"
109
+ origin_info = entry.origin ? "Originally set #{origin_label(entry.origin)}." : "Set at unknown location"
110
+ raise ArgumentError, "Attempt to redefine entity '#{entry.typed_name}'. #{origin_info}"
77
111
  end
78
112
 
79
113
  # TODO: Should not really be here?? - TODO: A Label provider ? semantics for the URI?
80
114
  #
81
115
  def origin_label(origin)
82
116
  if origin && origin.is_a?(URI)
83
- origin.to_s
117
+ format_uri(origin)
84
118
  elsif origin.respond_to?(:uri)
85
- origin.uri.to_s
119
+ format_uri(origin.uri)
86
120
  else
87
121
  origin
88
122
  end
89
123
  end
90
124
 
125
+ def format_uri(uri)
126
+ (uri.scheme == 'puppet' ? 'by ' : 'at ') + uri.to_s.sub(/^puppet:/,'')
127
+ end
128
+
91
129
  # loads in priority order:
92
130
  # 1. already loaded here
93
131
  # 2. load from parent
@@ -96,7 +134,10 @@ class Puppet::Pops::Loader::BaseLoader < Puppet::Pops::Loader::Loader
96
134
  #
97
135
  def internal_load(typed_name)
98
136
  # avoid calling get_entry, by looking it up
99
- @named_values[typed_name] || parent.load_typed(typed_name) || find(typed_name)
137
+ te = @named_values[typed_name]
138
+ te = parent.load_typed(typed_name) if te.nil? || te.value.nil?
139
+ te = find(typed_name) if te.nil? || te.value.nil?
140
+ te
100
141
  end
101
142
 
102
143
  end
@@ -48,13 +48,38 @@ class Puppet::Pops::Loader::DependencyLoader < Puppet::Pops::Loader::BaseLoader
48
48
  end
49
49
  end
50
50
 
51
- def to_s()
51
+ # @api public
52
+ #
53
+ def loaded_entry(typed_name, check_dependencies = false)
54
+ super || (check_dependencies ? loaded_entry_in_dependency(typed_name, check_dependencies) : nil)
55
+ end
56
+
57
+ def to_s
52
58
  "(DependencyLoader '#{@loader_name}' [" + @dependency_loaders.map {|loader| loader.to_s }.join(' ,') + "])"
53
59
  end
54
60
 
55
61
  private
56
62
 
57
- def index()
63
+ def loaded_entry_in_dependency(typed_name, check_dependencies)
64
+ if typed_name.qualified?
65
+ if l = index[typed_name.name_parts[0]]
66
+ l.loaded_entry(typed_name)
67
+ else
68
+ # no module entered as dependency with name matching first segment of wanted name
69
+ nil
70
+ end
71
+ else
72
+ # a non name-spaced name, have to search since it can be anywhere.
73
+ # (Note: superclass caches the result in this loader as it would have to repeat this search for every
74
+ # lookup otherwise).
75
+ @dependency_loaders.reduce(nil) do |previous, loader|
76
+ break previous if !previous.nil?
77
+ loader.loaded_entry(typed_name, check_dependencies)
78
+ end
79
+ end
80
+ end
81
+
82
+ def index
58
83
  @index ||= @dependency_loaders.reduce({}) { |index, loader| index[loader.module_name] = loader; index }
59
84
  end
60
85
  end
@@ -55,6 +55,18 @@ class Puppet::Pops::Loader::Loader
55
55
  raise NotImplementedError.new
56
56
  end
57
57
 
58
+ # Returns an already loaded entry if one exists, or nil. This does not trigger loading
59
+ # of the given type/name.
60
+ #
61
+ # @param typed_name [TypedName] - the type, name combination to lookup
62
+ # @param check_dependencies [Boolean] - if dependencies should be checked in additiona to here and parent
63
+ # @return [NamedEntry, nil] the entry containing the loaded value, or nil if not found
64
+ # @api public
65
+ #
66
+ def loaded_entry(typed_name, check_dependencies = false)
67
+ raise NotImplementedError.new(self.class)
68
+ end
69
+
58
70
  # Produces the value associated with the given name if defined **in this loader**, or nil if not defined.
59
71
  # This lookup does not trigger any loading, or search of the given name.
60
72
  # An implementor of this method may not search or look up in any other loader, and it may not
@@ -0,0 +1,29 @@
1
+ module Puppet::Pops::Loader
2
+
3
+ # A PredefinedLoader is a loader that is manually populated with loaded elements
4
+ # before being used. It never loads anything on its own.
5
+ # When searching for a type, it must exist or an error is raised
6
+ #
7
+ class PredefinedLoader < BaseLoader
8
+ def find(typed_name)
9
+ if typed_name.type == :type
10
+ raise Puppet::Pops::Loaders::LoaderError, "Cannot load undefined type '#{typed_name.name.capitalize}'"
11
+ else
12
+ nil
13
+ end
14
+ end
15
+
16
+ def to_s()
17
+ "(PredefinedLoader '#{loader_name}')"
18
+ end
19
+
20
+ # Allows shadowing since this loader is used internally for things like function local types
21
+ # And they should win as there is otherwise a risk that the local types clash with built in types
22
+ # that were added after the function was written, or by resource types loaded by the 3x auto loader.
23
+ #
24
+ def allow_shadowing?
25
+ true
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,57 @@
1
+ module Puppet::Pops
2
+ module Loader
3
+
4
+ # Runtime3TypeLoader
5
+ # ===
6
+ # Loads a resource type using the 3.x type loader
7
+ #
8
+ # @api private
9
+ class Runtime3TypeLoader < BaseLoader
10
+ def initialize(parent_loader, environment)
11
+ super(parent_loader, environment.name)
12
+ @environment = environment
13
+ end
14
+
15
+ def to_s()
16
+ "(Runtime3TypeLoader '#{loader_name()}')"
17
+ end
18
+
19
+ # Finds typed/named entity in this module
20
+ # @param typed_name [TypedName] the type/name to find
21
+ # @return [Loader::NamedEntry, nil found/created entry, or nil if not found
22
+ #
23
+ def find(typed_name)
24
+ return nil unless typed_name.type == :type
25
+
26
+ name = typed_name.name
27
+ value = @environment.known_resource_types.find_definition(name)
28
+ if value.nil?
29
+ # Look for Puppet::Type
30
+ value = Puppet::Type.type(name)
31
+ if value.nil?
32
+ # Cache the fact that it wasn't found
33
+ set_entry(typed_name, nil)
34
+ return nil
35
+ end
36
+ end
37
+
38
+ # Loaded types doesn't have the same life cycle as this loader, so we must start by
39
+ # checking if the type was created. If it was, an entry will already be stored in
40
+ # this loader. If not, then it was created before this loader was instantiated and
41
+ # we must therefore add it.
42
+ te = get_entry(typed_name)
43
+ te = set_entry(typed_name, Types::TypeFactory.resource(value.name.to_s)) if te.nil? || te.value.nil?
44
+ te
45
+ end
46
+
47
+ # Allows shadowing since this loader is populalted with all loaded resource types at time
48
+ # of loading. This loading will, for built in types override the aliases configured in the static
49
+ # loader.
50
+ #
51
+ def allow_shadowing?
52
+ true
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -1,12 +1,16 @@
1
1
  # Static Loader contains constants, basic data types and other types required for the system
2
2
  # to boot.
3
3
  #
4
- class Puppet::Pops::Loader::StaticLoader < Puppet::Pops::Loader::Loader
4
+ module Puppet::Pops
5
+ module Loader
6
+ class StaticLoader < Loader
5
7
 
6
8
  attr_reader :loaded
7
9
  def initialize
8
10
  @loaded = {}
9
11
  create_logging_functions()
12
+ create_built_in_types()
13
+ create_resource_type_references()
10
14
  end
11
15
 
12
16
  def load_typed(typed_name)
@@ -29,14 +33,17 @@ class Puppet::Pops::Loader::StaticLoader < Puppet::Pops::Loader::Loader
29
33
  def to_s()
30
34
  "(StaticLoader)"
31
35
  end
32
- private
33
36
 
34
- def load_constant(typed_name)
37
+ def loaded_entry(typed_name, _)
35
38
  @loaded[typed_name]
36
39
  end
37
40
 
38
41
  private
39
42
 
43
+ def load_constant(typed_name)
44
+ @loaded[typed_name]
45
+ end
46
+
40
47
  # Creates a function for each of the specified log levels
41
48
  #
42
49
  def create_logging_functions()
@@ -70,10 +77,90 @@ class Puppet::Pops::Loader::StaticLoader < Puppet::Pops::Loader::Loader
70
77
  end
71
78
  end
72
79
 
73
- typed_name = Puppet::Pops::Loader::Loader::TypedName.new(:function, level)
80
+ typed_name = TypedName.new(:function, level)
74
81
  # TODO:closure scope is fake (an empty hash) - waiting for new global scope to be available via lookup of :scopes
75
82
  func = fc.new({},self)
76
- @loaded[ typed_name ] = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, func, __FILE__)
83
+ @loaded[ typed_name ] = NamedEntry.new(typed_name, func, __FILE__)
84
+ end
85
+ end
86
+
87
+ def create_built_in_types
88
+ origin_uri = URI("puppet:Puppet-Type-System/Static-Loader")
89
+ type_map = Puppet::Pops::Types::TypeParser.type_map
90
+ type_map.each do |name, type|
91
+ typed_name = TypedName.new(:type, name)
92
+ @loaded[ typed_name ] = NamedEntry.new(typed_name, type, origin_uri)#__FILE__)
77
93
  end
78
94
  end
95
+
96
+ def create_resource_type_references()
97
+ # These needs to be done quickly and we do not want to scan the file system for these
98
+ # We are also not interested in their definition only that they exist.
99
+ # These types are in all environments.
100
+ #
101
+ %w{
102
+ Auegas
103
+ Component
104
+ Computer
105
+ Cron
106
+ Exec
107
+ File
108
+ Filebucket
109
+ Group
110
+ Host
111
+ Interface
112
+ K5login
113
+ Macauthorization
114
+ Mailalias
115
+ Maillist
116
+ Mcx
117
+ Mount
118
+ Nagios_command
119
+ Nagios_contact
120
+ Nagios_contactgroup
121
+ Nagios_host
122
+ Nagios_hostdependency
123
+ Nagios_hostescalation
124
+ Nagios_hostgroup
125
+ Nagios_hostextinfo
126
+ Nagios_service
127
+ Nagios_servicedependency
128
+ Nagios_serviceescalation
129
+ Nagios_serviceextinfo
130
+ Nagios_servicegroup
131
+ Nagios_timeperiod
132
+ Notify
133
+ Package
134
+ Resources
135
+ Router
136
+ Schedule
137
+ Scheduled_task
138
+ Selboolean
139
+ Selmodule
140
+ Service
141
+ Ssh_authorized_key
142
+ Sshkey
143
+ Stage
144
+ Tidy
145
+ User
146
+ Vlan
147
+ Whit
148
+ Yumrepo
149
+ Zfs
150
+ Zone
151
+ Zpool
152
+ }.each { |name| create_resource_type_reference(name) }
153
+
154
+ if Puppet[:app_management]
155
+ create_resource_type_reference('Node')
156
+ end
157
+ end
158
+
159
+ def create_resource_type_reference(name)
160
+ typed_name = TypedName.new(:type, name.downcase)
161
+ type = Puppet::Pops::Types::TypeFactory.resource(name)
162
+ @loaded[ typed_name ] = NamedEntry.new(typed_name, type, __FILE__)
163
+ end
164
+ end
165
+ end
79
166
  end