3
3
require 'puppet/face'
5
5
describe Puppet::Face[:node, '0.0.1'] do
6
it "REVISIT: really should have some tests"
7
Puppet::SSL::Host.ca_location = :none
10
describe '#cleanup' do
11
it "should clean everything" do
13
"cert" => ['hostname'],
14
"cached_facts" => ['hostname'],
15
"cached_node" => ['hostname'],
16
"reports" => ['hostname'],
18
# Support for cleaning storeconfigs has been temporarily suspended.
19
# "storeconfigs" => ['hostname', :unexport]
20
}.each { |k, v| subject.expects("clean_#{k}".to_sym).with(*v) }
21
subject.cleanup('hostname', :unexport)
25
describe 'when running #clean' do
27
Puppet::Node::Facts.indirection.stubs(:terminus_class=)
28
Puppet::Node::Facts.indirection.stubs(:cache_class=)
29
Puppet::Node.stubs(:terminus_class=)
30
Puppet::Node.stubs(:cache_class=)
33
it 'should invoke #cleanup' do
34
subject.expects(:cleanup).with('hostname', nil)
35
subject.clean('hostname')
39
describe "clean action" do
41
Puppet::Node::Facts.indirection.stubs(:terminus_class=)
42
Puppet::Node::Facts.indirection.stubs(:cache_class=)
43
Puppet::Node.stubs(:terminus_class=)
44
Puppet::Node.stubs(:cache_class=)
45
subject.stubs(:cleanup)
48
it "should have a clean action" do
49
subject.should be_action :clean
52
it "should not accept a call with no arguments" do
53
expect { subject.clean() }.should raise_error
56
it "should accept a node name" do
57
expect { subject.clean('hostname') }.should_not raise_error
60
it "should accept more than one node name" do
62
subject.clean('hostname', 'hostname2', {})
63
end.should_not raise_error
66
subject.clean('hostname', 'hostname2', 'hostname3', { :unexport => true })
67
end.should_not raise_error
70
it "should accept the option --unexport" do
71
expect { subject.help('hostname', :unexport => true) }.
72
should_not raise_error ArgumentError
75
context "clean action" do
76
subject { Puppet::Face[:node, :current] }
78
Puppet::Util::Log.stubs(:newdestination)
79
Puppet::Util::Log.stubs(:level=)
82
describe "during setup" do
83
it "should set facts terminus and cache class to yaml" do
84
Puppet::Node::Facts.indirection.expects(:terminus_class=).with(:yaml)
85
Puppet::Node::Facts.indirection.expects(:cache_class=).with(:yaml)
87
subject.clean('hostname')
90
it "should run in master mode" do
91
subject.clean('hostname')
92
$puppet_application_mode.name.should == :master
95
it "should set node cache as yaml" do
96
Puppet::Node.indirection.expects(:terminus_class=).with(:yaml)
97
Puppet::Node.indirection.expects(:cache_class=).with(:yaml)
99
subject.clean('hostname')
102
it "should manage the certs if the host is a CA" do
103
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true)
104
Puppet::SSL::Host.expects(:ca_location=).with(:local)
105
subject.clean('hostname')
108
it "should not manage the certs if the host is not a CA" do
109
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(false)
110
Puppet::SSL::Host.expects(:ca_location=).with(:none)
111
subject.clean('hostname')
115
describe "when cleaning certificate" do
117
Puppet::SSL::Host.stubs(:destroy)
119
Puppet::SSL::CertificateAuthority.stubs(:instance).returns(@ca)
122
it "should send the :destroy order to the ca if we are a CA" do
123
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true)
124
@ca.expects(:revoke).with(@host)
125
@ca.expects(:destroy).with(@host)
126
subject.clean_cert(@host)
129
it "should not destroy the certs if we are not a CA" do
130
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(false)
131
@ca.expects(:revoke).never
132
@ca.expects(:destroy).never
133
subject.clean_cert(@host)
137
describe "when cleaning cached facts" do
138
it "should destroy facts" do
140
Puppet::Node::Facts.indirection.expects(:destroy).with(@host)
142
subject.clean_cached_facts(@host)
146
describe "when cleaning cached node" do
147
it "should destroy the cached node" do
148
Puppet::Node.indirection.expects(:destroy).with(@host)
149
subject.clean_cached_node(@host)
153
describe "when cleaning archived reports" do
154
it "should tell the reports to remove themselves" do
155
Puppet::Transaction::Report.indirection.stubs(:destroy).with(@host)
157
subject.clean_reports(@host)
161
# describe "when cleaning storeconfigs entries for host", :if => Puppet.features.rails? do
163
# # Stub this so we don't need access to the DB
164
# require 'puppet/rails/host'
166
# Puppet.stubs(:[]).with(:storeconfigs).returns(true)
168
# Puppet::Rails.stubs(:connect)
169
# @rails_node = stub_everything 'rails_node'
170
# Puppet::Rails::Host.stubs(:find_by_name).returns(@rails_node)
173
# it "should connect to the database" do
174
# Puppet::Rails.expects(:connect)
175
# subject.clean_storeconfigs(@host, false)
178
# it "should find the right host entry" do
179
# Puppet::Rails::Host.expects(:find_by_name).with(@host).returns(@rails_node)
180
# subject.clean_storeconfigs(@host, false)
183
# describe "without unexport" do
184
# it "should remove the host and it's content" do
185
# @rails_node.expects(:destroy)
186
# subject.clean_storeconfigs(@host, false)
190
# describe "with unexport" do
192
# @rails_node.stubs(:id).returns(1234)
194
# @type = stub_everything 'type'
195
# @type.stubs(:validattr?).with(:ensure).returns(true)
197
# @ensure_name = stub_everything 'ensure_name', :id => 23453
198
# Puppet::Rails::ParamName.stubs(:find_or_create_by_name).returns(@ensure_name)
200
# @param_values = stub_everything 'param_values'
201
# @resource = stub_everything 'resource', :param_values => @param_values, :restype => "File"
202
# Puppet::Rails::Resource.stubs(:find).returns([@resource])
205
# it "should find all resources" do
206
# Puppet::Rails::Resource.expects(:find).with(:all, {:include => {:param_values => :param_name}, :conditions => ["exported=? AND host_id=?", true, 1234]}).returns([])
208
# subject.clean_storeconfigs(@host, true)
211
# describe "with an exported native type" do
213
# Puppet::Type.stubs(:type).returns(@type)
214
# @type.expects(:validattr?).with(:ensure).returns(true)
217
# it "should test a native type for ensure as an attribute" do
218
# subject.clean_storeconfigs(@host, true)
221
# it "should delete the old ensure parameter" do
222
# ensure_param = stub 'ensure_param', :id => 12345, :line => 12
223
# @param_values.stubs(:find).returns(ensure_param)
224
# Puppet::Rails::ParamValue.expects(:delete).with(12345);
225
# subject.clean_storeconfigs(@host, true)
228
# it "should add an ensure => absent parameter" do
229
# @param_values.expects(:create).with(:value => "absent",
231
# :param_name => @ensure_name)
232
# subject.clean_storeconfigs(@host, true)
236
# describe "with an exported definition" do
237
# it "should try to lookup a definition and test it for the ensure argument" do
238
# Puppet::Type.stubs(:type).returns(nil)
239
# definition = stub_everything 'definition', :arguments => { 'ensure' => 'present' }
240
# Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(definition)
241
# subject.clean_storeconfigs(@host, true)
245
# it "should not unexport the resource of an unknown type" do
246
# Puppet::Type.stubs(:type).returns(nil)
247
# Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(nil)
248
# Puppet::Rails::ParamName.expects(:find_or_create_by_name).never
249
# subject.clean_storeconfigs(@host)
252
# it "should not unexport the resource of a not ensurable native type" do
253
# Puppet::Type.stubs(:type).returns(@type)
254
# @type.expects(:validattr?).with(:ensure).returns(false)
255
# Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(nil)
256
# Puppet::Rails::ParamName.expects(:find_or_create_by_name).never
257
# subject.clean_storeconfigs(@host, true)
260
# it "should not unexport the resource of a not ensurable definition" do
261
# Puppet::Type.stubs(:type).returns(nil)
262
# definition = stub_everything 'definition', :arguments => { 'foobar' => 'someValue' }
263
# Puppet::Resource::TypeCollection.any_instance.expects(:find_definition).with('', "File").returns(definition)
264
# Puppet::Rails::ParamName.expects(:find_or_create_by_name).never
265
# subject.clean_storeconfigs(@host, true)