puppet 4.4.2-x86-mingw32 → 4.5.0-x86-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
@@ -44,6 +44,10 @@ describe 'the regsubst function' do
44
44
  it 'should handle case insensitive flag' do
45
45
  expect(regsubst('the monkey breaks baNAna trees', 'b[an]+a', 'coconut', 'I')).to eql('the monkey breaks coconut trees')
46
46
  end
47
+
48
+ it 'should allow hash as replacement' do
49
+ expect(regsubst('tuto', '[uo]', { 'u' => 'o', 'o' => 'u' }, 'G')).to eql('totu')
50
+ end
47
51
  end
48
52
 
49
53
  context 'when using a regexp pattern' do
@@ -70,6 +74,10 @@ describe 'the regsubst function' do
70
74
  it 'should treat Regexp as Regexp[//]' do
71
75
  expect(regsubst('abc', type_parser.parse("Regexp"), '_', 'G')).to eql('_a_b_c_')
72
76
  end
77
+
78
+ it 'should allow hash as replacement' do
79
+ expect(regsubst('tuto', /[uo]/, { 'u' => 'o', 'o' => 'u' }, 'G')).to eql('totu')
80
+ end
73
81
  end
74
82
 
75
83
  context 'when using an array target' do
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ require 'puppet_spec/compiler'
4
+ require 'matchers/resource'
5
+
6
+ describe 'the then function' do
7
+ include PuppetSpec::Compiler
8
+ include Matchers::Resource
9
+
10
+ it 'calls a lambda passing one argument' do
11
+ expect(compile_to_catalog("then(testing) |$x| { notify { $x: } }")).to have_resource('Notify[testing]')
12
+ end
13
+
14
+ it 'produces what lambda returns if value is not undef' do
15
+ expect(compile_to_catalog("notify{ then(1) |$x| { testing }: }")).to have_resource('Notify[testing]')
16
+ end
17
+
18
+ it 'does not call lambda if argument is undef' do
19
+ expect(compile_to_catalog('then(undef) |$x| { notify { "failed": } }')).to_not have_resource('Notify[failed]')
20
+ end
21
+
22
+ it 'produces undef if given value is undef' do
23
+ expect(compile_to_catalog(<<-SOURCE)).to have_resource('Notify[test-Undef-ing]')
24
+ notify{ "test-${type(then(undef) |$x| { testing })}-ing": }
25
+ SOURCE
26
+ end
27
+
28
+ it 'errors when lambda wants too many args' do
29
+ expect do
30
+ compile_to_catalog('then(1) |$x, $y| { }')
31
+ end.to raise_error(/'then' block expects 1 argument, got 2/m)
32
+ end
33
+
34
+ it 'errors when lambda wants too few args' do
35
+ expect do
36
+ compile_to_catalog('then(1) || { }')
37
+ end.to raise_error(/'then' block expects 1 argument, got none/m)
38
+ end
39
+
40
+ end
@@ -14,15 +14,15 @@ module FunctionAPISpecModule
14
14
  end
15
15
 
16
16
  def add_function(name, function)
17
- typed_name = Puppet::Pops::Loader::Loader::TypedName.new(:function, name)
18
- entry = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, function, __FILE__)
19
- @constants[typed_name] = entry
17
+ set_entry(Puppet::Pops::Loader::Loader::TypedName.new(:function, name), function, __FILE__)
20
18
  end
21
19
 
22
20
  def add_type(name, type)
23
- typed_name = Puppet::Pops::Loader::Loader::TypedName.new(:type, name)
24
- entry = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, type, __FILE__)
25
- @constants[typed_name] = entry
21
+ set_entry(Puppet::Pops::Loader::Loader::TypedName.new(:type, name), type, __FILE__)
22
+ end
23
+
24
+ def set_entry(typed_name, value, origin = nil)
25
+ @constants[typed_name] = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, value, origin)
26
26
  end
27
27
 
28
28
  # override StaticLoader
@@ -472,10 +472,10 @@ describe 'the 4x function api' do
472
472
  end
473
473
  end
474
474
 
475
- context 'can use a loader when parsing types in function dispatch' do
475
+ context 'can use a loader when parsing types in function dispatch, and' do
476
476
  let(:parser) { Puppet::Pops::Parser::EvaluatingParser.new }
477
477
 
478
- it 'and resolve a referenced Type alias' do
478
+ it 'resolve a referenced Type alias' do
479
479
  the_loader = loader()
480
480
  the_loader.add_type('myalias', type_alias_t('MyAlias', 'Integer'))
