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
@@ -0,0 +1,53 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'puppet/dsl/resource_type_api'
|
5
|
+
|
6
|
+
describe Puppet::DSL::ResourceTypeAPI do
|
7
|
+
# Verify that the block creates a single AST node through the API,
|
8
|
+
# instantiate that AST node into a types, and return that type.
|
9
|
+
def test_api_call(&block)
|
10
|
+
main_object = Puppet::DSL::ResourceTypeAPI.new
|
11
|
+
main_object.instance_eval(&block)
|
12
|
+
created_ast_objects = main_object.instance_eval { @__created_ast_objects__ }
|
13
|
+
created_ast_objects.length.should == 1
|
14
|
+
new_types = created_ast_objects[0].instantiate('')
|
15
|
+
new_types.length.should == 1
|
16
|
+
new_types[0]
|
17
|
+
ensure
|
18
|
+
Thread.current[:ruby_file_parse_result] = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
[:definition, :node, :hostclass].each do |type|
|
22
|
+
method = type == :definition ? "define" : type
|
23
|
+
it "should be able to create a #{type}" do
|
24
|
+
newtype = test_api_call { send(method, "myname").should == nil }
|
25
|
+
newtype.should be_a(Puppet::Resource::Type)
|
26
|
+
newtype.type.should == type
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should use the provided name when creating a #{type}" do
|
30
|
+
newtype = test_api_call { send(method, "myname") }
|
31
|
+
newtype.name.should == "myname"
|
32
|
+
end
|
33
|
+
|
34
|
+
unless type == :definition
|
35
|
+
it "should pass in any provided options when creating a #{type}" do
|
36
|
+
newtype = test_api_call { send(method, "myname", :line => 200) }
|
37
|
+
newtype.line.should == 200
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set any provided block as the type's ruby code" do
|
42
|
+
newtype = test_api_call { send(method, "myname") { 'method_result' } }
|
43
|
+
newtype.ruby_code.call.should == 'method_result'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "when creating a definition" do
|
48
|
+
it "should use the provided options to define valid arguments for the resource type" do
|
49
|
+
newtype = test_api_call { define("myname", :arg1, :arg2) }
|
50
|
+
newtype.arguments.should == { 'arg1' => nil, 'arg2' => nil }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -152,93 +152,126 @@ TREE
|
|
152
152
|
TREE
|
153
153
|
end
|
154
154
|
end
|
155
|
+
|
155
156
|
describe '.set_option_defaults' do
|
156
|
-
|
157
|
-
|
157
|
+
describe 'option :environment' do
|
158
|
+
context 'passed:' do
|
159
|
+
let (:environment) { "ahgkduerh" }
|
160
|
+
let (:options) { {:environment => environment} }
|
158
161
|
|
159
|
-
|
160
|
-
|
161
|
-
let (:options) { {} }
|
162
|
+
it 'Puppet[:environment] should be set to the value of the option' do
|
163
|
+
subject.set_option_defaults options
|
162
164
|
|
163
|
-
|
164
|
-
options[value] = setting[value]
|
165
|
-
Puppet[value] = "bar"
|
165
|
+
Puppet[:environment].should == environment
|
166
166
|
end
|
167
167
|
|
168
|
-
it
|
168
|
+
it 'the option value should not be overridden' do
|
169
|
+
Puppet[:environment] = :foo
|
169
170
|
subject.set_option_defaults options
|
170
|
-
|
171
|
+
|
172
|
+
options[:environment].should == environment
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'NOT passed:' do
|
177
|
+
it 'Puppet[:environment] should NOT be overridden' do
|
178
|
+
Puppet[:environment] = :foo
|
179
|
+
|
180
|
+
subject.set_option_defaults({})
|
181
|
+
Puppet[:environment].should == :foo
|
171
182
|
end
|
172
183
|
|
173
|
-
it
|
184
|
+
it 'the option should be set to the value of Puppet[:environment]' do
|
185
|
+
options_to_modify = Hash.new
|
186
|
+
Puppet[:environment] = :abcdefg
|
187
|
+
|
188
|
+
subject.set_option_defaults options_to_modify
|
189
|
+
|
190
|
+
options_to_modify[:environment].should == :abcdefg
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'option :modulepath' do
|
196
|
+
context 'passed:' do
|
197
|
+
let (:modulepath) { PuppetSpec::Files.make_absolute('/bar') }
|
198
|
+
let (:options) { {:modulepath => modulepath} }
|
199
|
+
|
200
|
+
it 'Puppet[:modulepath] should be set to the value of the option' do
|
201
|
+
|
174
202
|
subject.set_option_defaults options
|
175
|
-
|
203
|
+
|
204
|
+
Puppet[:modulepath].should == modulepath
|
176
205
|
end
|
177
206
|
|
207
|
+
it 'the option value should not be overridden' do
|
208
|
+
Puppet[:modulepath] = "/foo"
|
209
|
+
|
210
|
+
subject.set_option_defaults options
|
211
|
+
|
212
|
+
options[:modulepath].should == modulepath
|
213
|
+
end
|
178
214
|
end
|
179
215
|
|
180
|
-
|
181
|
-
let (:options) { {} }
|
216
|
+
context 'NOT passed:' do
|
217
|
+
let (:options) { {:environment => :pmttestenv} }
|
182
218
|
|
183
219
|
before(:each) do
|
184
|
-
Puppet[
|
220
|
+
Puppet[:modulepath] = "/no"
|
221
|
+
Puppet[:environment] = :pmttestenv
|
222
|
+
Puppet.settings.set_value(:modulepath,
|
223
|
+
["/foo", "/bar", "/no"].join(File::PATH_SEPARATOR),
|
224
|
+
:pmttestenv)
|
185
225
|
end
|
186
226
|
|
187
|
-
it
|
227
|
+
it 'Puppet[:modulepath] should be reset to the module path of the current environment' do
|
188
228
|
subject.set_option_defaults options
|
189
|
-
|
229
|
+
|
230
|
+
Puppet[:modulepath].should == Puppet.settings.value(:modulepath, :pmttestenv)
|
190
231
|
end
|
191
232
|
|
192
|
-
it
|
233
|
+
it 'the option should be set to the module path of the current environment' do
|
193
234
|
subject.set_option_defaults options
|
194
|
-
|
235
|
+
|
236
|
+
options[:modulepath].should == Puppet.settings.value(:modulepath, :pmttestenv)
|
195
237
|
end
|
196
238
|
end
|
197
239
|
end
|
198
240
|
|
199
|
-
describe ':target_dir' do
|
200
|
-
let (:
|
241
|
+
describe 'option :target_dir' do
|
242
|
+
let (:target_dir) { 'boo' }
|
201
243
|
|
202
|
-
|
203
|
-
|
204
|
-
}
|
205
|
-
let (:options) { {:modulepath => my_fake_path}}
|
244
|
+
context 'passed:' do
|
245
|
+
let (:options) { {:target_dir => target_dir} }
|
206
246
|
|
207
|
-
|
247
|
+
it 'the option value should be prepended to the Puppet[:modulepath]' do
|
248
|
+
Puppet[:modulepath] = "/fuz"
|
249
|
+
original_modulepath = Puppet[:modulepath]
|
208
250
|
|
209
|
-
it "should set options[:target_dir]" do
|
210
251
|
subject.set_option_defaults options
|
211
|
-
|
252
|
+
|
253
|
+
Puppet[:modulepath].should == options[:target_dir] + File::PATH_SEPARATOR + original_modulepath
|
212
254
|
end
|
213
255
|
|
214
|
-
it
|
256
|
+
it 'the option value should be turned into an absolute path' do
|
215
257
|
subject.set_option_defaults options
|
216
|
-
options[:target_dir].should == my_fake_path.split(sep).first
|
217
|
-
end
|
218
|
-
end
|
219
258
|
|
220
|
-
|
221
|
-
let (:my_target_dir) { make_absolute("/foo/bar") }
|
222
|
-
before(:each) do
|
223
|
-
options[:target_dir] = my_target_dir
|
259
|
+
options[:target_dir].should == File.expand_path(target_dir)
|
224
260
|
end
|
261
|
+
end
|
225
262
|
|
226
|
-
|
227
|
-
|
228
|
-
|
263
|
+
describe 'NOT passed:' do
|
264
|
+
before :each do
|
265
|
+
Puppet[:modulepath] = 'foo' + File::PATH_SEPARATOR + 'bar'
|
229
266
|
end
|
230
267
|
|
231
|
-
it
|
268
|
+
it 'the option should be set to the first component of Puppet[:modulepath]' do
|
269
|
+
options = Hash.new
|
232
270
|
subject.set_option_defaults options
|
233
|
-
options[:modulepath].split(sep).first.should == my_target_dir
|
234
|
-
end
|
235
271
|
|
236
|
-
|
237
|
-
subject.set_option_defaults options
|
238
|
-
options[:modulepath].split(sep).drop(1).join(sep).should == my_fake_path
|
272
|
+
options[:target_dir].should == Puppet[:modulepath].split(File::PATH_SEPARATOR)[0]
|
239
273
|
end
|
240
274
|
end
|
241
|
-
|
242
275
|
end
|
243
276
|
end
|
244
277
|
end
|
@@ -311,6 +311,10 @@ describe "Puppet Network Format" do
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
314
|
+
it "should render empty hashes as empty strings" do
|
315
|
+
subject.render({}).should == ''
|
316
|
+
end
|
317
|
+
|
314
318
|
it "should render a non-trivially-keyed Hash as JSON" do
|
315
319
|
hash = { [1,2] => 3, [2,3] => 5, [3,4] => 7 }
|
316
320
|
subject.render(hash).should == json.render(hash).chomp
|
@@ -441,19 +441,6 @@ describe Puppet::Node::Environment do
|
|
441
441
|
env.instance_eval { perform_initial_import }
|
442
442
|
end
|
443
443
|
|
444
|
-
it "should not do anything when using ruby dsl" do
|
445
|
-
Puppet[:manifest] = "test.rb"
|
446
|
-
@parser.expects(:parse).never
|
447
|
-
env.instance_eval { perform_initial_import }
|
448
|
-
end
|
449
|
-
|
450
|
-
it "returns empty hostclass when using Ruby DSL" do
|
451
|
-
Puppet[:manifest] = "test.rb"
|
452
|
-
env.instance_eval { perform_initial_import }.tap {|c|
|
453
|
-
c.should be_a Puppet::Parser::AST::Hostclass
|
454
|
-
}.code.should be nil
|
455
|
-
end
|
456
|
-
|
457
444
|
it "should mark the type collection as needing a reparse when there is an error parsing" do
|
458
445
|
@parser.expects(:parse).raises Puppet::ParseError.new("Syntax error at ...")
|
459
446
|
env.stubs(:known_resource_types).returns Puppet::Resource::TypeCollection.new(env)
|
@@ -247,32 +247,6 @@ describe Puppet::Parser::Compiler do
|
|
247
247
|
@compiler.compile
|
248
248
|
end
|
249
249
|
|
250
|
-
it "should evaluate ruby code on main object when using ruby dsl" do
|
251
|
-
compile_stub(:evaluate_main)
|
252
|
-
Puppet::Util::ManifestFiletypeHelper.expects(:is_ruby_filename?).at_least_once.returns true
|
253
|
-
@compiler.expects :assign_ruby_code
|
254
|
-
|
255
|
-
@compiler.compile
|
256
|
-
end
|
257
|
-
|
258
|
-
it "should create a new Puppet::DSL::Parser when using ruby dsl" do
|
259
|
-
compile_stub(:evaluate_main)
|
260
|
-
File.stubs(:read).returns("test code")
|
261
|
-
Puppet[:manifest] = "test.rb"
|
262
|
-
Puppet::DSL::Parser.expects(:prepare_for_evaluation).with {|main, code, filename| code == "test code" and main.is_a? Puppet::Resource::Type}.returns stub(:evaluate)
|
263
|
-
|
264
|
-
@compiler.compile
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should call evaluate on DSL Parser instance when using ruby dsl" do
|
268
|
-
compile_stub(:evaluate_main)
|
269
|
-
Puppet::Util::ManifestFiletypeHelper.expects(:is_ruby_filename?).at_least_once.returns true
|
270
|
-
File.stubs(:read).returns("")
|
271
|
-
Puppet::DSL::Parser.expects :prepare_for_evaluation
|
272
|
-
|
273
|
-
@compiler.compile
|
274
|
-
end
|
275
|
-
|
276
250
|
it "should create a new, empty 'main' if no main class exists" do
|
277
251
|
compile_stub(:evaluate_main)
|
278
252
|
@compiler.compile
|
@@ -49,6 +49,20 @@ describe Puppet::Parser do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
describe "when parsing files" do
|
53
|
+
before do
|
54
|
+
FileTest.stubs(:exist?).returns true
|
55
|
+
File.stubs(:read).returns ""
|
56
|
+
@parser.stubs(:watch_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should treat files ending in 'rb' as ruby files" do
|
60
|
+
@parser.expects(:parse_ruby_file)
|
61
|
+
@parser.file = "/my/file.rb"
|
62
|
+
@parser.parse
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
52
66
|
describe "when parsing append operator" do
|
53
67
|
|
54
68
|
it "should not raise syntax errors" do
|
@@ -11,6 +11,7 @@ describe Puppet::Parser::TypeLoader do
|
|
11
11
|
|
12
12
|
before do
|
13
13
|
@loader = Puppet::Parser::TypeLoader.new(:myenv)
|
14
|
+
Puppet.expects(:deprecation_warning).never
|
14
15
|
end
|
15
16
|
|
16
17
|
it "should support an environment" do
|
@@ -92,20 +93,6 @@ describe Puppet::Parser::TypeLoader do
|
|
92
93
|
# This will fail if it tries to reimport the file.
|
93
94
|
@loader.import("myfile")
|
94
95
|
end
|
95
|
-
|
96
|
-
it "checks the type of DSL to import" do
|
97
|
-
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", [make_absolute("/one")]]
|
98
|
-
Puppet::Util::ManifestFiletypeHelper.expects(:is_ruby_filename?).at_least_once.returns false
|
99
|
-
|
100
|
-
@loader.import("myfile")
|
101
|
-
end
|
102
|
-
|
103
|
-
it "evaluates loaded Ruby code" do
|
104
|
-
File.stubs(:read).returns("hostclass(:asdf) {}")
|
105
|
-
Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", [make_absolute("/one.rb")]]
|
106
|
-
|
107
|
-
@loader.import("myfile").map(&:name).should include "asdf"
|
108
|
-
end
|
109
96
|
end
|
110
97
|
|
111
98
|
describe "when importing all" do
|
@@ -136,7 +123,7 @@ describe Puppet::Parser::TypeLoader do
|
|
136
123
|
|
137
124
|
# write out the class
|
138
125
|
if type == "ruby"
|
139
|
-
File.open(path, "w") { |f| f.print "hostclass
|
126
|
+
File.open(path, "w") { |f| f.print "hostclass '#{name}' do\nend" }
|
140
127
|
else
|
141
128
|
File.open(path, "w") { |f| f.print "class #{name} {}" }
|
142
129
|
end
|
@@ -160,6 +147,8 @@ describe Puppet::Parser::TypeLoader do
|
|
160
147
|
end
|
161
148
|
|
162
149
|
it "should load all ruby manifests from all modules in the specified environment" do
|
150
|
+
Puppet.expects(:deprecation_warning).at_least(1)
|
151
|
+
|
163
152
|
@module1 = mk_module(@modulebase1, "one")
|
164
153
|
@module2 = mk_module(@modulebase2, "two")
|
165
154
|
|
@@ -5,11 +5,36 @@ require 'stringio'
|
|
5
5
|
provider_class = Puppet::Type.type(:package).provider(:openbsd)
|
6
6
|
|
7
7
|
describe provider_class do
|
8
|
-
|
8
|
+
let(:package) { Puppet::Type.type(:package).new(:name => 'bash', :provider => 'openbsd') }
|
9
|
+
let(:provider) { provider_class.new(package) }
|
9
10
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
11
|
+
def expect_read_from_pkgconf(lines)
|
12
|
+
pkgconf = stub(:readlines => lines)
|
13
|
+
File.expects(:exist?).with('/etc/pkg.conf').returns(true)
|
14
|
+
File.expects(:open).with('/etc/pkg.conf', 'rb').returns(pkgconf)
|
15
|
+
end
|
16
|
+
|
17
|
+
def expect_pkgadd_with_source(source)
|
18
|
+
provider.expects(:pkgadd).with do |fullname|
|
19
|
+
ENV.should_not be_key 'PKG_PATH'
|
20
|
+
fullname.should == source
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def expect_pkgadd_with_env_and_name(source, &block)
|
25
|
+
ENV.should_not be_key 'PKG_PATH'
|
26
|
+
|
27
|
+
provider.expects(:pkgadd).with do |fullname|
|
28
|
+
ENV.should be_key 'PKG_PATH'
|
29
|
+
ENV['PKG_PATH'].should == source
|
30
|
+
|
31
|
+
fullname.should == provider.resource[:name]
|
32
|
+
end
|
33
|
+
provider.expects(:execpipe).with(['/bin/pkg_info', '-I', provider.resource[:name]]).yields('')
|
34
|
+
|
35
|
+
yield
|
36
|
+
|
37
|
+
ENV.should_not be_key 'PKG_PATH'
|
13
38
|
end
|
14
39
|
|
15
40
|
before :each do
|
@@ -22,78 +47,167 @@ describe provider_class do
|
|
22
47
|
|
23
48
|
context "::instances" do
|
24
49
|
it "should return nil if execution failed" do
|
25
|
-
|
26
|
-
|
50
|
+
provider_class.expects(:execpipe).raises(Puppet::ExecutionFailure, 'wawawa')
|
51
|
+
provider_class.instances.should be_nil
|
27
52
|
end
|
28
53
|
|
29
54
|
it "should return the empty set if no packages are listed" do
|
30
|
-
|
31
|
-
|
55
|
+
provider_class.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields(StringIO.new(''))
|
56
|
+
provider_class.instances.should be_empty
|
32
57
|
end
|
33
58
|
|
34
59
|
it "should return all packages when invoked" do
|
35
60
|
fixture = File.read(my_fixture('pkginfo.list'))
|
36
|
-
|
37
|
-
|
61
|
+
provider_class.expects(:execpipe).with(%w{/bin/pkg_info -a}).yields(fixture)
|
62
|
+
provider_class.instances.map(&:name).sort.should ==
|
38
63
|
%w{bash bzip2 expat gettext libiconv lzo openvpn python vim wget}.sort
|
39
64
|
end
|
40
65
|
end
|
41
66
|
|
42
67
|
context "#install" do
|
43
68
|
it "should fail if the resource doesn't have a source" do
|
44
|
-
|
45
|
-
|
46
|
-
|
69
|
+
File.expects(:exist?).with('/etc/pkg.conf').returns(false)
|
70
|
+
|
71
|
+
expect {
|
72
|
+
provider.install
|
73
|
+
}.to raise_error Puppet::Error, /must specify a package source/
|
47
74
|
end
|
48
75
|
|
49
|
-
it "should
|
50
|
-
|
76
|
+
it "should fail if /etc/pkg.conf exists, but is not readable" do
|
77
|
+
File.expects(:exist?).with('/etc/pkg.conf').returns(true)
|
78
|
+
File.expects(:open).with('/etc/pkg.conf', 'rb').raises(Errno::EACCES)
|
51
79
|
|
80
|
+
expect {
|
81
|
+
provider.install
|
82
|
+
}.to raise_error Errno::EACCES, /Permission denied/
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should fail if /etc/pkg.conf exists, but there is no installpath" do
|
86
|
+
expect_read_from_pkgconf([])
|
87
|
+
expect {
|
88
|
+
provider.install
|
89
|
+
}.to raise_error Puppet::Error, /No valid installpath found in \/etc\/pkg\.conf and no source was set/
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should install correctly when given a directory-unlike source" do
|
52
93
|
source = '/whatever.pkg'
|
53
|
-
provider
|
54
|
-
|
55
|
-
ENV.should_not be_key 'PKG_PATH'
|
56
|
-
name == source
|
57
|
-
end
|
94
|
+
provider.resource[:source] = source
|
95
|
+
expect_pkgadd_with_source(source)
|
58
96
|
|
59
97
|
provider.install
|
60
|
-
ENV.should_not be_key 'PKG_PATH'
|
61
98
|
end
|
62
99
|
|
63
100
|
it "should install correctly when given a directory-like source" do
|
64
|
-
ENV.should_not be_key 'PKG_PATH'
|
65
|
-
|
66
101
|
source = '/whatever/'
|
67
|
-
provider
|
68
|
-
|
69
|
-
|
70
|
-
|
102
|
+
provider.resource[:source] = source
|
103
|
+
expect_pkgadd_with_env_and_name(source) do
|
104
|
+
provider.install
|
105
|
+
end
|
106
|
+
end
|
71
107
|
|
72
|
-
|
108
|
+
it "should install correctly when given a CDROM installpath" do
|
109
|
+
dir = '/mnt/cdrom/5.2/packages/amd64/'
|
110
|
+
expect_read_from_pkgconf(["installpath = #{dir}"])
|
111
|
+
expect_pkgadd_with_env_and_name(dir) do
|
112
|
+
provider.install
|
73
113
|
end
|
74
|
-
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should install correctly when given a ftp mirror" do
|
117
|
+
url = 'ftp://your.ftp.mirror/pub/OpenBSD/5.2/packages/amd64/'
|
118
|
+
expect_read_from_pkgconf(["installpath = #{url}"])
|
119
|
+
expect_pkgadd_with_env_and_name(url) do
|
120
|
+
provider.install
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should set the resource's source parameter" do
|
125
|
+
url = 'ftp://your.ftp.mirror/pub/OpenBSD/5.2/packages/amd64/'
|
126
|
+
expect_read_from_pkgconf(["installpath = #{url}"])
|
127
|
+
expect_pkgadd_with_env_and_name(url) do
|
128
|
+
provider.install
|
129
|
+
end
|
130
|
+
|
131
|
+
provider.resource[:source].should == url
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should strip leading whitespace in installpath" do
|
135
|
+
dir = '/one/'
|
136
|
+
lines = ["# Notice the extra spaces after the ='s\n",
|
137
|
+
"installpath = #{dir}\n",
|
138
|
+
"# And notice how each line ends with a newline\n"]
|
139
|
+
|
140
|
+
expect_read_from_pkgconf(lines)
|
141
|
+
expect_pkgadd_with_env_and_name(dir) do
|
142
|
+
provider.install
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should not require spaces around the equals" do
|
147
|
+
dir = '/one/'
|
148
|
+
lines = ["installpath=#{dir}"]
|
149
|
+
|
150
|
+
expect_read_from_pkgconf(lines)
|
151
|
+
expect_pkgadd_with_env_and_name(dir) do
|
152
|
+
provider.install
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should be case-insensitive" do
|
157
|
+
dir = '/one/'
|
158
|
+
lines = ["INSTALLPATH = #{dir}"]
|
159
|
+
|
160
|
+
expect_read_from_pkgconf(lines)
|
161
|
+
expect_pkgadd_with_env_and_name(dir) do
|
162
|
+
provider.install
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should ignore unknown keywords" do
|
167
|
+
dir = '/one/'
|
168
|
+
lines = ["foo = bar\n",
|
169
|
+
"installpath = #{dir}\n"]
|
170
|
+
|
171
|
+
expect_read_from_pkgconf(lines)
|
172
|
+
expect_pkgadd_with_env_and_name(dir) do
|
173
|
+
provider.install
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should preserve trailing spaces" do
|
178
|
+
dir = '/one/ '
|
179
|
+
lines = ["installpath = #{dir}"]
|
180
|
+
|
181
|
+
expect_read_from_pkgconf(lines)
|
182
|
+
expect_pkgadd_with_source(dir)
|
75
183
|
|
76
184
|
provider.install
|
77
|
-
|
185
|
+
end
|
186
|
+
|
187
|
+
%w{ installpath installpath= }.each do |line|
|
188
|
+
it "should reject '#{line}'" do
|
189
|
+
expect_read_from_pkgconf([line])
|
190
|
+
expect {
|
191
|
+
provider.install
|
192
|
+
}.to raise_error(Puppet::Error, /No valid installpath found in \/etc\/pkg\.conf and no source was set/)
|
193
|
+
end
|
78
194
|
end
|
79
195
|
end
|
80
196
|
|
81
197
|
context "#get_version" do
|
82
198
|
it "should return nil if execution fails" do
|
83
|
-
provider = subject.new(package)
|
84
199
|
provider.expects(:execpipe).raises(Puppet::ExecutionFailure, 'wawawa')
|
85
200
|
provider.get_version.should be_nil
|
86
201
|
end
|
87
202
|
|
88
203
|
it "should return the package version if in the output" do
|
89
204
|
fixture = File.read(my_fixture('pkginfo.list'))
|
90
|
-
provider = subject.new(package(:name => 'bash'))
|
91
205
|
provider.expects(:execpipe).with(%w{/bin/pkg_info -I bash}).yields(fixture)
|
92
206
|
provider.get_version.should == '3.1.17'
|
93
207
|
end
|
94
208
|
|
95
209
|
it "should return the empty string if the package is not present" do
|
96
|
-
provider
|
210
|
+
provider.resource[:name] = 'zsh'
|
97
211
|
provider.expects(:execpipe).with(%w{/bin/pkg_info -I zsh}).yields(StringIO.new(''))
|
98
212
|
provider.get_version.should == ''
|
99
213
|
end
|
@@ -102,13 +216,12 @@ describe provider_class do
|
|
102
216
|
context "#query" do
|
103
217
|
it "should return the installed version if present" do
|
104
218
|
fixture = File.read(my_fixture('pkginfo.detail'))
|
105
|
-
provider = subject.new(package(:name => 'bash'))
|
106
219
|
provider.expects(:pkginfo).with('bash').returns(fixture)
|
107
220
|
provider.query.should == { :ensure => '3.1.17' }
|
108
221
|
end
|
109
222
|
|
110
223
|
it "should return nothing if not present" do
|
111
|
-
provider
|
224
|
+
provider.resource[:name] = 'zsh'
|
112
225
|
provider.expects(:pkginfo).with('zsh').returns('')
|
113
226
|
provider.query.should be_nil
|
114
227
|
end
|