puppet 3.0.0.rc7 → 3.0.0.rc8
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/ext/build_defaults.yaml +3 -3
- data/lib/puppet/data_binding.rb +29 -0
- data/lib/puppet/defaults.rb +2 -10
- data/lib/puppet/indirector/hiera.rb +1 -31
- data/lib/puppet/resource.rb +40 -29
- data/lib/puppet/resource/type.rb +1 -1
- data/lib/puppet/version.rb +1 -1
- data/spec/integration/parser/undef_param_spec.rb +58 -59
- data/spec/unit/resource_spec.rb +11 -7
- metadata +5 -5
data/ext/build_defaults.yaml
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=master'
|
3
3
|
packaging_repo: 'packaging'
|
4
4
|
default_cow: 'base-squeeze-i386.cow'
|
5
|
-
cows: 'base-lucid-
|
5
|
+
cows: 'base-lucid-i386.cow base-natty-i386.cow base-oneiric-i386.cow base-precise-i386.cow base-sid-i386.cow base-squeeze-i386.cow base-stable-i386.cow base-testing-i386.cow base-unstable-i386.cow base-wheezy-i386.cow'
|
6
6
|
pbuild_conf: '/etc/pbuilderrc'
|
7
7
|
packager: 'puppetlabs'
|
8
8
|
gpg_name: 'info@puppetlabs.com'
|
9
9
|
gpg_key: '4BD6EC30'
|
10
10
|
sign_tar: FALSE
|
11
11
|
# a space separated list of mock configs
|
12
|
-
final_mocks: 'pl-5-i386 pl-
|
13
|
-
rc_mocks: 'pl-5-i386-dev pl-
|
12
|
+
final_mocks: 'pl-5-i386 pl-6-i386 fedora-15-i386 fedora-16-i386 fedora-17-i386'
|
13
|
+
rc_mocks: 'pl-5-i386-dev pl-6-i386-dev fedora-15-i386-dev fedora-16-i386-dev fedora-17-i386-dev'
|
14
14
|
yum_host: 'burji.puppetlabs.com'
|
15
15
|
yum_repo_path: '/opt/repository/yum/'
|
16
16
|
build_gem: TRUE
|
data/lib/puppet/data_binding.rb
CHANGED
@@ -8,4 +8,33 @@ class Puppet::DataBinding
|
|
8
8
|
|
9
9
|
indirects(:data_binding, :terminus_setting => :data_binding_terminus,
|
10
10
|
:doc => "Where to find external data bindings.")
|
11
|
+
|
12
|
+
# A class that acts just enough like a Puppet::Parser::Scope to
|
13
|
+
# fool Hiera's puppet backend. This class doesn't actually do anything
|
14
|
+
# but it does allow people to use the puppet backend with the hiera
|
15
|
+
# data bindings withough causing problems.
|
16
|
+
class Variables
|
17
|
+
FAKE_RESOURCE = Struct.new(:name).new("fake").freeze
|
18
|
+
FAKE_CATALOG = Struct.new(:classes).new([].freeze).freeze
|
19
|
+
|
20
|
+
def initialize(variable_bindings)
|
21
|
+
@variable_bindings = variable_bindings
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](name)
|
25
|
+
@variable_bindings[name]
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource
|
29
|
+
FAKE_RESOURCE
|
30
|
+
end
|
31
|
+
|
32
|
+
def catalog
|
33
|
+
FAKE_CATALOG
|
34
|
+
end
|
35
|
+
|
36
|
+
def function_include(name)
|
37
|
+
# noop
|
38
|
+
end
|
39
|
+
end
|
11
40
|
end
|
data/lib/puppet/defaults.rb
CHANGED
@@ -1488,14 +1488,7 @@ database from within the Puppet Master process."
|
|
1488
1488
|
|
1489
1489
|
# This doesn't actually work right now.
|
1490
1490
|
|
1491
|
-
|
1492
|
-
:parser,
|
1493
|
-
|
1494
|
-
:lexical => {
|
1495
|
-
:default => false,
|
1496
|
-
:type => :boolean,
|
1497
|
-
:desc => "Whether to use lexical scoping (vs. dynamic).",
|
1498
|
-
},
|
1491
|
+
define_settings(:parser,
|
1499
1492
|
:templatedir => {
|
1500
1493
|
:default => "$vardir/templates",
|
1501
1494
|
:type => :directory,
|
@@ -1503,8 +1496,7 @@ database from within the Puppet Master process."
|
|
1503
1496
|
directories.",
|
1504
1497
|
}
|
1505
1498
|
)
|
1506
|
-
define_settings(
|
1507
|
-
:puppetdoc,
|
1499
|
+
define_settings(:puppetdoc,
|
1508
1500
|
:document_all => {
|
1509
1501
|
:default => false,
|
1510
1502
|
:type => :boolean,
|
@@ -9,8 +9,7 @@ class Puppet::Indirector::Hiera < Puppet::Indirector::Terminus
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def find(request)
|
12
|
-
|
13
|
-
hiera.lookup(request.key, nil, fake_scope, nil, nil)
|
12
|
+
hiera.lookup(request.key, nil, request.options[:variables], nil, nil)
|
14
13
|
end
|
15
14
|
|
16
15
|
private
|
@@ -36,34 +35,5 @@ class Puppet::Indirector::Hiera < Puppet::Indirector::Terminus
|
|
36
35
|
def hiera
|
37
36
|
self.class.hiera
|
38
37
|
end
|
39
|
-
|
40
|
-
# A class that acts just enough like a Puppet::Parser::Scope to
|
41
|
-
# fool Hiera's puppet backend. This class doesn't actually do anything
|
42
|
-
# but it does allow people to use the puppet backend with the hiera
|
43
|
-
# data bindings withough causing problems.
|
44
|
-
class FakeScope
|
45
|
-
FAKE_RESOURCE = Struct.new(:name).new("fake").freeze
|
46
|
-
FAKE_CATALOG = Struct.new(:classes).new([].freeze).freeze
|
47
|
-
|
48
|
-
def initialize(variable_bindings)
|
49
|
-
@variable_bindings = variable_bindings
|
50
|
-
end
|
51
|
-
|
52
|
-
def [](name)
|
53
|
-
@variable_bindings[name]
|
54
|
-
end
|
55
|
-
|
56
|
-
def resource
|
57
|
-
FAKE_RESOURCE
|
58
|
-
end
|
59
|
-
|
60
|
-
def catalog
|
61
|
-
FAKE_CATALOG
|
62
|
-
end
|
63
|
-
|
64
|
-
def function_include(name)
|
65
|
-
# noop
|
66
|
-
end
|
67
|
-
end
|
68
38
|
end
|
69
39
|
|
data/lib/puppet/resource.rb
CHANGED
@@ -300,45 +300,56 @@ class Puppet::Resource
|
|
300
300
|
[ type, title ].join('/')
|
301
301
|
end
|
302
302
|
|
303
|
+
def missing_arguments
|
304
|
+
resource_type.arguments.select do |param, default|
|
305
|
+
param = param.to_sym
|
306
|
+
parameters[param].nil? || parameters[param].value == :undef
|
307
|
+
end
|
308
|
+
end
|
309
|
+
private :missing_arguments
|
310
|
+
|
311
|
+
# Consult external data bindings for class parameter values which must be
|
312
|
+
# namespaced in the backend.
|
313
|
+
#
|
314
|
+
# Example:
|
315
|
+
#
|
316
|
+
# class foo($port){ ... }
|
317
|
+
#
|
318
|
+
# We make a request to the backend for the key 'foo::port' not 'foo'
|
319
|
+
#
|
320
|
+
def lookup_external_default_for(param, scope)
|
321
|
+
if resource_type.type == :hostclass
|
322
|
+
Puppet::DataBinding.indirection.find(
|
323
|
+
"#{resource_type.name}::#{param}",
|
324
|
+
:environment => scope.environment.to_s,
|
325
|
+
:variables => Puppet::DataBinding::Variables.new(scope))
|
326
|
+
else
|
327
|
+
nil
|
328
|
+
end
|
329
|
+
end
|
330
|
+
private :lookup_external_default_for
|
331
|
+
|
303
332
|
def set_default_parameters(scope)
|
304
333
|
return [] unless resource_type and resource_type.respond_to?(:arguments)
|
305
334
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
param = param.to_sym
|
310
|
-
next if parameters.include?(param)
|
311
|
-
unless is_a?(Puppet::Parser::Resource)
|
312
|
-
fail Puppet::DevError, "Cannot evaluate default parameters for #{self} - not a parser resource"
|
313
|
-
end
|
335
|
+
unless is_a?(Puppet::Parser::Resource)
|
336
|
+
fail Puppet::DevError, "Cannot evaluate default parameters for #{self} - not a parser resource"
|
337
|
+
end
|
314
338
|
|
315
|
-
|
316
|
-
|
317
|
-
#
|
318
|
-
# Example:
|
319
|
-
#
|
320
|
-
# class foo($port){ ... }
|
321
|
-
#
|
322
|
-
# We make a request to the backend for the key 'foo::port' not 'foo'
|
323
|
-
#
|
324
|
-
external_value = nil
|
325
|
-
if resource_type.type == :hostclass
|
326
|
-
namespaced_param = "#{resource_type.name}::#{param}"
|
327
|
-
external_value = Puppet::DataBinding.indirection.find(
|
328
|
-
namespaced_param, :host => scope.host, :environment => scope.environment.to_s, :facts => scope.facts.values)
|
329
|
-
end
|
339
|
+
missing_arguments.collect do |param, default|
|
340
|
+
external_value = lookup_external_default_for(param, scope)
|
330
341
|
|
331
|
-
if external_value.nil?
|
332
|
-
next
|
342
|
+
if external_value.nil? && default.nil?
|
343
|
+
next
|
344
|
+
elsif external_value.nil?
|
333
345
|
value = default.safeevaluate(scope)
|
334
346
|
else
|
335
347
|
value = external_value
|
336
348
|
end
|
337
349
|
|
338
|
-
self[param] = value
|
339
|
-
|
340
|
-
end
|
341
|
-
result
|
350
|
+
self[param.to_sym] = value
|
351
|
+
param
|
352
|
+
end.compact
|
342
353
|
end
|
343
354
|
|
344
355
|
def to_resource
|
data/lib/puppet/resource/type.rb
CHANGED
@@ -316,7 +316,7 @@ class Puppet::Resource::Type
|
|
316
316
|
|
317
317
|
# Evaluate the default parameters, now that all other variables are set
|
318
318
|
default_params = resource.set_default_parameters(scope)
|
319
|
-
default_params.each { |param| scope[param
|
319
|
+
default_params.each { |param| scope[param] = resource[param] }
|
320
320
|
|
321
321
|
# This has to come after the above parameters so that default values
|
322
322
|
# can use their values
|
data/lib/puppet/version.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'puppet_spec/compiler'
|
3
3
|
|
4
|
-
describe "
|
4
|
+
describe "Parameter passing" do
|
5
5
|
include PuppetSpec::Compiler
|
6
6
|
|
7
|
+
before :each do
|
8
|
+
# DataBinding will be consulted before falling back to a default value,
|
9
|
+
# but we aren't testing that here
|
10
|
+
Puppet::DataBinding.indirection.stubs(:find)
|
11
|
+
end
|
12
|
+
|
7
13
|
def expect_the_message_to_be(message, node = Puppet::Node.new('the node'))
|
8
14
|
catalog = compile_to_catalog(yield, node)
|
9
15
|
catalog.resource('Notify', 'something')[:message].should == message
|
@@ -12,77 +18,70 @@ describe "Undefined parameters should be handled so that" do
|
|
12
18
|
def expect_puppet_error(message, node = Puppet::Node.new('the node'))
|
13
19
|
expect { compile_to_catalog(yield, node) }.to raise_error(Puppet::Error, message)
|
14
20
|
end
|
15
|
-
|
16
|
-
|
21
|
+
|
22
|
+
it "overrides the default when a value is given" do
|
23
|
+
expect_the_message_to_be('2') do <<-MANIFEST
|
24
|
+
define a($x=1) { notify { 'something': message => $x }}
|
25
|
+
a {'a': x => 2}
|
26
|
+
MANIFEST
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
class foo {
|
26
|
-
define a($x=1) { notify { 'something': message => $x }}
|
27
|
-
a {'a': x => 2}
|
28
|
-
}
|
29
|
-
MANIFEST
|
30
|
-
end
|
30
|
+
it "shadows an inherited variable with the default value when undef is passed" do
|
31
|
+
expect_the_message_to_be('default') do <<-MANIFEST
|
32
|
+
class a { $x = 'inherited' }
|
33
|
+
class b($x='default') inherits a { notify { 'something': message => $x }}
|
34
|
+
class { 'b': x => undef}
|
35
|
+
MANIFEST
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
class foo {
|
41
|
-
define a($x=1) { notify { 'something': message => $x == undef }}
|
42
|
-
a {'a': x => undef}
|
43
|
-
}
|
44
|
-
MANIFEST
|
45
|
-
end
|
39
|
+
it "uses a default value that comes from an inherited class when the parameter is undef" do
|
40
|
+
expect_the_message_to_be('inherited') do <<-MANIFEST
|
41
|
+
class a { $x = 'inherited' }
|
42
|
+
class b($y=$x) inherits a { notify { 'something': message => $y }}
|
43
|
+
class { 'b': y => undef}
|
44
|
+
MANIFEST
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
55
|
-
class foo {
|
56
|
-
define a($x=1) { notify { 'something': message => $x }}
|
57
|
-
a {'a': }
|
58
|
-
}
|
59
|
-
MANIFEST
|
60
|
-
end
|
48
|
+
it "uses a default value that references another variable when the parameter is passed as undef" do
|
49
|
+
expect_the_message_to_be('a') do <<-MANIFEST
|
50
|
+
define a($a = $title) { notify { 'something': message => $a }}
|
51
|
+
a {'a': a => undef}
|
52
|
+
MANIFEST
|
61
53
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
define a($x=undef) { notify { 'something': message => $x == undef}}
|
69
|
-
a {'a': }
|
70
|
-
}
|
54
|
+
end
|
55
|
+
|
56
|
+
it "uses the default when 'undef' is given'" do
|
57
|
+
expect_the_message_to_be('1') do <<-MANIFEST
|
58
|
+
define a($x=1) { notify { 'something': message => $x }}
|
59
|
+
a {'a': x => undef}
|
71
60
|
MANIFEST
|
72
|
-
end
|
73
61
|
end
|
62
|
+
end
|
74
63
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
}
|
80
|
-
class foo {
|
81
|
-
define a($x) { notify { 'something': message => $x }}
|
82
|
-
a {'a': }
|
83
|
-
}
|
64
|
+
it "uses the default when no parameter is provided" do
|
65
|
+
expect_the_message_to_be('1') do <<-MANIFEST
|
66
|
+
define a($x=1) { notify { 'something': message => $x }}
|
67
|
+
a {'a': }
|
84
68
|
MANIFEST
|
85
|
-
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "uses a value of undef when the default is undef and no parameter is provided" do
|
73
|
+
expect_the_message_to_be(true) do <<-MANIFEST
|
74
|
+
define a($x=undef) { notify { 'something': message => $x == undef}}
|
75
|
+
a {'a': }
|
76
|
+
MANIFEST
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "errors when no parameter is provided and there is no default" do
|
81
|
+
expect_puppet_error(/^Must pass x to A\[a\].*/) do <<-MANIFEST
|
82
|
+
define a($x) { notify { 'something': message => $x }}
|
83
|
+
a {'a': }
|
84
|
+
MANIFEST
|
86
85
|
end
|
87
86
|
end
|
88
87
|
end
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -302,21 +302,21 @@ describe Puppet::Resource do
|
|
302
302
|
Puppet::Resource::Type.new(:definition, "default_param", :arguments => {"a" => Puppet::Parser::AST::String.new(:value => "a_default_value")})
|
303
303
|
)
|
304
304
|
resource = Puppet::Parser::Resource.new("default_param", "name", :scope => Puppet::Parser::Scope.new(Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))))
|
305
|
-
resource.set_default_parameters(@scope).should == [
|
305
|
+
resource.set_default_parameters(@scope).should == ["a"]
|
306
306
|
end
|
307
307
|
|
308
308
|
describe "when the resource type is :hostclass" do
|
309
|
-
let(:
|
309
|
+
let(:environment_name) { "testing env" }
|
310
310
|
let(:fact_values) { { :a => 1 } }
|
311
311
|
let(:port) { Puppet::Parser::AST::String.new(:value => '80') }
|
312
312
|
let(:apache) { Puppet::Resource::Type.new(:hostclass, 'apache', :arguments => { 'port' => port }) }
|
313
313
|
|
314
314
|
before do
|
315
|
-
environment = Puppet::Node::Environment.new(
|
315
|
+
environment = Puppet::Node::Environment.new(environment_name)
|
316
316
|
environment.known_resource_types.add(apache)
|
317
317
|
|
318
318
|
@scope.stubs(:host).returns('host')
|
319
|
-
@scope.stubs(:environment).returns(Puppet::Node::Environment.new(
|
319
|
+
@scope.stubs(:environment).returns(Puppet::Node::Environment.new(environment_name))
|
320
320
|
@scope.stubs(:facts).returns(Puppet::Node::Facts.new("facts", fact_values))
|
321
321
|
end
|
322
322
|
|
@@ -327,19 +327,23 @@ describe Puppet::Resource do
|
|
327
327
|
|
328
328
|
it "should query the data_binding terminus using a namespaced key" do
|
329
329
|
Puppet::DataBinding.indirection.expects(:find).with(
|
330
|
-
'apache::port', :
|
330
|
+
'apache::port', all_of(has_key(:environment), has_key(:variables)))
|
331
331
|
resource.set_default_parameters(@scope)
|
332
332
|
end
|
333
333
|
|
334
334
|
it "should use the value from the data_binding terminus" do
|
335
335
|
Puppet::DataBinding.indirection.expects(:find).returns('443')
|
336
|
-
|
336
|
+
|
337
|
+
resource.set_default_parameters(@scope)
|
338
|
+
|
337
339
|
resource[:port].should == '443'
|
338
340
|
end
|
339
341
|
|
340
342
|
it "should use the default value if the data_binding terminus returns nil" do
|
341
343
|
Puppet::DataBinding.indirection.expects(:find).returns(nil)
|
342
|
-
|
344
|
+
|
345
|
+
resource.set_default_parameters(@scope)
|
346
|
+
|
343
347
|
resource[:port].should == '80'
|
344
348
|
end
|
345
349
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3961099711
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 3.0.0.
|
11
|
+
- 8
|
12
|
+
version: 3.0.0.rc8
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Puppet Labs
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-09-
|
20
|
+
date: 2012-09-25 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: hiera
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 1980549863
|
31
31
|
segments:
|
32
32
|
- 1
|
33
33
|
- 0
|