481
481
  here = get_binding(the_loader)
@@ -495,7 +495,7 @@ describe 'the 4x function api' do
495
495
  expect(parser.evaluate({}, program)).to eql(10)
496
496
  end
497
497
 
498
- it 'and distinguish between a Type alias and a Resource type' do
498
+ it 'reports a reference to an unresolved type' do
499
499
  the_loader = loader()
500
500
  here = get_binding(the_loader)
501
501
  fc = eval(<<-CODE, here)
@@ -511,11 +511,79 @@ describe 'the 4x function api' do
511
511
  the_loader.add_function('testing::test', fc.new({}, the_loader))
512
512
  program = parser.parse_string('testing::test(10)', __FILE__)
513
513
  Puppet::Pops::Adapters::LoaderAdapter.adapt(program.model).loader = the_loader
514
- expect { parser.evaluate({}, program) }.to raise_error(Puppet::Error, /parameter 'x' expects a Resource value, got Integer/)
514
+ expect { parser.evaluate({}, program) }.to raise_error(Puppet::Error, /parameter 'x' references an unresolved type 'MyAlias'/)
515
+ end
516
+
517
+ it 'create local Type aliases' do
518
+ the_loader = loader()
519
+ here = get_binding(the_loader)
520
+ fc = eval(<<-CODE, here)
521
+ Puppet::Functions.create_function('testing::test') do
522
+ local_types do
523
+ type 'MyType = Array[Integer]'
524
+ end
525
+ dispatch :test do
526
+ param 'MyType', :x
527
+ end
528
+ def test(x)
529
+ x
530
+ end
531
+ end
532
+ CODE
533
+ the_loader.add_function('testing::test', fc.new({}, the_loader))
534
+ program = parser.parse_string('testing::test([10,20])', __FILE__)
535
+ Puppet::Pops::Adapters::LoaderAdapter.adapt(program.model).loader = the_loader
536
+ expect(parser.evaluate({}, program)).to eq([10,20])
537
+ end
538
+
539
+ it 'create nested local Type aliases' do
540
+ the_loader = loader()
541
+ here = get_binding(the_loader)
542
+ fc = eval(<<-CODE, here)
543
+ Puppet::Functions.create_function('testing::test') do
544
+ local_types do
545
+ type 'InnerType = Array[Integer]'
546
+ type 'OuterType = Hash[String,InnerType]'
547
+ end
548
+ dispatch :test do
549
+ param 'OuterType', :x
550
+ end
551
+ def test(x)
552
+ x
553
+ end
554
+ end
555
+ CODE
556
+ the_loader.add_function('testing::test', fc.new({}, the_loader))
557
+ program = parser.parse_string("testing::test({'x' => [10,20]})", __FILE__)
558
+ Puppet::Pops::Adapters::LoaderAdapter.adapt(program.model).loader = the_loader
559
+ expect(parser.evaluate({}, program)).to eq({'x' => [10,20]})
560
+ end
561
+
562
+ it 'create self referencing local Type aliases' do
563
+ the_loader = loader()
564
+ here = get_binding(the_loader)
565
+ fc = eval(<<-CODE, here)
566
+ Puppet::Functions.create_function('testing::test') do
567
+ local_types do
568
+ type 'Tree = Hash[String,Variant[String,Tree]]'
569
+ end
570
+ dispatch :test do
571
+ param 'Tree', :x
572
+ end
573
+ def test(x)
574
+ x
575
+ end
576
+ end
577
+ CODE
578
+ the_loader.add_function('testing::test', fc.new({}, the_loader))
579
+ program = parser.parse_string("testing::test({'x' => {'y' => 'n'}})", __FILE__)
580
+ Puppet::Pops::Adapters::LoaderAdapter.adapt(program.model).loader = the_loader
581
+ expect(parser.evaluate({}, program)).to eq({'x' => {'y' => 'n'}})
515
582
  end
516
583
  end
517
584
  end
518
585
 
586
+
519
587
  def create_noargs_function_class
520
588
  f = Puppet::Functions.create_function('test') do
521
589
  def test()
@@ -63,17 +63,58 @@ describe 'HieraPuppet' do
63
63
  expect(HieraPuppet.send(:hiera_config_file)).to eq(Puppet[:hiera_config])
64
64
  end
65
65
 
