puppet 3.1.0.rc1 → 3.1.0.rc2
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/COMMITTERS.md +185 -0
- data/ext/debian/changelog.erb +6 -0
- data/ext/debian/puppet-common.manpages +1 -0
- data/ext/debian/puppet.default +3 -1
- data/ext/debian/puppetmaster.default +6 -3
- data/ext/redhat/puppet.spec.erb +16 -5
- data/lib/puppet.rb +3 -5
- data/lib/puppet/defaults.rb +6 -5
- data/lib/puppet/dsl.rb +3 -7
- data/lib/puppet/dsl/resource_api.rb +120 -0
- data/lib/puppet/dsl/resource_type_api.rb +34 -0
- data/lib/puppet/module_tool.rb +23 -11
- data/lib/puppet/network/formats.rb +1 -1
- data/lib/puppet/node/environment.rb +1 -3
- data/lib/puppet/parser/ast/definition.rb +5 -2
- data/lib/puppet/parser/ast/hostclass.rb +3 -2
- data/lib/puppet/parser/ast/node.rb +5 -2
- data/lib/puppet/parser/ast/resourceparam.rb +1 -1
- data/lib/puppet/parser/compiler.rb +0 -10
- data/lib/puppet/parser/lexer.rb +50 -39
- data/lib/puppet/parser/parser_support.rb +29 -11
- data/lib/puppet/parser/scope.rb +2 -2
- data/lib/puppet/parser/type_loader.rb +7 -31
- data/lib/puppet/provider/package/openbsd.rb +16 -2
- data/lib/puppet/provider/package/pip.rb +11 -2
- data/lib/puppet/provider/package/portage.rb +29 -12
- data/lib/puppet/provider/service/launchd.rb +19 -14
- data/lib/puppet/provider/service/upstart.rb +1 -1
- data/lib/puppet/provider/user/hpux.rb +37 -2
- data/lib/puppet/resource.rb +25 -38
- data/lib/puppet/resource/type.rb +6 -14
- data/lib/puppet/settings.rb +1 -1
- data/lib/puppet/ssl/certificate_authority.rb +4 -1
- data/lib/puppet/ssl/certificate_request.rb +3 -1
- data/lib/puppet/ssl/certificate_signer.rb +22 -0
- data/lib/puppet/type.rb +4 -4
- data/lib/puppet/util/methodhelper.rb +0 -19
- data/lib/puppet/util/rubygems.rb +3 -1
- data/lib/puppet/util/selinux.rb +1 -6
- data/lib/puppet/version.rb +1 -1
- data/man/man5/puppet.conf.5 +81 -95
- data/man/man8/extlookup2hiera.8 +23 -0
- data/man/man8/puppet-agent.8 +3 -3
- data/man/man8/puppet-apply.8 +2 -6
- data/man/man8/puppet-ca.8 +6 -7
- data/man/man8/puppet-catalog.8 +6 -7
- data/man/man8/puppet-cert.8 +4 -4
- data/man/man8/puppet-certificate.8 +6 -7
- data/man/man8/puppet-certificate_request.8 +6 -7
- data/man/man8/puppet-certificate_revocation_list.8 +6 -7
- data/man/man8/puppet-config.8 +4 -8
- data/man/man8/puppet-describe.8 +1 -1
- data/man/man8/puppet-device.8 +1 -1
- data/man/man8/puppet-doc.8 +3 -3
- data/man/man8/puppet-facts.8 +4 -8
- data/man/man8/puppet-file.8 +6 -7
- data/man/man8/puppet-filebucket.8 +1 -1
- data/man/man8/puppet-help.8 +2 -6
- data/man/man8/puppet-inspect.8 +1 -1
- data/man/man8/puppet-instrumentation_data.8 +3 -7
- data/man/man8/puppet-instrumentation_listener.8 +3 -7
- data/man/man8/puppet-instrumentation_probe.8 +3 -7
- data/man/man8/puppet-key.8 +6 -7
- data/man/man8/puppet-kick.8 +5 -1
- data/man/man8/puppet-man.8 +2 -6
- data/man/man8/puppet-master.8 +2 -2
- data/man/man8/puppet-module.8 +11 -9
- data/man/man8/puppet-node.8 +38 -37
- data/man/man8/puppet-parser.8 +2 -6
- data/man/man8/puppet-plugin.8 +2 -6
- data/man/man8/puppet-queue.8 +1 -1
- data/man/man8/puppet-report.8 +3 -7
- data/man/man8/puppet-resource.8 +1 -1
- data/man/man8/puppet-resource_type.8 +3 -7
- data/man/man8/puppet-secret_agent.8 +2 -6
- data/man/man8/puppet-status.8 +3 -7
- data/man/man8/puppet.8 +1 -1
- data/spec/integration/parser/ruby_manifest_spec.rb +128 -0
- data/spec/lib/puppet_spec/compiler.rb +0 -11
- data/spec/spec_helper.rb +3 -4
- data/spec/unit/dsl/resource_api_spec.rb +180 -0
- data/spec/unit/dsl/resource_type_api_spec.rb +53 -0
- data/spec/unit/module_tool_spec.rb +79 -46
- data/spec/unit/network/formats_spec.rb +4 -0
- data/spec/unit/node/environment_spec.rb +0 -13
- data/spec/unit/parser/compiler_spec.rb +0 -26
- data/spec/unit/parser/parser_spec.rb +14 -0
- data/spec/unit/parser/type_loader_spec.rb +4 -15
- data/spec/unit/provider/package/openbsd_spec.rb +148 -35
- data/spec/unit/provider/package/pip_spec.rb +49 -25
- data/spec/unit/provider/package/portage_spec.rb +65 -0
- data/spec/unit/provider/service/launchd_spec.rb +6 -5
- data/spec/unit/provider/user/hpux_spec.rb +39 -11
- data/spec/unit/provider/user/useradd_spec.rb +14 -14
- data/spec/unit/resource/type_spec.rb +7 -49
- data/spec/unit/resource_spec.rb +0 -32
- data/spec/unit/ssl/certificate_request_spec.rb +18 -0
- data/spec/unit/util/rubygems_spec.rb +1 -1
- data/spec/unit/util/selinux_spec.rb +0 -2
- metadata +17 -50
- data/lib/puppet/dsl/actions.rb +0 -283
- data/lib/puppet/dsl/blank_slate.rb +0 -55
- data/lib/puppet/dsl/context.rb +0 -393
- data/lib/puppet/dsl/parser.rb +0 -57
- data/lib/puppet/dsl/resource_decorator.rb +0 -56
- data/lib/puppet/dsl/resource_reference.rb +0 -95
- data/lib/puppet/dsl/type_reference.rb +0 -102
- data/lib/puppet/util/manifest_filetype_helper.rb +0 -22
- data/spec/integration/dsl/classes_spec.rb +0 -191
- data/spec/integration/dsl/defaults_spec.rb +0 -38
- data/spec/integration/dsl/definitions_spec.rb +0 -73
- data/spec/integration/dsl/functions_spec.rb +0 -95
- data/spec/integration/dsl/nodes_spec.rb +0 -96
- data/spec/integration/dsl/params_spec.rb +0 -146
- data/spec/integration/dsl/relationships_spec.rb +0 -46
- data/spec/integration/dsl/resources_spec.rb +0 -202
- data/spec/integration/dsl/type_loading_spec.rb +0 -64
- data/spec/lib/matchers/catalog.rb +0 -50
- data/spec/lib/puppet_spec/dsl.rb +0 -29
- data/spec/unit/dsl/actions_spec.rb +0 -402
- data/spec/unit/dsl/blank_slate_spec.rb +0 -27
- data/spec/unit/dsl/context_spec.rb +0 -678
- data/spec/unit/dsl/parser_spec.rb +0 -56
- data/spec/unit/dsl/resource_decorator_spec.rb +0 -94
- data/spec/unit/dsl/resource_reference_spec.rb +0 -150
- data/spec/unit/dsl/type_reference_spec.rb +0 -164
- data/spec/unit/util/manifest_filetype_helper_spec.rb +0 -29
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'puppet'
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'matchers/catalog'
|
4
|
-
require 'puppet_spec/compiler'
|
5
|
-
|
6
|
-
include PuppetSpec::Compiler
|
7
|
-
|
8
|
-
describe Puppet::DSL do
|
9
|
-
prepare_compiler
|
10
|
-
|
11
|
-
describe "relationships" do
|
12
|
-
it "allows requiring resources" do
|
13
|
-
p = compile_to_catalog(<<-'END')
|
14
|
-
define foo() {
|
15
|
-
notify {"foo": message => "foo" }
|
16
|
-
}
|
17
|
-
define bar() {
|
18
|
-
notify {"bar": message => "bar" }
|
19
|
-
}
|
20
|
-
|
21
|
-
node "default" {
|
22
|
-
bar {"bar": }
|
23
|
-
foo {"foo": require => Bar["bar"] }
|
24
|
-
}
|
25
|
-
END
|
26
|
-
|
27
|
-
r = compile_ruby_to_catalog(<<-'END')
|
28
|
-
define :foo do
|
29
|
-
notify "foo", :message => "foo"
|
30
|
-
end
|
31
|
-
|
32
|
-
define :bar do
|
33
|
-
notify "bar", :message => "bar"
|
34
|
-
end
|
35
|
-
|
36
|
-
node "default" do
|
37
|
-
bar "bar"
|
38
|
-
foo "foo", :require => Bar["bar"]
|
39
|
-
end
|
40
|
-
END
|
41
|
-
|
42
|
-
r.should be_equivalent_to_catalog p
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
@@ -1,202 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'matchers/catalog'
|
3
|
-
require 'puppet_spec/compiler'
|
4
|
-
|
5
|
-
include PuppetSpec::Compiler
|
6
|
-
|
7
|
-
describe Puppet::DSL do
|
8
|
-
prepare_compiler
|
9
|
-
|
10
|
-
describe "resources" do
|
11
|
-
|
12
|
-
it "should be able to define resource" do
|
13
|
-
p = compile_to_catalog(<<-MANIFEST)
|
14
|
-
define foo() {
|
15
|
-
notice("foo")
|
16
|
-
}
|
17
|
-
MANIFEST
|
18
|
-
|
19
|
-
r = compile_ruby_to_catalog(<<-MANIFEST)
|
20
|
-
define "foo" do
|
21
|
-
notice "foo"
|
22
|
-
end
|
23
|
-
MANIFEST
|
24
|
-
|
25
|
-
r.should be_equivalent_to_catalog p
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should be able to define resource with parameters" do
|
29
|
-
p = compile_to_catalog(<<-MANIFEST)
|
30
|
-
define foo($msg) {
|
31
|
-
notice($msg)
|
32
|
-
}
|
33
|
-
MANIFEST
|
34
|
-
|
35
|
-
r = compile_ruby_to_catalog(<<-MANIFEST)
|
36
|
-
define :foo, :arguments => {:msg => nil} do
|
37
|
-
notice params[:msg]
|
38
|
-
end
|
39
|
-
MANIFEST
|
40
|
-
|
41
|
-
r.should be_equivalent_to_catalog p
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should be able to use defined resource" do
|
45
|
-
p = compile_to_catalog(<<-MANIFEST)
|
46
|
-
define foo() {
|
47
|
-
notice("foo")
|
48
|
-
}
|
49
|
-
|
50
|
-
foo {"foo": }
|
51
|
-
MANIFEST
|
52
|
-
|
53
|
-
r = compile_ruby_to_catalog(<<-MANIFEST)
|
54
|
-
define :foo do
|
55
|
-
notice "foo"
|
56
|
-
end
|
57
|
-
|
58
|
-
foo "foo"
|
59
|
-
MANIFEST
|
60
|
-
|
61
|
-
r.should be_equivalent_to_catalog p
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should be able to use defined resource in a node" do
|
65
|
-
p = compile_to_catalog(<<-MANIFEST)
|
66
|
-
define foo() {
|
67
|
-
notice("foo")
|
68
|
-
}
|
69
|
-
|
70
|
-
node default {
|
71
|
-
foo {"foo": }
|
72
|
-
}
|
73
|
-
MANIFEST
|
74
|
-
|
75
|
-
r = compile_ruby_to_catalog(<<-MANIFEST)
|
76
|
-
define :foo do
|
77
|
-
notice "foo"
|
78
|
-
end
|
79
|
-
|
80
|
-
node 'default' do
|
81
|
-
foo "foo"
|
82
|
-
end
|
83
|
-
MANIFEST
|
84
|
-
|
85
|
-
r.should be_equivalent_to_catalog p
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should be able to use defined resource in a class" do
|
89
|
-
p = compile_to_catalog(<<-MANIFEST)
|
90
|
-
define foo() {
|
91
|
-
notice($name)
|
92
|
-
}
|
93
|
-
|
94
|
-
class bar {
|
95
|
-
foo {"foo": }
|
96
|
-
}
|
97
|
-
MANIFEST
|
98
|
-
|
99
|
-
r = compile_ruby_to_catalog(<<-MANIFEST)
|
100
|
-
define :foo do
|
101
|
-
notice params[:name]
|
102
|
-
end
|
103
|
-
|
104
|
-
hostclass :bar do
|
105
|
-
foo "foo"
|
106
|
-
end
|
107
|
-
MANIFEST
|
108
|
-
|
109
|
-
r.should be_equivalent_to_catalog p
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should be able to export resources" do
|
113
|
-
p = compile_to_catalog(<<-MANIFEST)
|
114
|
-
define foo($msg = "bar") {
|
115
|
-
notify {$msg: message => $msg}
|
116
|
-
}
|
117
|
-
|
118
|
-
node default {
|
119
|
-
@@foo {"foobar":}
|
120
|
-
|
121
|
-
Foo <<| |>>
|
122
|
-
}
|
123
|
-
MANIFEST
|
124
|
-
|
125
|
-
r = compile_ruby_to_catalog(<<-MANIFEST)
|
126
|
-
define :foo, :arguments => {:msg => "bar"} do
|
127
|
-
notify params[:msg], :message => params[:msg]
|
128
|
-
end
|
129
|
-
|
130
|
-
node "default" do
|
131
|
-
export do
|
132
|
-
foo "foobar"
|
133
|
-
end
|
134
|
-
|
135
|
-
Foo.collect
|
136
|
-
end
|
137
|
-
MANIFEST
|
138
|
-
|
139
|
-
p.should be_equivalent_to_catalog r
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should be able to virtualise resources" do
|
143
|
-
p = compile_to_catalog(<<-MANIFEST)
|
144
|
-
define foo($msg = "bar") {
|
145
|
-
notify {$msg: message => $msg}
|
146
|
-
}
|
147
|
-
|
148
|
-
node default {
|
149
|
-
@foo {"foobar":}
|
150
|
-
|
151
|
-
Foo <| |>
|
152
|
-
}
|
153
|
-
MANIFEST
|
154
|
-
|
155
|
-
r = compile_ruby_to_catalog(<<-MANIFEST)
|
156
|
-
define :foo, :arguments => {:msg => "bar"} do
|
157
|
-
notify params[:msg], :message => params[:msg]
|
158
|
-
end
|
159
|
-
|
160
|
-
node "default" do
|
161
|
-
virtual do
|
162
|
-
foo "foobar"
|
163
|
-
end
|
164
|
-
|
165
|
-
Foo.realise
|
166
|
-
end
|
167
|
-
MANIFEST
|
168
|
-
|
169
|
-
p.should be_equivalent_to_catalog r
|
170
|
-
end
|
171
|
-
|
172
|
-
context "references" do
|
173
|
-
before :each do
|
174
|
-
@catalog = compile_to_catalog(<<-MANIFEST)
|
175
|
-
file {"redis.conf": owner => root}
|
176
|
-
|
177
|
-
service {"redis": require => File['redis.conf']}
|
178
|
-
MANIFEST
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should be able to reference other resources" do
|
182
|
-
compile_ruby_to_catalog(<<-MANIFEST).should be_equivalent_to_catalog @catalog
|
183
|
-
file "redis.conf", :owner => "root"
|
184
|
-
|
185
|
-
service "redis", :require => File["redis.conf"]
|
186
|
-
MANIFEST
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should be able to reference other resources using a block" do
|
190
|
-
r = compile_ruby_to_catalog(<<-MANIFEST).should be_equivalent_to_catalog @catalog
|
191
|
-
file "redis.conf", :owner => "root"
|
192
|
-
|
193
|
-
service "redis" do |s|
|
194
|
-
s.require = File["redis.conf"]
|
195
|
-
end
|
196
|
-
MANIFEST
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet_spec/compiler'
|
3
|
-
require 'puppet_spec/modules'
|
4
|
-
require 'puppet_spec/files'
|
5
|
-
|
6
|
-
include PuppetSpec::Compiler
|
7
|
-
include PuppetSpec::Modules
|
8
|
-
include PuppetSpec::Files
|
9
|
-
|
10
|
-
describe Puppet::DSL do
|
11
|
-
def mk_manifest(file, content)
|
12
|
-
name = self.module.name + "::" + file.gsub("/", "::").split(".")[0]
|
13
|
-
path = File.join(modulebase, self.module.name, "manifests", file)
|
14
|
-
FileUtils.mkdir_p(File.split(path)[0])
|
15
|
-
|
16
|
-
File.open(path, "w") { |f| f.print content }
|
17
|
-
end
|
18
|
-
|
19
|
-
prepare_compiler
|
20
|
-
|
21
|
-
let(:modulebase) do
|
22
|
-
base = File.join(tmpdir("base"), "modules")
|
23
|
-
FileUtils.mkdir_p(base)
|
24
|
-
Puppet[:modulepath] = base
|
25
|
-
base
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:module) { PuppetSpec::Modules.create "module", modulebase }
|
29
|
-
|
30
|
-
describe "type loader" do
|
31
|
-
|
32
|
-
it "should load ruby code when referenced from puppet" do
|
33
|
-
mk_manifest("foo.rb", <<-MANIFEST)
|
34
|
-
hostclass :'module::foo' do; end
|
35
|
-
MANIFEST
|
36
|
-
|
37
|
-
compile_to_catalog(<<-MANIFEST)
|
38
|
-
include module::foo
|
39
|
-
MANIFEST
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should load ruby code when referenced from ruby" do
|
43
|
-
mk_manifest("bar.rb", <<-MANIFEST)
|
44
|
-
hostclass :'module::bar' do; end
|
45
|
-
MANIFEST
|
46
|
-
|
47
|
-
compile_ruby_to_catalog(<<-MANIFEST)
|
48
|
-
use :'module::bar'
|
49
|
-
MANIFEST
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should load puppet code when referenced from ruby" do
|
53
|
-
mk_manifest("baz.pp", <<-MANIFEST)
|
54
|
-
class module::baz {}
|
55
|
-
MANIFEST
|
56
|
-
|
57
|
-
compile_ruby_to_catalog(<<-MANIFEST)
|
58
|
-
use :'module::bar'
|
59
|
-
MANIFEST
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
@@ -1,50 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define :be_equivalent_to_catalog do |expected|
|
2
|
-
diffable
|
3
|
-
|
4
|
-
match do |actual|
|
5
|
-
actual.is_a? Puppet::Resource::Catalog and
|
6
|
-
expected.is_a? Puppet::Resource::Catalog and
|
7
|
-
compare_catalogs(actual, expected)
|
8
|
-
end
|
9
|
-
|
10
|
-
failure_message_for_should do |actual|
|
11
|
-
"expected catalog #{actual.inspect} would be equivalent to catalog #{expected.inspect}"
|
12
|
-
end
|
13
|
-
|
14
|
-
failure_message_for_should_not do |actual|
|
15
|
-
"expected catalog #{actual.inspect} would not be equivalent to catalog #{expected.inspect}"
|
16
|
-
end
|
17
|
-
|
18
|
-
description do
|
19
|
-
"be equivalent to catalog #{expected.inspect}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def compare_catalogs(actual, expected)
|
23
|
-
compare_attributes([:name, :environment, :tags, :classes], actual, expected) and
|
24
|
-
compare_resources(actual, expected) and
|
25
|
-
compare_relationships(actual, expected)
|
26
|
-
end
|
27
|
-
|
28
|
-
def compare_attributes(attributes, actual, expected)
|
29
|
-
attributes.all? do |attribute|
|
30
|
-
actual.send(attribute) == expected.send(attribute)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def compare_relationships(actual, expected)
|
35
|
-
actual = actual.edges.sort_by { |r| r.to_s }
|
36
|
-
expected = expected.edges.sort_by { |r| r.to_s }
|
37
|
-
|
38
|
-
[:source, :target, :event, :callback].all? do |attribute|
|
39
|
-
actual.map(&attribute) == expected.map(&attribute)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def compare_resources(actual, expected)
|
44
|
-
actual = actual.resources.sort_by { |r| r.name }
|
45
|
-
expected = expected.resources.sort_by { |r| r.name }
|
46
|
-
|
47
|
-
actual == expected
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
data/spec/lib/puppet_spec/dsl.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module PuppetSpec
|
2
|
-
module DSL
|
3
|
-
|
4
|
-
def prepare_compiler_and_scope_for_evaluation
|
5
|
-
let(:compiler) { Puppet::Parser::Compiler.new Puppet::Node.new("test") }
|
6
|
-
let(:scope) { Puppet::Parser::Scope.new compiler, :source => "test" }
|
7
|
-
end
|
8
|
-
|
9
|
-
def evaluate_in_context(options = {}, &block)
|
10
|
-
eval_scope = options.fetch :scope, scope
|
11
|
-
Puppet::DSL::Context.new(block, options).evaluate eval_scope, eval_scope.known_resource_types
|
12
|
-
end
|
13
|
-
|
14
|
-
def known_resource_types
|
15
|
-
compiler.known_resource_types
|
16
|
-
end
|
17
|
-
|
18
|
-
def evaluate_in_scope(options = {})
|
19
|
-
eval_scope = options.fetch :scope, scope
|
20
|
-
Puppet::DSL::Parser.add_scope eval_scope
|
21
|
-
Puppet::DSL::Parser.known_resource_types = eval_scope.known_resource_types
|
22
|
-
yield
|
23
|
-
ensure
|
24
|
-
Puppet::DSL::Parser.known_resource_types = nil
|
25
|
-
Puppet::DSL::Parser.remove_scope
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,402 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'puppet_spec/dsl'
|
3
|
-
|
4
|
-
require 'puppet/dsl/actions'
|
5
|
-
|
6
|
-
include PuppetSpec::DSL
|
7
|
-
|
8
|
-
describe Puppet::DSL::Actions do
|
9
|
-
prepare_compiler_and_scope_for_evaluation
|
10
|
-
subject { Puppet::DSL::Actions.new :undefined }
|
11
|
-
|
12
|
-
describe "#type_reference" do
|
13
|
-
it "returns a type reference object" do
|
14
|
-
evaluate_in_scope do
|
15
|
-
subject.type_reference("file").should be_a Puppet::DSL::TypeReference
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns a type reference for a given type" do
|
20
|
-
evaluate_in_scope do
|
21
|
-
subject.type_reference("file").type_name.should == "File"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#is_resource_type?" do
|
27
|
-
|
28
|
-
it "should return true when type is a class" do
|
29
|
-
evaluate_in_scope do
|
30
|
-
subject.is_resource_type?(:class).should be true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should return true when type is a node" do
|
35
|
-
evaluate_in_scope do
|
36
|
-
subject.is_resource_type?(:node).should be true
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should return true when type is a builtin type" do
|
41
|
-
evaluate_in_scope do
|
42
|
-
subject.is_resource_type?(:file).should be true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should return true when type is defined in manifests" do
|
47
|
-
evaluate_in_context { define(:foo) {} }
|
48
|
-
evaluate_in_scope do
|
49
|
-
subject.is_resource_type?(:foo).should be true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should return false otherwise" do
|
54
|
-
evaluate_in_scope do
|
55
|
-
subject.is_resource_type?(:asdasdasfasf).should be false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#is_function?" do
|
62
|
-
it "should return true when a puppet function exists" do
|
63
|
-
subject.is_function?("notice").should be true
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should return false otherwise" do
|
67
|
-
subject.is_function?("asdfasdf").should be false
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe "#get_resource" do
|
72
|
-
|
73
|
-
it "should return the reference if it's already a resource" do
|
74
|
-
ref = Puppet::Resource.new "foo", "bar"
|
75
|
-
subject.send(:get_resource, ref).should == ref
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should get a resource from Puppet::DSL::ResourceReference" do
|
79
|
-
res = evaluate_in_context { file "foo" }.first
|
80
|
-
ref = evaluate_in_context { type("file")["foo"] }
|
81
|
-
subject.send(:get_resource, ref).should == res
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should get a resource from a string" do
|
85
|
-
res = evaluate_in_context { file "foo" }.first
|
86
|
-
evaluate_in_scope { subject.send(:get_resource, "File[foo]").should == res }
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should return a string when the string reference doesn't exist" do
|
90
|
-
reference = "File[foo]"
|
91
|
-
evaluate_in_scope { subject.send(:get_resource, reference).should == reference }
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should stringify the parameter when resource can't be found" do
|
95
|
-
evaluate_in_scope { subject.send(:get_resource, 3).should == "3" }
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "#params" do
|
100
|
-
it "returns current scope" do
|
101
|
-
evaluate_in_scope do
|
102
|
-
subject.params.should == Puppet::DSL::Parser.current_scope
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#create_node" do
|
109
|
-
it "raises NoMethodError when called from invalid nesting" do
|
110
|
-
lambda do
|
111
|
-
subject.create_node "foo", {}, 1 do
|
112
|
-
end
|
113
|
-
end.should raise_error NoMethodError
|
114
|
-
end
|
115
|
-
|
116
|
-
it "raises ArgumentError when code is nil" do
|
117
|
-
lambda do
|
118
|
-
subject.create_node "foo", {}, nil, 0
|
119
|
-
end.should raise_error ArgumentError
|
120
|
-
end
|
121
|
-
|
122
|
-
it "creates a new puppet node" do
|
123
|
-
evaluate_in_scope do
|
124
|
-
subject.create_node("foo", {}, 0) {}.tap do |r|
|
125
|
-
r.type.should == :node
|
126
|
-
r.name.should == "foo"
|
127
|
-
end.should be_a Puppet::Resource::Type
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
it "allows to pass a regex instead of name" do
|
132
|
-
evaluate_in_scope do
|
133
|
-
subject.create_node(/foo/, {}, 0) {}.tap do |r|
|
134
|
-
r.name_is_regex?.should be true
|
135
|
-
end.should be_a Puppet::Resource::Type
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
it "sets options for puppet node" do
|
140
|
-
evaluate_in_scope do
|
141
|
-
subject.create_node("foo", {:inherits => "bar"}, 0) {}.parent.should == "bar"
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
it "adds the node to known resource types" do
|
146
|
-
evaluate_in_scope do
|
147
|
-
resource_types = mock
|
148
|
-
resource_types.expects(:add_node).with {|n| n.type == :node }
|
149
|
-
resource_types.stubs(:hostclass).returns nil
|
150
|
-
Puppet::DSL::Parser.stubs(:known_resource_types).returns resource_types
|
151
|
-
|
152
|
-
subject.create_node "foo", {}, 0 do
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
it "sets ruby code for the node" do
|
158
|
-
block = proc {}
|
159
|
-
context = mock "Context"
|
160
|
-
Puppet::DSL::Context.expects(:new).with {|code, _| code == block}.returns context
|
161
|
-
evaluate_in_scope do
|
162
|
-
subject.create_node("foo", {}, 0, &block).ruby_code.should include context
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "#create_hostclass" do
|
168
|
-
it "raises NoMethodError when called from invalid nesting" do
|
169
|
-
lambda do
|
170
|
-
subject.create_hostclass :foo, {}, 1 do
|
171
|
-
end
|
172
|
-
end.should raise_error NoMethodError
|
173
|
-
end
|
174
|
-
|
175
|
-
it "raises ArgumentError when code is nil" do
|
176
|
-
lambda do
|
177
|
-
subject.create_hostclass :foo, {}, nil, 0
|
178
|
-
end.should raise_error ArgumentError
|
179
|
-
end
|
180
|
-
|
181
|
-
it "creates a new puppet hostclass" do
|
182
|
-
evaluate_in_scope do
|
183
|
-
subject.create_hostclass(:foo, {}, 0) {}.tap do |r|
|
184
|
-
r.type.should == :hostclass
|
185
|
-
r.name.should == "foo"
|
186
|
-
end.should be_a Puppet::Resource::Type
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
it "sets options for puppet hostclass" do
|
191
|
-
evaluate_in_scope do
|
192
|
-
subject.create_hostclass(:foo, {:inherits => :bar, :arguments => {:myparam => 3}}, 0) {}.tap do |r|
|
193
|
-
r.parent.should == "bar"
|
194
|
-
r.arguments.should == {"myparam" => 3}
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
it "adds the hostclass to resource type collection" do
|
200
|
-
evaluate_in_scope do
|
201
|
-
resource_types = mock
|
202
|
-
resource_types.expects(:add_hostclass).with {|n| n.type == :hostclass }
|
203
|
-
Puppet::DSL::Parser.stubs(:known_resource_types).returns resource_types
|
204
|
-
|
205
|
-
subject.create_hostclass :foo, {}, 0 do
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
it "sets ruby code for hostclass" do
|
211
|
-
block = proc {}
|
212
|
-
context = mock "Context"
|
213
|
-
Puppet::DSL::Context.expects(:new).with {|code, _| code == block}.returns context
|
214
|
-
evaluate_in_scope do
|
215
|
-
subject.create_hostclass(:foo, {}, 0, &block).ruby_code.should include context
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "#create_definition" do
|
221
|
-
it "raises NoMethodError when called from invalid nesting" do
|
222
|
-
lambda do
|
223
|
-
subject.create_definition :foo, {}, 1 do
|
224
|
-
end
|
225
|
-
end.should raise_error NoMethodError
|
226
|
-
end
|
227
|
-
|
228
|
-
it "raises ArgumentError when code is nil" do
|
229
|
-
lambda do
|
230
|
-
subject.create_definition :foo, {}, nil, 0
|
231
|
-
end.should raise_error ArgumentError
|
232
|
-
end
|
233
|
-
|
234
|
-
it "creates new definition" do
|
235
|
-
evaluate_in_scope do
|
236
|
-
subject.create_definition(:foo, {}, 0) {}.tap do |r|
|
237
|
-
r.should be_a Puppet::Resource::Type
|
238
|
-
r.type.should == :definition
|
239
|
-
r.name.should == "foo"
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
it "set options for the definition" do
|
246
|
-
evaluate_in_scope do
|
247
|
-
subject.create_definition(:foo, {:arguments => {:param => 42}}, 0) {}.arguments.should == {"param" => 42}
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
it "adds definition to known resource types" do
|
252
|
-
evaluate_in_scope do
|
253
|
-
resource_types = mock
|
254
|
-
resource_types.expects(:add_definition).with {|n| n.type == :definition }
|
255
|
-
Puppet::DSL::Parser.stubs(:known_resource_types).returns resource_types
|
256
|
-
|
257
|
-
subject.create_definition :foo, {}, 0 do
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
|
263
|
-
it "sets ruby code for definition" do
|
264
|
-
block = proc {}
|
265
|
-
context = mock "Context"
|
266
|
-
Puppet::DSL::Context.expects(:new).with {|code, _| code == block}.returns context
|
267
|
-
evaluate_in_scope do
|
268
|
-
subject.create_definition(:foo, {}, 0, &block).ruby_code.should include context
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
describe "#create_resource" do
|
274
|
-
it "raises NoMethodError when importing" do
|
275
|
-
scope = mock
|
276
|
-
scope.stubs(:nil?).returns true
|
277
|
-
scope.stubs(:known_resource_types).returns nil
|
278
|
-
evaluate_in_scope :scope => scope do
|
279
|
-
lambda { subject.create_resource :notify, "message", {}, nil }.should raise_error NoMethodError
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
it "creates the resource when the type exists" do
|
284
|
-
scope.compiler.expects(:add_resource).with { |s, r| s == scope and r.is_a? Puppet::Parser::Resource }
|
285
|
-
|
286
|
-
evaluate_in_scope do
|
287
|
-
subject.create_resource :notify, "foo", {}, nil
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
it "returns an array of created resources" do
|
292
|
-
evaluate_in_scope do
|
293
|
-
subject.create_resource(:notify, ["foo", "bar"], {}, nil).map(&:title).should == ["foo", "bar"]
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
it "sets the passed options to it" do
|
298
|
-
evaluate_in_scope do
|
299
|
-
resource = subject.create_resource(:file, "/tmp/test", {:ensure => :present, :mode => "0666"}, nil).first
|
300
|
-
resource[:ensure].should == "present"
|
301
|
-
resource[:mode].should == "0666"
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
it "evaluates options passed in block" do
|
306
|
-
evaluate_in_scope do
|
307
|
-
block = proc do |resource|
|
308
|
-
resource.ensure = :present
|
309
|
-
resource.mode = "0666"
|
310
|
-
end
|
311
|
-
|
312
|
-
resource = subject.create_resource(:file, "/tmp/foo", {}, block).first
|
313
|
-
resource[:ensure].should == "present"
|
314
|
-
resource[:mode].should == "0666"
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
context "when virtualizing" do
|
319
|
-
it "creates virtual resource when called from virtual scope" do
|
320
|
-
evaluate_in_scope do
|
321
|
-
subject.virtualizing = true
|
322
|
-
|
323
|
-
subject.create_resource(:notify, "foo", {}, nil).first.virtual.should be true
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
it "creates virtual resource when passed virtual option" do
|
328
|
-
evaluate_in_scope do
|
329
|
-
subject.create_resource(:notify, "foo", {:virtual => true}, nil).first.virtual.should be true
|
330
|
-
end
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
context "when exporting" do
|
335
|
-
it "creates exported resource when called from exporting scope" do
|
336
|
-
evaluate_in_scope do
|
337
|
-
subject.exporting = true
|
338
|
-
|
339
|
-
subject.create_resource(:notify, "foo", {}, nil).first.exported.should be true
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
it "creates exported resource when passed export option" do
|
344
|
-
evaluate_in_scope do
|
345
|
-
subject.create_resource(:notify, "foo", {:export => true}, nil).first.exported.should be true
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
describe "#call_function" do
|
352
|
-
it "raises NoMethodError when importing" do
|
353
|
-
scope = mock
|
354
|
-
scope.stubs(:nil?).returns true
|
355
|
-
scope.stubs(:known_resource_types).returns nil
|
356
|
-
evaluate_in_scope :scope => scope do
|
357
|
-
lambda { subject.call_function "notice", [] }.should raise_error NoMethodError
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
it "calls the function and passes the array of arguments when it exists" do
|
362
|
-
scope.expects(:notice).with(["foo", "bar"])
|
363
|
-
evaluate_in_scope do
|
364
|
-
subject.call_function "notice", ["foo", "bar"]
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
describe "#validate_options" do
|
370
|
-
let(:attributes) { {:foo => "bar"} }
|
371
|
-
|
372
|
-
it "raises ArgumentError when invalid options are passed" do
|
373
|
-
lambda do
|
374
|
-
subject.validate_options [:asdf], attributes
|
375
|
-
end.should raise_error ArgumentError
|
376
|
-
end
|
377
|
-
|
378
|
-
it "does nothing when all attributes are valid" do
|
379
|
-
lambda do
|
380
|
-
subject.validate_options [:foo], attributes
|
381
|
-
end.should_not raise_error ArgumentError
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
it "allows to read and set exporting setting" do
|
386
|
-
subject.exporting?.should be false
|
387
|
-
subject.exporting = true
|
388
|
-
subject.exporting?.should be true
|
389
|
-
subject.exporting = false
|
390
|
-
subject.exporting?.should be false
|
391
|
-
end
|
392
|
-
|
393
|
-
it "allows to read and set virtualizing setting" do
|
394
|
-
subject.virtualizing?.should be false
|
395
|
-
subject.virtualizing = true
|
396
|
-
subject.virtualizing?.should be true
|
397
|
-
subject.virtualizing = false
|
398
|
-
subject.virtualizing?.should be false
|
399
|
-
end
|
400
|
-
|
401
|
-
end
|
402
|
-
|