1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/face'
describe Puppet::Face[:node, '0.0.1'] do
after :all do
Puppet::SSL::Host.ca_location = :none
end
describe '#cleanup' do
it "should clean everything" do
{
"cert" => ['hostname'],
"cached_facts" => ['hostname'],
"cached_node" => ['hostname'],
"reports" => ['hostname'],
}.each { |k, v| subject.expects("clean_#{k}".to_sym).with(*v) }
subject.cleanup('hostname')
end
end
describe 'when running #clean' do
before :each do
Puppet::Node::Facts.indirection.stubs(:terminus_class=)
Puppet::Node::Facts.indirection.stubs(:cache_class=)
Puppet::Node.stubs(:terminus_class=)
Puppet::Node.stubs(:cache_class=)
end
it 'should invoke #cleanup' do
subject.expects(:cleanup).with('hostname', nil)
subject.clean('hostname')
end
end
describe "clean action" do
before :each do
Puppet::Node::Facts.indirection.stubs(:terminus_class=)
Puppet::Node::Facts.indirection.stubs(:cache_class=)
Puppet::Node.stubs(:terminus_class=)
Puppet::Node.stubs(:cache_class=)
subject.stubs(:cleanup)
end
it "should have a clean action" do
expect(subject).to be_action :clean
end
it "should not accept a call with no arguments" do
expect { subject.clean() }.to raise_error(RuntimeError, /At least one node should be passed/)
end
it "should accept a node name" do
expect { subject.clean('hostname') }.to_not raise_error
end
it "should accept more than one node name" do
expect do
subject.clean('hostname', 'hostname2', {})
end.to_not raise_error
expect do
subject.clean('hostname', 'hostname2', 'hostname3')
end.to_not raise_error
end
context "clean action" do
subject { Puppet::Face[:node, :current] }
before :each do
Puppet::Util::Log.stubs(:newdestination)
Puppet::Util::Log.stubs(:level=)
end
describe "during setup" do
it "should set facts terminus and cache class to yaml" do
Puppet::Node::Facts.indirection.expects(:terminus_class=).with(:yaml)
Puppet::Node::Facts.indirection.expects(:cache_class=).with(:yaml)
subject.clean('hostname')
end
it "should run in master mode" do
subject.clean('hostname')
expect(Puppet.run_mode).to be_master
end
it "should set node cache as yaml" do
Puppet::Node.indirection.expects(:terminus_class=).with(:yaml)
Puppet::Node.indirection.expects(:cache_class=).with(:yaml)
subject.clean('hostname')
end
it "should manage the certs if the host is a CA" do
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true)
Puppet::SSL::Host.expects(:ca_location=).with(:local)
subject.clean('hostname')
end
it "should not manage the certs if the host is not a CA" do
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(false)
Puppet::SSL::Host.expects(:ca_location=).with(:none)
subject.clean('hostname')
end
end
describe "when cleaning certificate" do
before :each do
Puppet::SSL::Host.stubs(:destroy)
@ca = mock()
Puppet::SSL::CertificateAuthority.stubs(:instance).returns(@ca)
end
it "should send the :destroy order to the ca if we are a CA" do
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(true)
@ca.expects(:revoke).with(@host)
@ca.expects(:destroy).with(@host)
subject.clean_cert(@host)
end
it "should not destroy the certs if we are not a CA" do
Puppet::SSL::CertificateAuthority.stubs(:ca?).returns(false)
@ca.expects(:revoke).never
@ca.expects(:destroy).never
subject.clean_cert(@host)
end
end
describe "when cleaning cached facts" do
it "should destroy facts" do
@host = 'node'
Puppet::Node::Facts.indirection.expects(:destroy).with(@host)
subject.clean_cached_facts(@host)
end
end
describe "when cleaning cached node" do
it "should destroy the cached node" do
Puppet::Node.indirection.expects(:destroy).with(@host)
subject.clean_cached_node(@host)
end
end
describe "when cleaning archived reports" do
it "should tell the reports to remove themselves" do
Puppet::Transaction::Report.indirection.stubs(:destroy).with(@host)
subject.clean_reports(@host)
end
end
end
end
end
|