66
- it "should use Puppet.settings[:codedir] as the base directory when hiera_config is not set" do
67
- begin
66
+ context 'when hiera_config is not set' do
67
+ let(:code_hiera_config) { File.join(Puppet[:codedir], 'hiera.yaml') }
68
+ let(:conf_hiera_config) { File.join(Puppet[:confdir], 'hiera.yaml') }
69
+
70
+ before(:each) do
71
+ Puppet.settings.setting(:hiera_config).send(:remove_instance_variable, :@evaluated_default)
68
72
  Puppet.settings[:hiera_config] = nil
69
- rescue ArgumentError => detail
70
- raise unless detail.message =~ /unknown setting/
73
+ Puppet.settings[:codedir] = '/dev/null/puppetlabs/code'
74
+ Puppet.settings[:confdir] = '/dev/null/puppetlabs/puppet'
71
75
  end
72
- Puppet.settings[:codedir] = "/dev/null/puppet"
73
- hiera_config = File.join(Puppet[:codedir], 'hiera.yaml')
74
- Puppet::FileSystem.stubs(:exist?).with(hiera_config).returns(true)
75
76
 
76
- expect(HieraPuppet.send(:hiera_config_file)).to eq(hiera_config)
77
+ it "should use Puppet.settings[:codedir]/hiera.yaml when '$codedir/hiera.yaml' exists and '$confdir/hiera.yaml' does not exist" do
78
+ Puppet::FileSystem.stubs(:exist?).with(code_hiera_config).returns(true)
79
+ Puppet::FileSystem.stubs(:exist?).with(conf_hiera_config).returns(false)
80
+
81
+ expect(HieraPuppet.send(:hiera_config_file)).to eq(code_hiera_config)
82
+ end
83
+
84
+ it "should use Puppet.settings[:confdir]/hiera.yaml when '$codedir/hiera.yaml' does not exist and '$confdir/hiera.yaml' exists" do
85
+ Puppet::FileSystem.stubs(:exist?).with(code_hiera_config).returns(false)
86
+ Puppet::FileSystem.stubs(:exist?).with(conf_hiera_config).returns(true)
87
+
88
+ expect(HieraPuppet.send(:hiera_config_file)).to eq(conf_hiera_config)
89
+ end
90
+
91
+ it "should use Puppet.settings[:codedir]/hiera.yaml when '$codedir/hiera.yaml' exists and '$confdir/hiera.yaml' exists" do
92
+ Puppet::FileSystem.stubs(:exist?).with(code_hiera_config).returns(true)
93
+ Puppet::FileSystem.stubs(:exist?).with(conf_hiera_config).returns(true)
94
+
95
+ expect(HieraPuppet.send(:hiera_config_file)).to eq(code_hiera_config)
96
+ end
97
+
98
+ it "should return nil when neither '$codedir/hiera.yaml' nor '$confdir/hiera.yaml' exists" do
99
+ Puppet::FileSystem.stubs(:exist?).with(code_hiera_config).returns(false)
100
+ Puppet::FileSystem.stubs(:exist?).with(conf_hiera_config).returns(false)
101
+
102
+ expect(HieraPuppet.send(:hiera_config_file)).to eq(nil)
103
+ end
104
+
105
+ it "should return explicitly set option even if both '$codedir/hiera.yaml' and '$confdir/hiera.yaml' exists" do
106
+ if Puppet::Util::Platform.windows?
107
+ explicit_hiera_config = 'C:/an/explicit/hiera.yaml'
108
+ else
109
+ explicit_hiera_config = '/an/explicit/hiera.yaml'
110
+ end
111
+ Puppet.settings[:hiera_config] = explicit_hiera_config
112
+ Puppet::FileSystem.stubs(:exist?).with(explicit_hiera_config).returns(true)
113
+ Puppet::FileSystem.stubs(:exist?).with(code_hiera_config).returns(true)
114
+ Puppet::FileSystem.stubs(:exist?).with(conf_hiera_config).returns(true)
115
+
116
+ expect(HieraPuppet.send(:hiera_config_file)).to eq(explicit_hiera_config)
117
+ end
77
118
  end
78
119
  end
79
120
 
@@ -21,6 +21,11 @@ describe Puppet::Indirector::ResourceType::Parser do
21
21
  expect(Puppet::Indirector::Terminus.terminus_class(:resource_type, :parser)).to equal(Puppet::Indirector::ResourceType::Parser)
22
22
  end
23
23
 
24
+ it "is deprecated on the network, but still allows requests" do
25
+ Puppet.expects(:deprecation_warning)
26
+ expect(Puppet::Indirector::ResourceType::Parser.new.allow_remote_requests?).to eq(true)
27
+ end
28
+
24
29
  describe "when finding" do
25
30
  it "should return any found type from the request's environment" do
