puppet 4.9.3-x86-mingw32 → 4.9.4-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.
- data/lib/puppet/functions/eyaml_lookup_key.rb +18 -10
- data/lib/puppet/functions/hocon_data.rb +6 -4
- data/lib/puppet/functions/json_data.rb +7 -5
- data/lib/puppet/functions/yaml_data.rb +14 -11
- data/lib/puppet/pops/functions/dispatcher.rb +8 -9
- data/lib/puppet/pops/lookup.rb +3 -1
- data/lib/puppet/pops/lookup/configured_data_provider.rb +1 -1
- data/lib/puppet/pops/lookup/context.rb +75 -11
- data/lib/puppet/pops/lookup/data_hash_function_provider.rb +1 -1
- data/lib/puppet/pops/lookup/data_provider.rb +9 -18
- data/lib/puppet/pops/lookup/function_provider.rb +5 -2
- data/lib/puppet/pops/lookup/global_data_provider.rb +12 -7
- data/lib/puppet/pops/lookup/hiera_config.rb +51 -23
- data/lib/puppet/pops/lookup/invocation.rb +14 -0
- data/lib/puppet/pops/lookup/lookup_key_function_provider.rb +3 -2
- data/lib/puppet/pops/types/types.rb +68 -21
- data/lib/puppet/version.rb +1 -1
- data/spec/unit/functions/hiera_spec.rb +88 -19
- data/spec/unit/functions/lookup_spec.rb +126 -68
- data/spec/unit/pops/lookup/context_spec.rb +126 -18
- data/spec/unit/pops/lookup/lookup_spec.rb +34 -0
- metadata +2 -2
@@ -1,5 +1,6 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
require 'spec_helper'
|
3
|
+
require 'puppet_spec/files'
|
3
4
|
require 'puppet_spec/compiler'
|
4
5
|
|
5
6
|
module Puppet::Pops
|
@@ -9,28 +10,28 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
9
10
|
context 'an instance' do
|
10
11
|
include PuppetSpec::Compiler
|
11
12
|
it 'can be created' do
|
12
|
-
code = "notice(type(Puppet::LookupContext.new('
|
13
|
+
code = "notice(type(Puppet::LookupContext.new('m')))"
|
13
14
|
expect(eval_and_collect_notices(code)[0]).to match(/Object\[\{name => 'Puppet::LookupContext'/)
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'returns its environment_name' do
|
17
|
-
code = "notice(Puppet::LookupContext.new('
|
18
|
-
expect(eval_and_collect_notices(code)[0]).to eql('
|
18
|
+
code = "notice(Puppet::LookupContext.new('m').environment_name)"
|
19
|
+
expect(eval_and_collect_notices(code)[0]).to eql('production')
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'returns its module_name' do
|
22
|
-
code = "notice(Puppet::LookupContext.new('
|
23
|
+
code = "notice(Puppet::LookupContext.new('m').module_name)"
|
23
24
|
expect(eval_and_collect_notices(code)[0]).to eql('m')
|
24
25
|
end
|
25
26
|
|
26
27
|
it 'can use an undef module_name' do
|
27
|
-
code = "notice(type(Puppet::LookupContext.new(
|
28
|
+
code = "notice(type(Puppet::LookupContext.new(undef).module_name))"
|
28
29
|
expect(eval_and_collect_notices(code)[0]).to eql('Undef')
|
29
30
|
end
|
30
31
|
|
31
32
|
it 'can store and retrieve a value using the cache' do
|
32
33
|
code = <<-PUPPET.unindent
|
33
|
-
$ctx = Puppet::LookupContext.new('
|
34
|
+
$ctx = Puppet::LookupContext.new('m')
|
34
35
|
$ctx.cache('ze_key', 'ze_value')
|
35
36
|
notice($ctx.cached_value('ze_key'))
|
36
37
|
PUPPET
|
@@ -39,7 +40,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
39
40
|
|
40
41
|
it 'the cache method returns the value that is cached' do
|
41
42
|
code = <<-PUPPET.unindent
|
42
|
-
$ctx = Puppet::LookupContext.new('
|
43
|
+
$ctx = Puppet::LookupContext.new('m')
|
43
44
|
notice($ctx.cache('ze_key', 'ze_value'))
|
44
45
|
PUPPET
|
45
46
|
expect(eval_and_collect_notices(code)[0]).to eql('ze_value')
|
@@ -47,7 +48,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
47
48
|
|
48
49
|
it 'can store and retrieve a hash using the cache' do
|
49
50
|
code = <<-PUPPET.unindent
|
50
|
-
$ctx = Puppet::LookupContext.new('
|
51
|
+
$ctx = Puppet::LookupContext.new('m')
|
51
52
|
$ctx.cache_all({ 'v1' => 'first', 'v2' => 'second' })
|
52
53
|
$ctx.cached_entries |$key, $value| { notice($key); notice($value) }
|
53
54
|
PUPPET
|
@@ -56,7 +57,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
56
57
|
|
57
58
|
it 'can use the cache to merge hashes' do
|
58
59
|
code = <<-PUPPET.unindent
|
59
|
-
$ctx = Puppet::LookupContext.new('
|
60
|
+
$ctx = Puppet::LookupContext.new('m')
|
60
61
|
$ctx.cache_all({ 'v1' => 'first', 'v2' => 'second' })
|
61
62
|
$ctx.cache_all({ 'v3' => 'third', 'v4' => 'fourth' })
|
62
63
|
$ctx.cached_entries |$key, $value| { notice($key); notice($value) }
|
@@ -66,7 +67,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
66
67
|
|
67
68
|
it 'can use the cache to merge hashes and individual entries' do
|
68
69
|
code = <<-PUPPET.unindent
|
69
|
-
$ctx = Puppet::LookupContext.new('
|
70
|
+
$ctx = Puppet::LookupContext.new('m')
|
70
71
|
$ctx.cache_all({ 'v1' => 'first', 'v2' => 'second' })
|
71
72
|
$ctx.cache('v3', 'third')
|
72
73
|
$ctx.cached_entries |$key, $value| { notice($key); notice($value) }
|
@@ -76,7 +77,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
76
77
|
|
77
78
|
it 'can iterate the cache using one argument block' do
|
78
79
|
code = <<-PUPPET.unindent
|
79
|
-
$ctx = Puppet::LookupContext.new('
|
80
|
+
$ctx = Puppet::LookupContext.new('m')
|
80
81
|
$ctx.cache_all({ 'v1' => 'first', 'v2' => 'second' })
|
81
82
|
$ctx.cached_entries |$entry| { notice($entry[0]); notice($entry[1]) }
|
82
83
|
PUPPET
|
@@ -85,7 +86,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
85
86
|
|
86
87
|
it 'can replace individual cached entries' do
|
87
88
|
code = <<-PUPPET.unindent
|
88
|
-
$ctx = Puppet::LookupContext.new('
|
89
|
+
$ctx = Puppet::LookupContext.new('m')
|
89
90
|
$ctx.cache_all({ 'v1' => 'first', 'v2' => 'second' })
|
90
91
|
$ctx.cache('v2', 'changed')
|
91
92
|
$ctx.cached_entries |$key, $value| { notice($key); notice($value) }
|
@@ -95,7 +96,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
95
96
|
|
96
97
|
it 'can replace multiple cached entries' do
|
97
98
|
code = <<-PUPPET.unindent
|
98
|
-
$ctx = Puppet::LookupContext.new('
|
99
|
+
$ctx = Puppet::LookupContext.new('m')
|
99
100
|
$ctx.cache_all({ 'v1' => 'first', 'v2' => 'second', 'v3' => 'third' })
|
100
101
|
$ctx.cache_all({ 'v1' => 'one', 'v3' => 'three' })
|
101
102
|
$ctx.cached_entries |$key, $value| { notice($key); notice($value) }
|
@@ -105,7 +106,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
105
106
|
|
106
107
|
it 'cached_entries returns an Iterable when called without a block' do
|
107
108
|
code = <<-PUPPET.unindent
|
108
|
-
$ctx = Puppet::LookupContext.new('
|
109
|
+
$ctx = Puppet::LookupContext.new('m')
|
109
110
|
$ctx.cache_all({ 'v1' => 'first', 'v2' => 'second' })
|
110
111
|
$iter = $ctx.cached_entries
|
111
112
|
notice(type($iter, generalized))
|
@@ -116,12 +117,119 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
116
117
|
|
117
118
|
it 'will throw :no_such_key when not_found is called' do
|
118
119
|
code = <<-PUPPET.unindent
|
119
|
-
$ctx = Puppet::LookupContext.new('
|
120
|
+
$ctx = Puppet::LookupContext.new('m')
|
120
121
|
$ctx.not_found
|
121
122
|
PUPPET
|
122
123
|
expect { eval_and_collect_notices(code) }.to throw_symbol(:no_such_key)
|
123
124
|
end
|
124
125
|
|
126
|
+
context 'with cached_file_data' do
|
127
|
+
include PuppetSpec::Files
|
128
|
+
|
129
|
+
let(:code_dir) { Puppet[:environmentpath] }
|
130
|
+
let(:env_name) { 'testing' }
|
131
|
+
let(:env_dir) { File.join(code_dir, env_name) }
|
132
|
+
let(:env) { Puppet::Node::Environment.create(env_name.to_sym, [File.join(populated_env_dir, 'modules')]) }
|
133
|
+
let(:node) { Puppet::Node.new('test', :environment => env) }
|
134
|
+
let(:data_yaml) { 'data.yaml' }
|
135
|
+
let(:data_path) { File.join(populated_env_dir, 'data', data_yaml) }
|
136
|
+
let(:populated_env_dir) do
|
137
|
+
dir_contained_in(code_dir,
|
138
|
+
{
|
139
|
+
env_name => {
|
140
|
+
'data' => {
|
141
|
+
data_yaml => <<-YAML.unindent
|
142
|
+
a: value a
|
143
|
+
YAML
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}
|
147
|
+
)
|
148
|
+
PuppetSpec::Files.record_tmp(File.join(env_dir))
|
149
|
+
env_dir
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'can use cached_file_data without a block' do
|
153
|
+
code = <<-PUPPET.unindent
|
154
|
+
$ctx = Puppet::LookupContext.new(nil)
|
155
|
+
$yaml_data = $ctx.cached_file_data('#{data_path}')
|
156
|
+
notice($yaml_data)
|
157
|
+
PUPPET
|
158
|
+
expect(eval_and_collect_notices(code, node)).to eql(["a: value a\n"])
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'can use cached_file_data with a block' do
|
162
|
+
code = <<-PUPPET.unindent
|
163
|
+
$ctx = Puppet::LookupContext.new(nil)
|
164
|
+
$yaml_data = $ctx.cached_file_data('#{data_path}') |$content| {
|
165
|
+
{ 'parsed' => $content }
|
166
|
+
}
|
167
|
+
notice($yaml_data)
|
168
|
+
PUPPET
|
169
|
+
expect(eval_and_collect_notices(code, node)).to eql(["{parsed => a: value a\n}"])
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'and multiple compilations' do
|
173
|
+
|
174
|
+
before(:each) { Puppet.settings[:environment_timeout] = 'unlimited' }
|
175
|
+
after(:each) do
|
176
|
+
Puppet.settings[:environment_timeout] = 0
|
177
|
+
Puppet.lookup(:environments).clear_all
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'will reuse cached_file_data and not call block again' do
|
181
|
+
|
182
|
+
code1 = <<-PUPPET.unindent
|
183
|
+
$ctx = Puppet::LookupContext.new(nil)
|
184
|
+
$yaml_data = $ctx.cached_file_data('#{data_path}') |$content| {
|
185
|
+
{ 'parsed' => $content }
|
186
|
+
}
|
187
|
+
notice($yaml_data)
|
188
|
+
PUPPET
|
189
|
+
|
190
|
+
code2 = <<-PUPPET.unindent
|
191
|
+
$ctx = Puppet::LookupContext.new(nil)
|
192
|
+
$yaml_data = $ctx.cached_file_data('#{data_path}') |$content| {
|
193
|
+
{ 'parsed' => 'should not be called' }
|
194
|
+
}
|
195
|
+
notice($yaml_data)
|
196
|
+
PUPPET
|
197
|
+
|
198
|
+
logs = []
|
199
|
+
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
|
200
|
+
Puppet[:code] = code1
|
201
|
+
Puppet::Parser::Compiler.compile(node)
|
202
|
+
Puppet[:code] = code2
|
203
|
+
Puppet::Parser::Compiler.compile(node)
|
204
|
+
end
|
205
|
+
logs = logs.select { |log| log.level == :notice }.map { |log| log.message }
|
206
|
+
expect(logs.uniq.size).to eql(1)
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'will invalidate cache if file changes' do
|
210
|
+
code = <<-PUPPET.unindent
|
211
|
+
$ctx = Puppet::LookupContext.new(nil)
|
212
|
+
$yaml_data = $ctx.cached_file_data('#{data_path}') |$content| {
|
213
|
+
{ 'parsed' => $content }
|
214
|
+
}
|
215
|
+
notice($yaml_data)
|
216
|
+
PUPPET
|
217
|
+
|
218
|
+
logs = []
|
219
|
+
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
|
220
|
+
Puppet[:code] = code
|
221
|
+
Puppet::Parser::Compiler.compile(node)
|
222
|
+
|
223
|
+
# Change contents!
|
224
|
+
File.write(data_path, "b: value b\n")
|
225
|
+
Puppet::Parser::Compiler.compile(node)
|
226
|
+
end
|
227
|
+
logs = logs.select { |log| log.level == :notice }.map { |log| log.message }
|
228
|
+
expect(logs).to eql(["{parsed => a: value a\n}", "{parsed => b: value b\n}"])
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
125
233
|
context 'when used in an Invocation' do
|
126
234
|
let(:node) { Puppet::Node.new('test') }
|
127
235
|
let(:compiler) { Puppet::Parser::Compiler.new(node) }
|
@@ -144,7 +252,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
144
252
|
it 'will not call explain unless explanations are active' do
|
145
253
|
invocation.lookup('dummy', nil) do
|
146
254
|
code = <<-PUPPET.unindent
|
147
|
-
$ctx = Puppet::LookupContext.new('
|
255
|
+
$ctx = Puppet::LookupContext.new('m')
|
148
256
|
$ctx.explain || { notice('stop calling'); 'bad' }
|
149
257
|
PUPPET
|
150
258
|
expect(compile_and_get_notices(code)).to be_empty
|
@@ -154,7 +262,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
154
262
|
it 'will call explain when explanations are active' do
|
155
263
|
invocation_with_explain.lookup('dummy', nil) do
|
156
264
|
code = <<-PUPPET.unindent
|
157
|
-
$ctx = Puppet::LookupContext.new('
|
265
|
+
$ctx = Puppet::LookupContext.new('m')
|
158
266
|
$ctx.explain || { notice('called'); 'good' }
|
159
267
|
PUPPET
|
160
268
|
expect(compile_and_get_notices(code)).to eql(['called'])
|
@@ -165,7 +273,7 @@ describe 'Puppet::Pops::Lookup::Context' do
|
|
165
273
|
it 'will call interpolate to resolve interpolation' do
|
166
274
|
invocation.lookup('dummy', nil) do
|
167
275
|
code = <<-PUPPET.unindent
|
168
|
-
$ctx = Puppet::LookupContext.new('
|
276
|
+
$ctx = Puppet::LookupContext.new('m')
|
169
277
|
notice($ctx.interpolate('-- %{testing} --'))
|
170
278
|
PUPPET
|
171
279
|
expect(compile_and_get_notices(code, { 'testing' => 'called' })).to eql(['-- called --'])
|
@@ -78,6 +78,40 @@ describe 'The lookup API' do
|
|
78
78
|
Puppet.pop_context
|
79
79
|
end
|
80
80
|
|
81
|
+
context 'when doing automatic parameter lookup' do
|
82
|
+
|
83
|
+
let(:mod_content) do
|
84
|
+
{
|
85
|
+
'hiera.yaml' => <<-YAML.unindent,
|
86
|
+
version: 5
|
87
|
+
YAML
|
88
|
+
'data' => {
|
89
|
+
'common.yaml' => <<-YAML.unindent
|
90
|
+
mod::x: mod::x (from module)
|
91
|
+
YAML
|
92
|
+
},
|
93
|
+
'manifests' => {
|
94
|
+
'init.pp' => <<-PUPPET.unindent
|
95
|
+
class mod($x) {
|
96
|
+
notify { $x: }
|
97
|
+
}
|
98
|
+
PUPPET
|
99
|
+
}
|
100
|
+
}
|
101
|
+
end
|
102
|
+
let(:logs) { [] }
|
103
|
+
let(:debugs) { logs.select { |log| log.level == :debug }.map { |log| log.message } }
|
104
|
+
|
105
|
+
it 'includes APL in explain output when debug is enabled' do
|
106
|
+
Puppet[:log_level] = 'debug'
|
107
|
+
Puppet[:code] = 'include mod'
|
108
|
+
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
|
109
|
+
compiler.compile
|
110
|
+
end
|
111
|
+
expect(debugs).to include(/Found key: "mod::x" value: "mod::x \(from module\)"/)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
81
115
|
context 'when doing lookup' do
|
82
116
|
it 'finds data in global layer' do
|
83
117
|
expect(Lookup.lookup('a', nil, nil, false, nil, invocation)).to eql('a (from global)')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.9.
|
4
|
+
version: 4.9.4
|
5
5
|
prerelease:
|
6
6
|
platform: x86-mingw32
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: facter
|