blob: be1f34ca3f58db928a4c55324ebdae97ffadedd0 (
plain)
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
|
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/configurer'
describe Puppet::Configurer do
include PuppetSpec::Files
describe "when running" do
before(:each) do
@catalog = Puppet::Resource::Catalog.new("testing", Puppet.lookup(:environments).get(Puppet[:environment]))
@catalog.add_resource(Puppet::Type.type(:notify).new(:title => "testing"))
# Make sure we don't try to persist the local state after the transaction ran,
# because it will fail during test (the state file is in a not-existing directory)
# and we need the transaction to be successful to be able to produce a summary report
@catalog.host_config = false
@configurer = Puppet::Configurer.new
end
it "should send a transaction report with valid data" do
@configurer.stubs(:save_last_run_summary)
Puppet::Transaction::Report.indirection.expects(:save).with do |report, x|
report.time.class == Time and report.logs.length > 0
end
Puppet[:report] = true
@configurer.run :catalog => @catalog
end
it "should save a correct last run summary" do
report = Puppet::Transaction::Report.new("apply")
Puppet::Transaction::Report.indirection.stubs(:save)
Puppet[:lastrunfile] = tmpfile("lastrunfile")
Puppet.settings.setting(:lastrunfile).mode = 0666
Puppet[:report] = true
# We only record integer seconds in the timestamp, and truncate
# backwards, so don't use a more accurate timestamp in the test.
# --daniel 2011-03-07
t1 = Time.now.tv_sec
@configurer.run :catalog => @catalog, :report => report
t2 = Time.now.tv_sec
# sticky bit only applies to directories in windows
file_mode = Puppet.features.microsoft_windows? ? '666' : '100666'
Puppet::FileSystem.stat(Puppet[:lastrunfile]).mode.to_s(8).should == file_mode
summary = nil
File.open(Puppet[:lastrunfile], "r") do |fd|
summary = YAML.load(fd.read)
end
summary.should be_a(Hash)
%w{time changes events resources}.each do |key|
summary.should be_key(key)
end
summary["time"].should be_key("notify")
summary["time"]["last_run"].should be_between(t1, t2)
end
end
end
|