26
31
  type = Puppet::Resource::Type.new(:hostclass, "foo")
@@ -190,6 +190,18 @@ describe Puppet::Indirector::REST do
190
190
  expect(Puppet::Indirector::REST.srv_service).to eq(:puppet)
191
191
  end
192
192
 
193
+ it 'excludes yaml from the Accept header' do
194
+ model.expects(:supported_formats).returns([:pson, :yaml, :binary])
195
+
196
+ expect(terminus.headers['Accept']).to eq('pson, binary')
197
+ end
198
+
199
+ it 'excludes b64_zlib_yaml from the Accept header' do
200
+ model.expects(:supported_formats).returns([:pson, :b64_zlib_yaml])
201
+
202
+ expect(terminus.headers['Accept']).to eq('pson')
203
+ end
204
+
193
205
  describe "when creating an HTTP client" do
194
206
  it "should use the class's server and port if the indirection request provides neither" do
195
207
  @request = stub 'request', :key => "foo", :server => nil, :port => nil
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ require 'puppet/network/http'
4
+
5
+ describe Puppet::Network::HTTP::API::Master::V3::Environment do
6
+ let(:response) { Puppet::Network::HTTP::MemoryResponse.new }
7
+
8
+ around :each do |example|
9
+ environment = Puppet::Node::Environment.create(:production, [], '/manifests')
10
+ loader = Puppet::Environments::Static.new(environment)
11
+ Puppet.override(:environments => loader) do
12
+ example.run
13
+ end
14
+ end
15
+
16
+ it "returns the environment catalog" do
17
+ request = Puppet::Network::HTTP::Request.from_hash(:headers => { 'accept' => 'application/json' }, :routing_path => "environment/production")
18
+
19
+ subject.call(request, response)
20
+
21
+ expect(response.code).to eq(200)
22
+
23
+ catalog = JSON.parse(response.body)
24
+ expect(catalog['environment']).to eq('production')
25
+ expect(catalog['applications']).to eq({})
26
+ end
27
+
28
+ it "returns 404 if the environment doesn't exist" do
29
+ request = Puppet::Network::HTTP::Request.from_hash(:routing_path => "environment/development")
30
+
31
+ expect { subject.call(request, response) }.to raise_error(Puppet::Network::HTTP::Error::HTTPNotFoundError, /development is not a known environment/)
32
+ end
33
+
34
+ it "omits code_id if unspecified" do
35
+ request = Puppet::Network::HTTP::Request.from_hash(:routing_path => "environment/production")
36
+
37
+ subject.call(request, response)
38
+
39
+ expect(JSON.parse(response.body)['code_id']).to be_nil
40
+ end
41
+
42
+ it "includes code_id if specified" do
43
+ request = Puppet::Network::HTTP::Request.from_hash(:params => {:code_id => '12345'}, :routing_path => "environment/production")
44
+
45
+ subject.call(request, response)
46
+
47
+ expect(JSON.parse(response.body)['code_id']).to eq('12345')
48
+ end
49
+
50
+ it "uses code_id from the catalog if it differs from the request" do
51
+ request = Puppet::Network::HTTP::Request.from_hash(:params => {:code_id => '12345'}, :routing_path => "environment/production")
52
+
53
+ Puppet::Resource::Catalog.any_instance.stubs(:code_id).returns('67890')
54
+
55
+ subject.call(request, response)
56
+
57
+ expect(JSON.parse(response.body)['code_id']).to eq('67890')
58
+ end
59
+ end
60
+
@@ -428,6 +428,16 @@ describe Puppet::Node::Environment do
428
428
  end
429
429
 
430
430
  describe "when performing initial import" do
431
+ let(:loaders) { Puppet::Pops::Loaders.new(env) }
432
+
433
+ around :each do |example|
434
+ Puppet::Parser::Compiler.any_instance.stubs(:loaders).returns(loaders)
435
+ Puppet.override(:loaders => loaders, :current_environment => env) do
436
+ example.run
437
+ Puppet::Pops::Loaders.clear
438
+ end
439
+ end
440
+
431
441
  it "loads from Puppet[:code]" do
432
442
  Puppet[:code] = "define foo {}"
433
443
  krt = env.known_resource_types
@@ -258,7 +258,7 @@ describe Puppet::Parser::Compiler do
258
258
  expect(@compiler.topscope['c']).to eq("d")
259
259
  end
260
260
 
261
- it "should set node parameters thar are of Symbol type as String variables in the top scope" do
261
+ it "should set node parameters that are of Symbol type as String variables in the top scope" do
262
262
  params = {"a" => :b}
