puppet 2.7.1 → 2.7.3
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/CHANGELOG +225 -1
- data/CONTRIBUTING.md +299 -0
- data/README.md +0 -1
- data/conf/redhat/puppet.spec +132 -25
- data/conf/solaris/pkginfo +1 -1
- data/conf/suse/puppet.spec +5 -2
- data/ext/envpuppet +56 -3
- data/ext/vim/README +2 -1
- data/ext/vim/ftplugin/puppet.vim +94 -0
- data/ext/vim/indent/puppet.vim +76 -0
- data/lib/puppet.rb +2 -3
- data/lib/puppet/application/agent.rb +7 -7
- data/lib/puppet/application/apply.rb +20 -8
- data/lib/puppet/application/ca.rb +5 -0
- data/lib/puppet/application/cert.rb +2 -1
- data/lib/puppet/application/certificate.rb +0 -5
- data/lib/puppet/application/device.rb +4 -4
- data/lib/puppet/application/doc.rb +23 -12
- data/lib/puppet/application/face_base.rb +2 -1
- data/lib/puppet/application/inspect.rb +5 -2
- data/lib/puppet/configurer.rb +60 -56
- data/lib/puppet/configurer/fact_handler.rb +6 -1
- data/lib/puppet/defaults.rb +20 -1
- data/lib/puppet/face/ca.rb +233 -0
- data/lib/puppet/face/certificate.rb +15 -11
- data/lib/puppet/face/certificate_request.rb +9 -11
- data/lib/puppet/face/certificate_revocation_list.rb +5 -7
- data/lib/puppet/face/node/clean.rb +154 -0
- data/lib/puppet/face/status.rb +1 -0
- data/lib/puppet/file_serving/configuration/parser.rb +6 -13
- data/lib/puppet/indirector/exec.rb +3 -3
- data/lib/puppet/indirector/face.rb +17 -7
- data/lib/puppet/indirector/report/processor.rb +29 -16
- data/lib/puppet/indirector/rest.rb +42 -7
- data/lib/puppet/indirector/yaml.rb +5 -0
- data/lib/puppet/interface.rb +7 -2
- data/lib/puppet/interface/action.rb +57 -23
- data/lib/puppet/interface/action_manager.rb +10 -5
- data/lib/puppet/interface/face_collection.rb +43 -52
- data/lib/puppet/interface/option.rb +19 -0
- data/lib/puppet/interface/option_builder.rb +13 -0
- data/lib/puppet/interface/option_manager.rb +2 -1
- data/lib/puppet/metatype/manager.rb +7 -20
- data/lib/puppet/module.rb +4 -1
- data/lib/puppet/network/authconfig.rb +3 -1
- data/lib/puppet/network/authstore.rb +14 -5
- data/lib/puppet/network/handler/fileserver.rb +3 -0
- data/lib/puppet/network/http/webrick.rb +1 -1
- data/lib/puppet/network/rest_authconfig.rb +6 -1
- data/lib/puppet/network/rest_authorization.rb +1 -1
- data/lib/puppet/parser/compiler.rb +8 -11
- data/lib/puppet/parser/functions.rb +1 -6
- data/lib/puppet/parser/functions/create_resources.rb +6 -5
- data/lib/puppet/parser/functions/regsubst.rb +26 -0
- data/lib/puppet/parser/functions/shellquote.rb +26 -0
- data/lib/puppet/parser/functions/sprintf.rb +26 -0
- data/lib/puppet/parser/grammar.ra +34 -60
- data/lib/puppet/parser/lexer.rb +5 -5
- data/lib/puppet/parser/parser.rb +913 -1196
- data/lib/puppet/parser/resource.rb +18 -1
- data/lib/puppet/parser/scope.rb +2 -2
- data/lib/puppet/provider/augeas/augeas.rb +42 -17
- data/lib/puppet/provider/mount/parsed.rb +19 -1
- data/lib/puppet/provider/naginator.rb +9 -1
- data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
- data/lib/puppet/provider/network_device.rb +1 -1
- data/lib/puppet/provider/package/aptitude.rb +1 -0
- data/lib/puppet/provider/package/pacman.rb +94 -0
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
- data/lib/puppet/rails/host.rb +7 -0
- data/lib/puppet/reports/store.rb +15 -0
- data/lib/puppet/resource/catalog.rb +15 -6
- data/lib/puppet/ssl/certificate.rb +6 -0
- data/lib/puppet/ssl/inventory.rb +2 -0
- data/lib/puppet/transaction.rb +9 -17
- data/lib/puppet/transaction/report.rb +3 -3
- data/lib/puppet/type.rb +13 -24
- data/lib/puppet/type/file.rb +8 -2
- data/lib/puppet/type/file/source.rb +2 -2
- data/lib/puppet/type/service.rb +20 -24
- data/lib/puppet/type/ssh_authorized_key.rb +12 -0
- data/lib/puppet/type/user.rb +8 -0
- data/lib/puppet/util.rb +0 -1
- data/lib/puppet/util/network_device.rb +3 -3
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/settings/file_setting.rb +1 -0
- data/lib/semver.rb +65 -0
- data/spec/integration/defaults_spec.rb +23 -1
- data/spec/integration/network/rest_authconfig_spec.rb +145 -0
- data/spec/integration/node/facts_spec.rb +1 -1
- data/spec/integration/parser/functions_spec.rb +1 -1
- data/spec/integration/parser/parser_spec.rb +31 -0
- data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
- data/spec/integration/type_spec.rb +11 -0
- data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
- data/spec/lib/puppet/face/huzzah.rb +1 -0
- data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
- data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
- data/spec/unit/application/agent_spec.rb +2 -2
- data/spec/unit/application/apply_spec.rb +74 -56
- data/spec/unit/application/cert_spec.rb +10 -0
- data/spec/unit/application/device_spec.rb +2 -3
- data/spec/unit/application/face_base_spec.rb +1 -0
- data/spec/unit/application/facts_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +5 -0
- data/spec/unit/configurer/fact_handler_spec.rb +45 -37
- data/spec/unit/configurer_spec.rb +405 -327
- data/spec/unit/face/ca_spec.rb +355 -0
- data/spec/unit/face/certificate_spec.rb +16 -4
- data/spec/unit/face/node_spec.rb +261 -1
- data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
- data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
- data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
- data/spec/unit/indirector/exec_spec.rb +4 -4
- data/spec/unit/indirector/face_spec.rb +3 -1
- data/spec/unit/indirector/facts/couch_spec.rb +2 -2
- data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
- data/spec/unit/indirector/node/exec_spec.rb +1 -1
- data/spec/unit/indirector/report/processor_spec.rb +31 -8
- data/spec/unit/indirector/rest_spec.rb +53 -5
- data/spec/unit/indirector/yaml_spec.rb +18 -0
- data/spec/unit/interface/action_spec.rb +112 -8
- data/spec/unit/interface/face_collection_spec.rb +46 -36
- data/spec/unit/interface/option_spec.rb +44 -0
- data/spec/unit/interface_spec.rb +11 -6
- data/spec/unit/module_spec.rb +38 -9
- data/spec/unit/network/authconfig_spec.rb +23 -0
- data/spec/unit/network/authstore_spec.rb +36 -4
- data/spec/unit/network/handler/fileserver_spec.rb +32 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/node_spec.rb +1 -0
- data/spec/unit/parser/compiler_spec.rb +8 -46
- data/spec/unit/parser/lexer_spec.rb +27 -17
- data/spec/unit/parser/resource_spec.rb +61 -3
- data/spec/unit/parser/scope_spec.rb +5 -1
- data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
- data/spec/unit/provider/cisco_spec.rb +3 -4
- data/spec/unit/provider/interface/cisco_spec.rb +1 -2
- data/spec/unit/provider/mount/parsed_spec.rb +41 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
- data/spec/unit/provider/network_device_spec.rb +1 -2
- data/spec/unit/provider/package/pacman_spec.rb +237 -0
- data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
- data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
- data/spec/unit/rails/host_spec.rb +8 -0
- data/spec/unit/resource/catalog_spec.rb +55 -8
- data/spec/unit/semver_spec.rb +187 -0
- data/spec/unit/ssl/certificate_spec.rb +25 -0
- data/spec/unit/transaction/report_spec.rb +3 -3
- data/spec/unit/transaction_spec.rb +8 -2
- data/spec/unit/type/file_spec.rb +57 -0
- data/spec/unit/type/interface_spec.rb +1 -2
- data/spec/unit/type/schedule_spec.rb +73 -42
- data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
- data/spec/unit/type/user_spec.rb +8 -0
- data/spec/unit/type/vlan_spec.rb +1 -2
- data/spec/unit/type_spec.rb +66 -0
- data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
- data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
- data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
- data/spec/unit/util/network_device/config_spec.rb +3 -4
- data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
- data/spec/unit/util/network_device_spec.rb +2 -2
- data/spec/unit/util/settings/file_setting_spec.rb +4 -0
- data/spec/unit/util/settings_spec.rb +11 -0
- data/test/lib/puppettest/railstesting.rb +0 -34
- metadata +19 -4
@@ -118,6 +118,14 @@ describe Puppet::FileServing::Configuration::Parser do
|
|
118
118
|
@parser.parse
|
119
119
|
end
|
120
120
|
|
121
|
+
it "should support inline comments" do
|
122
|
+
mock_file_content "[one]\nallow something \# will it work?\n"
|
123
|
+
|
124
|
+
@mount.expects(:info)
|
125
|
+
@mount.expects(:allow).with("something")
|
126
|
+
@parser.parse
|
127
|
+
end
|
128
|
+
|
121
129
|
it "should tell the mount to deny any deny values from the section" do
|
122
130
|
mock_file_content "[one]\ndeny something\n"
|
123
131
|
|
@@ -47,6 +47,7 @@ rn/G
|
|
47
47
|
response = stub 'response', :code => "200", :body => cert_string
|
48
48
|
response.stubs(:[]).with('content-type').returns "text/plain"
|
49
49
|
response.stubs(:[]).with('content-encoding')
|
50
|
+
network.stubs(:verify_callback=)
|
50
51
|
network.expects(:get).returns response
|
51
52
|
|
52
53
|
request = Puppet::Indirector::Request.new(:certificate, :find, "foo.com")
|
@@ -7,6 +7,10 @@ require 'tempfile'
|
|
7
7
|
describe "Puppet::Indirector::CertificateStatus::File" do
|
8
8
|
include PuppetSpec::Files
|
9
9
|
|
10
|
+
before :all do
|
11
|
+
Puppet::SSL::Host.configure_indirection(:file)
|
12
|
+
end
|
13
|
+
|
10
14
|
before do
|
11
15
|
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns true
|
12
16
|
@terminus = Puppet::SSL::Host.indirection.terminus(:file)
|
@@ -32,22 +32,22 @@ describe Puppet::Indirector::Exec do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should execute the command with the object name as the only argument" do
|
35
|
-
@searcher.expects(:execute).with(%w{/echo foo})
|
35
|
+
@searcher.expects(:execute).with(%w{/echo foo}, :combine => false)
|
36
36
|
@searcher.find(@request)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should return the output of the script" do
|
40
|
-
@searcher.expects(:execute).with(%w{/echo foo}).returns("whatever")
|
40
|
+
@searcher.expects(:execute).with(%w{/echo foo}, :combine => false).returns("whatever")
|
41
41
|
@searcher.find(@request).should == "whatever"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should return nil when the command produces no output" do
|
45
|
-
@searcher.expects(:execute).with(%w{/echo foo}).returns(nil)
|
45
|
+
@searcher.expects(:execute).with(%w{/echo foo}, :combine => false).returns(nil)
|
46
46
|
@searcher.find(@request).should be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should raise an exception if there's an execution failure" do
|
50
|
-
@searcher.expects(:execute).with(%w{/echo foo}).raises(Puppet::ExecutionFailure.new("message"))
|
50
|
+
@searcher.expects(:execute).with(%w{/echo foo}, :combine => false).raises(Puppet::ExecutionFailure.new("message"))
|
51
51
|
|
52
52
|
lambda {@searcher.find(@request)}.should raise_exception(Puppet::Error, 'Failed to find foo via exec: message')
|
53
53
|
end
|
@@ -12,6 +12,8 @@ describe Puppet::Indirector::Face do
|
|
12
12
|
instance
|
13
13
|
end
|
14
14
|
|
15
|
+
it { should be_option :extra }
|
16
|
+
|
15
17
|
it "should be able to return a list of indirections" do
|
16
18
|
Puppet::Indirector::Face.indirections.should be_include("catalog")
|
17
19
|
end
|
@@ -48,7 +50,7 @@ describe Puppet::Indirector::Face do
|
|
48
50
|
end
|
49
51
|
it "should forward passed options" do
|
50
52
|
subject.indirection.expects(method).with(:test, {'one'=>'1'})
|
51
|
-
subject.send(method, :test, {'one'=>'1'})
|
53
|
+
subject.send(method, :test, :extra => {'one'=>'1'})
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
@@ -4,9 +4,9 @@ require 'spec_helper'
|
|
4
4
|
require 'puppet/node/facts'
|
5
5
|
require 'puppet/indirector/facts/couch'
|
6
6
|
|
7
|
-
describe "Puppet::Node::Facts::Couch" do
|
7
|
+
describe "Puppet::Node::Facts::Couch", :'fails_on_ruby_1.9.2' => true do
|
8
8
|
describe "when couchdb is not available", :unless => Puppet.features.couchdb? do
|
9
|
-
it "should fail to initialize"
|
9
|
+
it "should fail to initialize" do
|
10
10
|
lambda { Puppet::Node::Facts::Couch.new }.should raise_error
|
11
11
|
end
|
12
12
|
end
|
@@ -1,9 +1,5 @@
|
|
1
|
-
#!/usr/bin/env
|
2
|
-
|
3
|
-
# Created by Luke Kanies on 2007-9-23.
|
4
|
-
# Copyright (c) 2007. All rights reserved.
|
5
|
-
|
6
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
require 'spec_helper'
|
7
3
|
|
8
4
|
require 'puppet/indirector/facts/network_device'
|
9
5
|
|
@@ -31,7 +31,7 @@ describe Puppet::Node::Exec do
|
|
31
31
|
@result = {}
|
32
32
|
# Use a local variable so the reference is usable in the execute definition.
|
33
33
|
result = @result
|
34
|
-
@searcher.meta_def(:execute) do |command|
|
34
|
+
@searcher.meta_def(:execute) do |command, arguments|
|
35
35
|
return YAML.dump(result)
|
36
36
|
end
|
37
37
|
|
@@ -15,39 +15,62 @@ describe Puppet::Transaction::Report::Processor do
|
|
15
15
|
it "should provide a method for saving reports" do
|
16
16
|
Puppet::Transaction::Report::Processor.new.should respond_to(:save)
|
17
17
|
end
|
18
|
+
|
19
|
+
it "should provide a method for cleaning reports" do
|
20
|
+
Puppet::Transaction::Report::Processor.new.should respond_to(:destroy)
|
21
|
+
end
|
22
|
+
|
18
23
|
end
|
19
24
|
|
20
|
-
describe Puppet::Transaction::Report::Processor, " when
|
25
|
+
describe Puppet::Transaction::Report::Processor, " when processing a report" do
|
21
26
|
before do
|
22
27
|
Puppet.settings.stubs(:use)
|
23
28
|
@reporter = Puppet::Transaction::Report::Processor.new
|
29
|
+
@request = stub 'request', :instance => stub("report", :host => 'hostname'), :key => 'node'
|
24
30
|
end
|
25
31
|
|
26
|
-
it "should not
|
32
|
+
it "should not save the report if reports are set to 'none'" do
|
27
33
|
Puppet::Reports.expects(:report).never
|
28
|
-
Puppet
|
34
|
+
Puppet[:reports] = 'none'
|
29
35
|
|
30
|
-
request =
|
36
|
+
request = Puppet::Indirector::Request.new(:indirection_name, :head, "key")
|
37
|
+
report = Puppet::Transaction::Report.new('apply')
|
38
|
+
request.instance = report
|
31
39
|
|
32
40
|
@reporter.save(request)
|
33
41
|
end
|
34
42
|
|
35
|
-
it "should
|
43
|
+
it "should save the report with each configured report type" do
|
36
44
|
Puppet.settings.stubs(:value).with(:reports).returns("one,two")
|
37
45
|
@reporter.send(:reports).should == %w{one two}
|
46
|
+
|
47
|
+
Puppet::Reports.expects(:report).with('one')
|
48
|
+
Puppet::Reports.expects(:report).with('two')
|
49
|
+
|
50
|
+
@reporter.save(@request)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should destroy reports for each processor that responds to destroy" do
|
54
|
+
Puppet.settings.stubs(:value).with(:reports).returns("http,store")
|
55
|
+
http_report = mock()
|
56
|
+
store_report = mock()
|
57
|
+
store_report.expects(:destroy).with(@request.key)
|
58
|
+
Puppet::Reports.expects(:report).with('http').returns(http_report)
|
59
|
+
Puppet::Reports.expects(:report).with('store').returns(store_report)
|
60
|
+
@reporter.destroy(@request)
|
38
61
|
end
|
39
62
|
end
|
40
63
|
|
41
64
|
describe Puppet::Transaction::Report::Processor, " when processing a report" do
|
42
65
|
before do
|
43
|
-
Puppet
|
66
|
+
Puppet[:reports] = "one"
|
44
67
|
Puppet.settings.stubs(:use)
|
45
68
|
@reporter = Puppet::Transaction::Report::Processor.new
|
46
69
|
|
47
70
|
@report_type = mock 'one'
|
48
71
|
@dup_report = mock 'dupe report'
|
49
72
|
@dup_report.stubs(:process)
|
50
|
-
@report =
|
73
|
+
@report = Puppet::Transaction::Report.new('apply')
|
51
74
|
@report.expects(:dup).returns(@dup_report)
|
52
75
|
|
53
76
|
@request = stub 'request', :instance => @report
|
@@ -74,7 +97,7 @@ describe Puppet::Transaction::Report::Processor, " when processing a report" do
|
|
74
97
|
end
|
75
98
|
|
76
99
|
it "should not raise exceptions" do
|
77
|
-
Puppet
|
100
|
+
Puppet[:trace] = false
|
78
101
|
@dup_report.expects(:process).raises(ArgumentError)
|
79
102
|
proc { @reporter.save(@request) }.should_not raise_error
|
80
103
|
end
|
@@ -90,6 +90,54 @@ describe Puppet::Indirector::REST do
|
|
90
90
|
@rest_class.port.should == 543
|
91
91
|
end
|
92
92
|
|
93
|
+
describe "when making http requests" do
|
94
|
+
it "should provide a suggestive error message when certificate verify failed" do
|
95
|
+
connection = Net::HTTP.new('my_server', 8140)
|
96
|
+
@searcher.stubs(:network).returns(connection)
|
97
|
+
|
98
|
+
connection.stubs(:get).raises(OpenSSL::SSL::SSLError.new('certificate verify failed'))
|
99
|
+
|
100
|
+
expect do
|
101
|
+
@searcher.http_request(:get, stub('request'))
|
102
|
+
end.to raise_error(/This is often because the time is out of sync on the server or client/)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should provide a helpful error message when hostname was not match with server certificate" do
|
106
|
+
Puppet[:certdnsnames] = 'foo:bar:baz'
|
107
|
+
csr = OpenSSL::X509::Request.new
|
108
|
+
csr.subject = OpenSSL::X509::Name.new([['CN', 'not_my_server']])
|
109
|
+
csr.public_key = OpenSSL::PKey::RSA.generate(Puppet[:keylength]).public_key
|
110
|
+
cert = Puppet::SSL::CertificateFactory.new('server', csr, csr, 14).result
|
111
|
+
|
112
|
+
connection = Net::HTTP.new('my_server', 8140)
|
113
|
+
@searcher.stubs(:network).returns(connection)
|
114
|
+
ssl_context = OpenSSL::SSL::SSLContext.new
|
115
|
+
ssl_context.stubs(:current_cert).returns(cert)
|
116
|
+
connection.stubs(:get).with do
|
117
|
+
connection.verify_callback.call(true, ssl_context)
|
118
|
+
end.raises(OpenSSL::SSL::SSLError.new('hostname was not match with server certificate'))
|
119
|
+
|
120
|
+
msg = /Server hostname 'my_server' did not match server certificate; expected one of (.+)/
|
121
|
+
expect { @searcher.http_request(:get, stub('request')) }.to(
|
122
|
+
raise_error(Puppet::Error, msg) do |error|
|
123
|
+
error.message =~ msg
|
124
|
+
$1.split(', ').should =~ ['foo', 'bar', 'baz', 'not_my_server']
|
125
|
+
end
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should pass along the error message otherwise" do
|
130
|
+
connection = Net::HTTP.new('my_server', 8140)
|
131
|
+
@searcher.stubs(:network).returns(connection)
|
132
|
+
|
133
|
+
connection.stubs(:get).raises(OpenSSL::SSL::SSLError.new('some other message'))
|
134
|
+
|
135
|
+
expect do
|
136
|
+
@searcher.http_request(:get, stub('request'))
|
137
|
+
end.to raise_error(/some other message/)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
93
141
|
describe "when deserializing responses" do
|
94
142
|
it "should return nil if the response code is 404" do
|
95
143
|
response = mock 'response'
|
@@ -219,7 +267,7 @@ describe Puppet::Indirector::REST do
|
|
219
267
|
|
220
268
|
describe "when doing a find" do
|
221
269
|
before :each do
|
222
|
-
@connection = stub('mock http connection', :get => @response)
|
270
|
+
@connection = stub('mock http connection', :get => @response, :verify_callback= => nil)
|
223
271
|
@searcher.stubs(:network).returns(@connection) # neuter the network connection
|
224
272
|
|
225
273
|
# Use a key with spaces, so we can test escaping
|
@@ -313,7 +361,7 @@ describe Puppet::Indirector::REST do
|
|
313
361
|
|
314
362
|
describe "when doing a head" do
|
315
363
|
before :each do
|
316
|
-
@connection = stub('mock http connection', :head => @response)
|
364
|
+
@connection = stub('mock http connection', :head => @response, :verify_callback= => nil)
|
317
365
|
@searcher.stubs(:network).returns(@connection)
|
318
366
|
|
319
367
|
# Use a key with spaces, so we can test escaping
|
@@ -349,7 +397,7 @@ describe Puppet::Indirector::REST do
|
|
349
397
|
|
350
398
|
describe "when doing a search" do
|
351
399
|
before :each do
|
352
|
-
@connection = stub('mock http connection', :get => @response)
|
400
|
+
@connection = stub('mock http connection', :get => @response, :verify_callback= => nil)
|
353
401
|
@searcher.stubs(:network).returns(@connection) # neuter the network connection
|
354
402
|
|
355
403
|
@model.stubs(:convert_from_multiple)
|
@@ -397,7 +445,7 @@ describe Puppet::Indirector::REST do
|
|
397
445
|
|
398
446
|
describe "when doing a destroy" do
|
399
447
|
before :each do
|
400
|
-
@connection = stub('mock http connection', :delete => @response)
|
448
|
+
@connection = stub('mock http connection', :delete => @response, :verify_callback= => nil)
|
401
449
|
@searcher.stubs(:network).returns(@connection) # neuter the network connection
|
402
450
|
|
403
451
|
@request = Puppet::Indirector::Request.new(:foo, :destroy, "foo bar")
|
@@ -453,7 +501,7 @@ describe Puppet::Indirector::REST do
|
|
453
501
|
|
454
502
|
describe "when doing a save" do
|
455
503
|
before :each do
|
456
|
-
@connection = stub('mock http connection', :put => @response)
|
504
|
+
@connection = stub('mock http connection', :put => @response, :verify_callback= => nil)
|
457
505
|
@searcher.stubs(:network).returns(@connection) # neuter the network connection
|
458
506
|
|
459
507
|
@instance = stub 'instance', :render => "mydata", :mime => "mime"
|
@@ -154,5 +154,23 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do
|
|
154
154
|
Dir.expects(:glob).with(:glob).returns []
|
155
155
|
@store.search(@request).should == []
|
156
156
|
end
|
157
|
+
|
158
|
+
describe Puppet::Indirector::Yaml, " when destroying" do
|
159
|
+
it "should unlink the right yaml file if it exists" do
|
160
|
+
path = File.join("/what/ever", @store.class.indirection_name.to_s, @request.key.to_s + ".yaml")
|
161
|
+
File.expects(:exists?).with(path).returns true
|
162
|
+
File.expects(:unlink).with(path)
|
163
|
+
|
164
|
+
@store.destroy(@request)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should not unlink the yaml file if it does not exists" do
|
168
|
+
path = File.join("/what/ever", @store.class.indirection_name.to_s, @request.key.to_s + ".yaml")
|
169
|
+
File.expects(:exists?).with(path).returns false
|
170
|
+
File.expects(:unlink).with(path).never
|
171
|
+
|
172
|
+
@store.destroy(@request)
|
173
|
+
end
|
174
|
+
end
|
157
175
|
end
|
158
176
|
end
|
@@ -121,6 +121,7 @@ describe Puppet::Interface::Action do
|
|
121
121
|
let :face do
|
122
122
|
Puppet::Interface.new(:ruby_api, '1.0.0') do
|
123
123
|
action :bar do
|
124
|
+
option "--bar"
|
124
125
|
when_invoked do |*args|
|
125
126
|
args.last
|
126
127
|
end
|
@@ -138,8 +139,8 @@ describe Puppet::Interface::Action do
|
|
138
139
|
options.should == { :bar => "beer" }
|
139
140
|
end
|
140
141
|
|
141
|
-
it "should call #
|
142
|
-
face.get_action(:bar).expects(:
|
142
|
+
it "should call #validate_and_clean on the action when invoked" do
|
143
|
+
face.get_action(:bar).expects(:validate_and_clean).with({}).returns({})
|
143
144
|
face.bar 1, :two, 'three'
|
144
145
|
end
|
145
146
|
end
|
@@ -171,6 +172,30 @@ describe Puppet::Interface::Action do
|
|
171
172
|
face.get_action(:foo).options.should =~ [:bar]
|
172
173
|
end
|
173
174
|
|
175
|
+
describe "option aliases" do
|
176
|
+
let :option do action.get_option :bar end
|
177
|
+
let :action do face.get_action :foo end
|
178
|
+
let :face do
|
179
|
+
Puppet::Interface.new(:action_level_options, '0.0.1') do
|
180
|
+
action :foo do
|
181
|
+
when_invoked do |options| options end
|
182
|
+
option "--bar", "--foo", "-b"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should only list options and not aliases" do
|
188
|
+
action.options.should =~ [:bar]
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should use the canonical option name when passed aliases" do
|
192
|
+
name = option.name
|
193
|
+
option.aliases.each do |input|
|
194
|
+
face.foo(input => 1).should == { name => 1 }
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
174
199
|
describe "with both face and action options" do
|
175
200
|
let :face do
|
176
201
|
Puppet::Interface.new(:action_level_options, '0.0.1') do
|
@@ -426,12 +451,12 @@ describe Puppet::Interface::Action do
|
|
426
451
|
end
|
427
452
|
|
428
453
|
it "should be invoked when calling a child action" do
|
429
|
-
subject.on_child(:foo => true
|
454
|
+
subject.on_child(:foo => true).should == :on_child
|
430
455
|
subject.reported.should == [ :child_before ]
|
431
456
|
end
|
432
457
|
|
433
458
|
it "should be invoked when calling a parent action" do
|
434
|
-
subject.on_parent(:foo => true
|
459
|
+
subject.on_parent(:foo => true).should == :on_parent
|
435
460
|
subject.reported.should == [ :child_before ]
|
436
461
|
end
|
437
462
|
end
|
@@ -443,12 +468,12 @@ describe Puppet::Interface::Action do
|
|
443
468
|
end
|
444
469
|
|
445
470
|
it "should be invoked when calling a child action" do
|
446
|
-
subject.on_child(:foo => true
|
471
|
+
subject.on_child(:foo => true).should == :on_child
|
447
472
|
subject.reported.should == [ :parent_before ]
|
448
473
|
end
|
449
474
|
|
450
475
|
it "should be invoked when calling a parent action" do
|
451
|
-
subject.on_parent(:foo => true
|
476
|
+
subject.on_parent(:foo => true).should == :on_parent
|
452
477
|
subject.reported.should == [ :parent_before ]
|
453
478
|
end
|
454
479
|
end
|
@@ -524,10 +549,10 @@ describe Puppet::Interface::Action do
|
|
524
549
|
it "should return the block if asked"
|
525
550
|
end
|
526
551
|
|
527
|
-
context "#
|
552
|
+
context "#validate_and_clean" do
|
528
553
|
subject do
|
529
554
|
Puppet::Interface.new(:validate_args, '1.0.0') do
|
530
|
-
script :test do |options|
|
555
|
+
script :test do |options| options end
|
531
556
|
end
|
532
557
|
end
|
533
558
|
|
@@ -541,5 +566,84 @@ describe Puppet::Interface::Action do
|
|
541
566
|
expect { subject.test :foo => true, :f => true }.
|
542
567
|
to raise_error ArgumentError, /Multiple aliases for the same option/
|
543
568
|
end
|
569
|
+
|
570
|
+
it "should fail if an unknown option is passed" do
|
571
|
+
expect { subject.test :unknown => true }.
|
572
|
+
to raise_error ArgumentError, /Unknown options passed: unknown/
|
573
|
+
end
|
574
|
+
|
575
|
+
it "should report all the unknown options passed" do
|
576
|
+
expect { subject.test :unknown => true, :unseen => false }.
|
577
|
+
to raise_error ArgumentError, /Unknown options passed: unknown, unseen/
|
578
|
+
end
|
579
|
+
|
580
|
+
it "should accept 'global' options from settings" do
|
581
|
+
expect {
|
582
|
+
subject.test(:certname => "true").should == { :certname => "true" }
|
583
|
+
}.not_to raise_error
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
context "default option values" do
|
588
|
+
subject do
|
589
|
+
Puppet::Interface.new(:default_option_values, '1.0.0') do
|
590
|
+
action :foo do
|
591
|
+
option "--foo" do end
|
592
|
+
option "--bar" do end
|
593
|
+
when_invoked do |options| options end
|
594
|
+
end
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
let :action do subject.get_action :foo end
|
599
|
+
let :option do action.get_option :foo end
|
600
|
+
|
601
|
+
it "should not add options without defaults" do
|
602
|
+
subject.foo.should == {}
|
603
|
+
end
|
604
|
+
|
605
|
+
it "should not add options without defaults, if options are given" do
|
606
|
+
subject.foo(:bar => 1).should == { :bar => 1 }
|
607
|
+
end
|
608
|
+
|
609
|
+
it "should add the option default value when set" do
|
610
|
+
option.default = proc { 12 }
|
611
|
+
subject.foo.should == { :foo => 12 }
|
612
|
+
end
|
613
|
+
|
614
|
+
it "should add the option default value when set, if other options are given" do
|
615
|
+
option.default = proc { 12 }
|
616
|
+
subject.foo(:bar => 1).should == { :foo => 12, :bar => 1 }
|
617
|
+
end
|
618
|
+
|
619
|
+
it "should invoke the same default proc every time called" do
|
620
|
+
option.default = proc { @foo ||= {} }
|
621
|
+
subject.foo[:foo].object_id.should == subject.foo[:foo].object_id
|
622
|
+
end
|
623
|
+
|
624
|
+
[nil, 0, 1, true, false, {}, []].each do |input|
|
625
|
+
it "should not override a passed option (#{input.inspect})" do
|
626
|
+
option.default = proc { :fail }
|
627
|
+
subject.foo(:foo => input).should == { :foo => input }
|
628
|
+
end
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
context "runtime manipulations" do
|
633
|
+
subject do
|
634
|
+
Puppet::Interface.new(:runtime_manipulations, '1.0.0') do
|
635
|
+
action :foo do
|
636
|
+
when_invoked do |options| options end
|
637
|
+
end
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
let :action do subject.get_action :foo end
|
642
|
+
|
643
|
+
it "should be the face default action if default is set true" do
|
644
|
+
subject.get_default_action.should be_nil
|
645
|
+
action.default = true
|
646
|
+
subject.get_default_action.should == action
|
647
|
+
end
|
544
648
|
end
|
545
649
|
end
|