263
263
  @node.stubs(:parameters).returns(params)
264
264
  compile_stub(:set_node_parameters)
@@ -838,6 +838,24 @@ describe Puppet::Parser::Compiler do
838
838
  end
839
839
  end
840
840
 
841
+ describe 'when using meta parameters to form relationships' do
842
+ include PuppetSpec::Compiler
843
+ [:before, :subscribe, :notify, :require].each do | meta_p |
844
+ it "an entry consisting of nested empty arrays is flattened for parameter #{meta_p}" do
845
+ expect {
846
+ node = Puppet::Node.new('someone')
847
+ manifest = <<-"MANIFEST"
848
+ notify{hello_kitty: message => meow, #{meta_p} => [[],[]]}
849
+ notify{hello_kitty2: message => meow, #{meta_p} => [[],[[]],[]]}
850
+ MANIFEST
851
+
852
+ catalog = compile_to_catalog(manifest, node)
853
+ catalog.to_ral
854
+ }.not_to raise_error
855
+ end
856
+ end
857
+ end
858
+
841
859
  describe "when evaluating node classes" do
842
860
  include PuppetSpec::Compiler
843
861
 
@@ -951,6 +969,7 @@ describe Puppet::Parser::Compiler do
951
969
  end
952
970
  end
953
971
 
972
+
954
973
  describe "when managing resource overrides" do
955
974
 
956
975
  before do
@@ -103,7 +103,7 @@ describe 'function for dynamically creating resources' do
103
103
 
104
104
  create_resources('foocreateresource', {'blah'=>{}})
105
105
  MANIFEST
106
- }.to raise_error(Puppet::Error, /Foocreateresource\[blah\]: expects a value for parameter 'one' on node foonode/)
106
+ }.to raise_error(Puppet::Error, /Foocreateresource\[blah\]: expects a value for parameter 'one' on node test/)
107
107
  end
108
108
 
109
109
  it 'should be able to add multiple defines' do
@@ -169,7 +169,7 @@ describe 'function for dynamically creating resources' do
169
169
  compile_to_catalog(<<-MANIFEST)
170
170
  create_resources('class', {'blah'=>{'one'=>'two'}})
171
171
  MANIFEST
172
- end.to raise_error(/Could not find declared class blah at line 1:11 on node foonode/)
172
+ end.to raise_error(/Could not find declared class blah at line 1:11 on node test/)
173
173
  end
174
174
 
175
175
  it 'should be able to add edges' do
@@ -24,7 +24,7 @@ shared_examples_for 'all functions transforming relative to absolute names' do |
24
24
  it 'raises and error for Resource that is not of class type' do
25
25
  expect {
26
26
  @scope.send(func_method, [Puppet::Pops::Types::TypeFactory.resource('file')])
27
- }.to raise_error(ArgumentError, /Cannot use a Resource\[file\] where a Resource\['class', name\] is expected/)
27
+ }.to raise_error(ArgumentError, /Cannot use a Resource\[File\] where a Resource\['class', name\] is expected/)
28
28
  end
29
29
 
30
30
  it 'raises and error for Resource that is unspecific' do
@@ -193,6 +193,13 @@ describe Puppet::Parser::Resource do
193
193
  expect(@compiler.catalog).to be_edge(foo_stage, resource)
194
194
  end
195
195
 
196
+ it 'should allow a resource reference to be undef' do
197
+ Puppet[:code] = "notify { 'hello': message=>'yo', notify => undef }"
198
+ catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new 'anyone')
199
+ edges = catalog.edges.map {|e| [e.source.ref, e.target.ref]}
200
+ expect(edges).to include(['Class[main]', 'Notify[hello]'])
201
+ end
202
+
196
203
  it "should allow edges to propagate multiple levels down the scope hierarchy" do
197
204
  Puppet[:code] = <<-MANIFEST
198
205
  stage { before: before => Stage[main] }
@@ -556,7 +563,7 @@ describe Puppet::Parser::Resource do
556
563
 
557
564
  # part of #629 -- the undef keyword. Make sure 'undef' params get skipped.
558
565
  it "should not include 'undef' parameters when converting itself to a hash" do
559
- resource = Puppet::Parser::Resource.new "file", "/tmp/testing", :source => mock("source"), :scope => mock("scope")
566
+ resource = Puppet::Parser::Resource.new "file", "/tmp/testing", :source => mock("source"), :scope => @scope
560
567
  resource[:owner] = :undef
561
568
  resource[:mode] = "755"
562
569
  expect(resource.to_hash[:owner]).to be_nil