puppet 2.6.4 → 2.6.5
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 +147 -0
- data/LICENSE +2 -2
- data/Rakefile +3 -4
- data/lib/puppet.rb +1 -1
- data/lib/puppet/application.rb +22 -5
- data/lib/puppet/application/apply.rb +2 -18
- data/lib/puppet/application/doc.rb +1 -4
- data/lib/puppet/application/inspect.rb +178 -0
- data/lib/puppet/configurer.rb +9 -11
- data/lib/puppet/configurer/plugin_handler.rb +0 -2
- data/lib/puppet/defaults.rb +12 -3
- data/lib/puppet/external/pson/pure/generator.rb +1 -22
- data/lib/puppet/file_bucket/dipper.rb +9 -3
- data/lib/puppet/file_bucket/file.rb +14 -94
- data/lib/puppet/indirector.rb +4 -0
- data/lib/puppet/indirector/catalog/active_record.rb +1 -1
- data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
- data/lib/puppet/indirector/indirection.rb +18 -8
- data/lib/puppet/indirector/resource/ral.rb +7 -2
- data/lib/puppet/indirector/rest.rb +19 -2
- data/lib/puppet/network/http/api/v1.rb +3 -0
- data/lib/puppet/network/http/handler.rb +16 -1
- data/lib/puppet/network/http/rack/rest.rb +1 -3
- data/lib/puppet/network/rest_authconfig.rb +4 -12
- data/lib/puppet/network/rights.rb +28 -14
- data/lib/puppet/parser/ast.rb +4 -0
- data/lib/puppet/parser/compiler.rb +18 -3
- data/lib/puppet/parser/functions/defined.rb +28 -6
- data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
- data/lib/puppet/parser/templatewrapper.rb +1 -0
- data/lib/puppet/property.rb +16 -1
- data/lib/puppet/property/keyvalue.rb +0 -2
- data/lib/puppet/property/list.rb +0 -2
- data/lib/puppet/provider/file/posix.rb +1 -3
- data/lib/puppet/provider/file/win32.rb +1 -3
- data/lib/puppet/provider/maillist/mailman.rb +3 -5
- data/lib/puppet/provider/mount.rb +2 -0
- data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
- data/lib/puppet/provider/package/freebsd.rb +2 -2
- data/lib/puppet/provider/zone/solaris.rb +1 -1
- data/lib/puppet/reference/configuration.rb +2 -2
- data/lib/puppet/reference/function.rb +4 -0
- data/lib/puppet/relationship.rb +4 -0
- data/lib/puppet/reports/store.rb +1 -19
- data/lib/puppet/resource.rb +11 -2
- data/lib/puppet/resource/status.rb +24 -3
- data/lib/puppet/resource/type.rb +24 -16
- data/lib/puppet/resource/type_collection.rb +4 -1
- data/lib/puppet/simple_graph.rb +4 -0
- data/lib/puppet/transaction.rb +1 -28
- data/lib/puppet/transaction/event.rb +9 -4
- data/lib/puppet/transaction/report.rb +42 -22
- data/lib/puppet/transaction/resource_harness.rb +99 -71
- data/lib/puppet/type.rb +22 -9
- data/lib/puppet/type/cron.rb +1 -5
- data/lib/puppet/type/exec.rb +4 -34
- data/lib/puppet/type/file.rb +19 -26
- data/lib/puppet/type/file/checksum.rb +1 -1
- data/lib/puppet/type/file/content.rb +2 -1
- data/lib/puppet/type/file/ctime.rb +18 -0
- data/lib/puppet/type/file/ensure.rb +1 -1
- data/lib/puppet/type/file/mode.rb +10 -44
- data/lib/puppet/type/file/mtime.rb +17 -0
- data/lib/puppet/type/file/owner.rb +1 -1
- data/lib/puppet/type/file/source.rb +0 -1
- data/lib/puppet/type/file/target.rb +1 -1
- data/lib/puppet/type/file/type.rb +5 -12
- data/lib/puppet/type/host.rb +1 -1
- data/lib/puppet/type/mount.rb +2 -2
- data/lib/puppet/type/package.rb +0 -2
- data/lib/puppet/type/service.rb +11 -5
- data/lib/puppet/type/user.rb +7 -9
- data/lib/puppet/type/yumrepo.rb +2 -2
- data/lib/puppet/type/zpool.rb +0 -4
- data/lib/puppet/util/checksums.rb +24 -1
- data/lib/puppet/util/command_line.rb +6 -2
- data/lib/puppet/util/command_line/puppet +5 -1
- data/lib/puppet/util/command_line/puppetca +2 -2
- data/lib/puppet/util/command_line/puppetd +11 -9
- data/lib/puppet/util/command_line/puppetdoc +2 -2
- data/lib/puppet/util/command_line/puppetmasterd +5 -0
- data/lib/puppet/util/log.rb +15 -8
- data/lib/puppet/util/log/destinations.rb +2 -0
- data/lib/puppet/util/log_paths.rb +1 -1
- data/lib/puppet/util/logging.rb +1 -1
- data/lib/puppet/util/metric.rb +1 -0
- data/lib/puppet/util/reference.rb +1 -10
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/zaml.rb +30 -31
- data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
- data/spec/integration/application/apply_spec.rb +1 -2
- data/spec/integration/defaults_spec.rb +1 -0
- data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
- data/spec/integration/indirector/report/rest_spec.rb +13 -17
- data/spec/integration/network/formats_spec.rb +2 -5
- data/spec/integration/network/server/mongrel_spec.rb +1 -2
- data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
- data/spec/integration/provider/package_spec.rb +1 -3
- data/spec/integration/provider/service/init_spec.rb +3 -9
- data/spec/integration/reference/providers_spec.rb +2 -2
- data/spec/integration/resource/catalog_spec.rb +1 -2
- data/spec/integration/transaction/report_spec.rb +1 -1
- data/spec/monkey_patches/alias_should_to_must.rb +2 -0
- data/spec/shared_behaviours/file_server_terminus.rb +1 -1
- data/spec/shared_behaviours/file_serving.rb +1 -1
- data/spec/shared_behaviours/memory_terminus.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/unit/application/agent_spec.rb +1 -0
- data/spec/unit/application/apply_spec.rb +7 -7
- data/spec/unit/application/doc_spec.rb +2 -2
- data/spec/unit/application/filebucket_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +278 -0
- data/spec/unit/application/kick_spec.rb +1 -3
- data/spec/unit/application/master_spec.rb +1 -3
- data/spec/unit/application/queue_spec.rb +1 -0
- data/spec/unit/application_spec.rb +63 -5
- data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
- data/spec/unit/configurer_spec.rb +33 -49
- data/spec/unit/file_bucket/dipper_spec.rb +69 -77
- data/spec/unit/file_bucket/file_spec.rb +12 -127
- data/spec/unit/file_serving/fileset_spec.rb +1 -0
- data/spec/unit/file_serving/metadata_spec.rb +4 -4
- data/spec/unit/indirector/active_record_spec.rb +1 -0
- data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
- data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
- data/spec/unit/indirector/facts/couch_spec.rb +1 -2
- data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
- data/spec/unit/indirector/file_server_spec.rb +6 -7
- data/spec/unit/indirector/indirection_spec.rb +71 -2
- data/spec/unit/indirector/ldap_spec.rb +2 -6
- data/spec/unit/indirector/node/active_record_spec.rb +1 -3
- data/spec/unit/indirector/queue_spec.rb +1 -3
- data/spec/unit/indirector/rest_spec.rb +37 -1
- data/spec/unit/indirector/ssl_file_spec.rb +5 -5
- data/spec/unit/indirector_spec.rb +6 -1
- data/spec/unit/module_spec.rb +1 -3
- data/spec/unit/network/formats_spec.rb +2 -5
- data/spec/unit/network/http/api/v1_spec.rb +4 -0
- data/spec/unit/network/http/compression_spec.rb +1 -3
- data/spec/unit/network/http/handler_spec.rb +39 -0
- data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
- data/spec/unit/network/http/mongrel_spec.rb +3 -9
- data/spec/unit/network/http/rack/rest_spec.rb +1 -3
- data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
- data/spec/unit/network/http/rack_spec.rb +2 -3
- data/spec/unit/network/http/webrick_spec.rb +1 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/network/rights_spec.rb +43 -23
- data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
- data/spec/unit/parameter_spec.rb +1 -2
- data/spec/unit/parser/collector_spec.rb +3 -6
- data/spec/unit/parser/compiler_spec.rb +90 -5
- data/spec/unit/parser/lexer_spec.rb +3 -2
- data/spec/unit/parser/templatewrapper_spec.rb +1 -0
- data/spec/unit/property/keyvalue_spec.rb +5 -5
- data/spec/unit/property/list_spec.rb +7 -7
- data/spec/unit/provider/mount/parsed_spec.rb +1 -2
- data/spec/unit/provider/mount_spec.rb +8 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
- data/spec/unit/provider/package/freebsd_spec.rb +55 -0
- data/spec/unit/provider/service/init_spec.rb +2 -0
- data/spec/unit/rails/host_spec.rb +1 -3
- data/spec/unit/rails/param_value_spec.rb +2 -3
- data/spec/unit/rails/resource_spec.rb +2 -3
- data/spec/unit/rails_spec.rb +5 -15
- data/spec/unit/relationship_spec.rb +2 -6
- data/spec/unit/reports/http_spec.rb +1 -1
- data/spec/unit/reports/store_spec.rb +31 -0
- data/spec/unit/reports/tagmail_spec.rb +1 -1
- data/spec/unit/resource/catalog_spec.rb +2 -6
- data/spec/unit/resource/status_spec.rb +53 -3
- data/spec/unit/resource/type_collection_spec.rb +0 -8
- data/spec/unit/resource/type_spec.rb +50 -4
- data/spec/unit/resource_spec.rb +10 -6
- data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
- data/spec/unit/transaction/event_spec.rb +21 -2
- data/spec/unit/transaction/report_spec.rb +91 -35
- data/spec/unit/transaction/resource_harness_spec.rb +289 -208
- data/spec/unit/transaction_spec.rb +1 -6
- data/spec/unit/type/augeas_spec.rb +1 -3
- data/spec/unit/type/file/content_spec.rb +63 -10
- data/spec/unit/type/file/ctime.rb +35 -0
- data/spec/unit/type/file/ensure_spec.rb +8 -7
- data/spec/unit/type/file/group_spec.rb +5 -5
- data/spec/unit/type/file/mtime.rb +35 -0
- data/spec/unit/type/file/owner_spec.rb +7 -7
- data/spec/unit/type/file/selinux_spec.rb +2 -2
- data/spec/unit/type/file/source_spec.rb +3 -3
- data/spec/unit/type/file/type.rb +20 -0
- data/spec/unit/type/file_spec.rb +131 -8
- data/spec/unit/type/mount_spec.rb +4 -4
- data/spec/unit/type/package_spec.rb +3 -3
- data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
- data/spec/unit/type/user_spec.rb +31 -3
- data/spec/unit/type/zpool_spec.rb +12 -12
- data/spec/unit/type_spec.rb +2 -2
- data/spec/unit/util/checksums_spec.rb +9 -1
- data/spec/unit/util/command_line_spec.rb +29 -0
- data/spec/unit/util/log/destinations_spec.rb +13 -0
- data/spec/unit/util/log_spec.rb +24 -12
- data/spec/unit/util/logging_spec.rb +1 -1
- data/spec/unit/util/metric_spec.rb +7 -7
- data/spec/unit/util/pson_spec.rb +15 -0
- data/spec/unit/util/queue/stomp_spec.rb +2 -6
- data/spec/unit/util/settings/file_setting_spec.rb +1 -3
- data/spec/unit/util/zaml_spec.rb +51 -0
- data/test/language/snippets.rb +3 -0
- data/test/lib/puppettest/fileparsing.rb +2 -0
- data/test/lib/puppettest/reporttesting.rb +1 -1
- data/test/lib/puppettest/support/utils.rb +1 -1
- data/test/network/server/mongrel_test.rb +0 -6
- data/test/other/report.rb +1 -1
- data/test/ral/providers/cron/crontab.rb +4 -1
- data/test/ral/type/file.rb +1 -1
- data/test/ral/type/filesources.rb +1 -4
- metadata +1119 -1113
- data/lib/puppet/transaction/change.rb +0 -87
- data/spec/Rakefile +0 -91
- data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
- data/spec/spec_specs/runnable_spec.rb +0 -95
- data/spec/unit/transaction/change_spec.rb +0 -193
@@ -1,10 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
4
|
+
require 'puppet_spec/files'
|
4
5
|
|
5
6
|
require 'puppet/transaction/resource_harness'
|
6
7
|
|
7
8
|
describe Puppet::Transaction::ResourceHarness do
|
9
|
+
include PuppetSpec::Files
|
10
|
+
|
8
11
|
before do
|
9
12
|
@transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
|
10
13
|
@resource = Puppet::Type.type(:file).new :path => "/my/file"
|
@@ -25,38 +28,6 @@ describe Puppet::Transaction::ResourceHarness do
|
|
25
28
|
Puppet::Transaction::ResourceHarness.new(@transaction).relationship_graph.should == "relgraph"
|
26
29
|
end
|
27
30
|
|
28
|
-
describe "when copying audited parameters" do
|
29
|
-
before do
|
30
|
-
@resource = Puppet::Type.type(:file).new :path => "/foo/bar", :audit => :mode
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should do nothing if no parameters are being audited" do
|
34
|
-
@resource[:audit] = []
|
35
|
-
@harness.expects(:cached).never
|
36
|
-
@harness.copy_audited_parameters(@resource, {}).should == []
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should do nothing if an audited parameter already has a desired value set" do
|
40
|
-
@resource[:mode] = "755"
|
41
|
-
@harness.expects(:cached).never
|
42
|
-
@harness.copy_audited_parameters(@resource, {}).should == []
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should copy any cached values to the 'should' values" do
|
46
|
-
@harness.cache(@resource, :mode, "755")
|
47
|
-
@harness.copy_audited_parameters(@resource, {}).should == [:mode]
|
48
|
-
|
49
|
-
@resource[:mode].should == 0755
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should cache and log the current value if no cached values are present" do
|
53
|
-
@resource.expects(:debug)
|
54
|
-
@harness.copy_audited_parameters(@resource, {:mode => "755"}).should == []
|
55
|
-
|
56
|
-
@harness.cached(@resource, :mode).should == "755"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
31
|
describe "when evaluating a resource" do
|
61
32
|
it "should create and return a resource status instance for the resource" do
|
62
33
|
@harness.evaluate(@resource).should be_instance_of(Puppet::Resource::Status)
|
@@ -78,212 +49,322 @@ describe Puppet::Transaction::ResourceHarness do
|
|
78
49
|
@harness.evaluate(@resource).should be_failed
|
79
50
|
end
|
80
51
|
|
81
|
-
it "should use the status and retrieved state to determine which changes need to be made" do
|
82
|
-
@harness.expects(:changes_to_perform).with(@status, @resource).returns []
|
83
|
-
@harness.evaluate(@resource)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should mark the status as out of sync and apply the created changes if there are any" do
|
87
|
-
changes = %w{mychanges}
|
88
|
-
@harness.expects(:changes_to_perform).returns changes
|
89
|
-
@harness.expects(:apply_changes).with(@status, changes)
|
90
|
-
@harness.evaluate(@resource).should be_out_of_sync
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should cache the last-synced time" do
|
94
|
-
changes = %w{mychanges}
|
95
|
-
@harness.stubs(:changes_to_perform).returns changes
|
96
|
-
@harness.stubs(:apply_changes)
|
97
|
-
@harness.expects(:cache).with { |resource, name, time| name == :synced and time.is_a?(Time) }
|
98
|
-
@harness.evaluate(@resource)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should flush the resource when applying changes if appropriate" do
|
102
|
-
changes = %w{mychanges}
|
103
|
-
@harness.stubs(:changes_to_perform).returns changes
|
104
|
-
@harness.stubs(:apply_changes)
|
105
|
-
@resource.expects(:flush)
|
106
|
-
@harness.evaluate(@resource)
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should use the status and retrieved state to determine which changes need to be made" do
|
110
|
-
@harness.expects(:changes_to_perform).with(@status, @resource).returns []
|
111
|
-
@harness.evaluate(@resource)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should not attempt to apply changes if none need to be made" do
|
115
|
-
@harness.expects(:changes_to_perform).returns []
|
116
|
-
@harness.expects(:apply_changes).never
|
117
|
-
@harness.evaluate(@resource).should_not be_out_of_sync
|
118
|
-
end
|
119
|
-
|
120
52
|
it "should store the resource's evaluation time in the resource status" do
|
121
53
|
@harness.evaluate(@resource).evaluation_time.should be_instance_of(Float)
|
122
54
|
end
|
123
|
-
|
124
|
-
it "should set the change count to the total number of changes" do
|
125
|
-
changes = %w{a b c d}
|
126
|
-
@harness.expects(:changes_to_perform).returns changes
|
127
|
-
@harness.expects(:apply_changes).with(@status, changes)
|
128
|
-
@harness.evaluate(@resource).change_count.should == 4
|
129
|
-
end
|
130
55
|
end
|
131
56
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
it "should retrieve the current values from the resource" do
|
140
|
-
@resource.expects(:retrieve).returns @current_state
|
141
|
-
@harness.changes_to_perform(@status, @resource)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should cache that the resource was checked" do
|
145
|
-
@harness.expects(:cache).with { |resource, name, time| name == :checked and time.is_a?(Time) }
|
146
|
-
@harness.changes_to_perform(@status, @resource)
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should create changes with the appropriate property and current value" do
|
150
|
-
@resource[:ensure] = :present
|
151
|
-
@current_state[:ensure] = :absent
|
152
|
-
|
153
|
-
change = stub 'change'
|
154
|
-
Puppet::Transaction::Change.expects(:new).with(@resource.parameter(:ensure), :absent).returns change
|
155
|
-
|
156
|
-
@harness.changes_to_perform(@status, @resource)[0].should equal(change)
|
57
|
+
def events_to_hash(events)
|
58
|
+
events.map do |event|
|
59
|
+
hash = {}
|
60
|
+
event.instance_variables.each do |varname|
|
61
|
+
hash[varname] = event.instance_variable_get(varname.to_sym)
|
62
|
+
end
|
63
|
+
hash
|
157
64
|
end
|
65
|
+
end
|
158
66
|
|
159
|
-
|
160
|
-
|
161
|
-
|
67
|
+
def make_stub_provider
|
68
|
+
stubProvider = Class.new(Puppet::Type)
|
69
|
+
stubProvider.instance_eval do
|
70
|
+
initvars
|
162
71
|
|
163
|
-
|
72
|
+
newparam(:name) do
|
73
|
+
desc "The name var"
|
74
|
+
isnamevar
|
75
|
+
end
|
164
76
|
|
165
|
-
|
166
|
-
|
77
|
+
newproperty(:foo) do
|
78
|
+
desc "A property that can be changed successfully"
|
79
|
+
def sync
|
80
|
+
end
|
167
81
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
@harness.changes_to_perform(@status, @resource)
|
172
|
-
@resource[:mode].should == 0755
|
173
|
-
end
|
82
|
+
def retrieve
|
83
|
+
:absent
|
84
|
+
end
|
174
85
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
@harness.changes_to_perform(@status, @resource)[0].must be_auditing
|
180
|
-
end
|
86
|
+
def insync?(reference_value)
|
87
|
+
false
|
88
|
+
end
|
89
|
+
end
|
181
90
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
@current_state[:mode] = :absent
|
91
|
+
newproperty(:bar) do
|
92
|
+
desc "A property that raises an exception when you try to change it"
|
93
|
+
def sync
|
94
|
+
raise ZeroDivisionError.new('bar')
|
95
|
+
end
|
188
96
|
|
189
|
-
|
97
|
+
def retrieve
|
98
|
+
:absent
|
99
|
+
end
|
190
100
|
|
191
|
-
|
192
|
-
|
193
|
-
|
101
|
+
def insync?(reference_value)
|
102
|
+
false
|
103
|
+
end
|
194
104
|
end
|
195
105
|
end
|
106
|
+
stubProvider
|
107
|
+
end
|
196
108
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
@harness.changes_to_perform(@status, @resource).should == []
|
205
|
-
end
|
109
|
+
describe "when an error occurs" do
|
110
|
+
before :each do
|
111
|
+
stub_provider = make_stub_provider
|
112
|
+
resource = stub_provider.new :name => 'name', :foo => 1, :bar => 2
|
113
|
+
resource.expects(:err).never
|
114
|
+
@status = @harness.evaluate(resource)
|
206
115
|
end
|
207
116
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
@current_state[:ensure] = :absent
|
213
|
-
@current_state[:mode] = :absent
|
117
|
+
it "should record previous successful events" do
|
118
|
+
@status.events[0].property.should == 'foo'
|
119
|
+
@status.events[0].status.should == 'success'
|
120
|
+
end
|
214
121
|
|
215
|
-
|
216
|
-
|
122
|
+
it "should record a failure event" do
|
123
|
+
@status.events[1].property.should == 'bar'
|
124
|
+
@status.events[1].status.should == 'failure'
|
217
125
|
end
|
126
|
+
end
|
218
127
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
mode = stub 'mode_change'
|
229
|
-
owner = stub 'owner_change'
|
230
|
-
Puppet::Transaction::Change.expects(:new).with(@resource.parameter(:mode), 0444).returns mode
|
231
|
-
Puppet::Transaction::Change.expects(:new).with(@resource.parameter(:owner), 50).returns owner
|
232
|
-
|
233
|
-
changes = @harness.changes_to_perform(@status, @resource)
|
234
|
-
changes.length.should == 2
|
235
|
-
changes.should be_include(mode)
|
236
|
-
changes.should be_include(owner)
|
128
|
+
describe "when auditing" do
|
129
|
+
it "should not call insync? on parameters that are merely audited" do
|
130
|
+
stub_provider = make_stub_provider
|
131
|
+
resource = stub_provider.new :name => 'name', :audit => ['foo']
|
132
|
+
resource.property(:foo).expects(:insync?).never
|
133
|
+
status = @harness.evaluate(resource)
|
134
|
+
status.events.each do |event|
|
135
|
+
event.status.should != 'failure'
|
237
136
|
end
|
238
137
|
end
|
239
138
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
139
|
+
it "should be able to audit a file's group" do # see bug #5710
|
140
|
+
test_file = tmpfile('foo')
|
141
|
+
File.open(test_file, 'w').close
|
142
|
+
resource = Puppet::Type.type(:file).new :path => test_file, :audit => ['group'], :backup => false
|
143
|
+
resource.expects(:err).never # make sure no exceptions get swallowed
|
144
|
+
status = @harness.evaluate(resource)
|
145
|
+
status.events.each do |event|
|
146
|
+
event.status.should != 'failure'
|
247
147
|
end
|
248
148
|
end
|
249
149
|
end
|
250
150
|
|
251
151
|
describe "when applying changes" do
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
152
|
+
[false, true].each do |noop_mode|; describe (noop_mode ? "in noop mode" : "in normal mode") do
|
153
|
+
[nil, '750'].each do |machine_state|; describe (machine_state ? "with a file initially present" : "with no file initially present") do
|
154
|
+
[nil, '750', '755'].each do |yaml_mode|
|
155
|
+
[nil, :file, :absent].each do |yaml_ensure|; describe "with mode=#{yaml_mode.inspect} and ensure=#{yaml_ensure.inspect} stored in state.yml" do
|
156
|
+
[false, true].each do |auditing_ensure|
|
157
|
+
[false, true].each do |auditing_mode|
|
158
|
+
auditing = []
|
159
|
+
auditing.push(:mode) if auditing_mode
|
160
|
+
auditing.push(:ensure) if auditing_ensure
|
161
|
+
[nil, :file, :absent].each do |ensure_property| # what we set "ensure" to in the manifest
|
162
|
+
[nil, '750', '755'].each do |mode_property| # what we set "mode" to in the manifest
|
163
|
+
manifest_settings = {}
|
164
|
+
manifest_settings[:audit] = auditing if !auditing.empty?
|
165
|
+
manifest_settings[:ensure] = ensure_property if ensure_property
|
166
|
+
manifest_settings[:mode] = mode_property if mode_property
|
167
|
+
describe "with manifest settings #{manifest_settings.inspect}" do; it "should behave properly" do
|
168
|
+
# Set up preconditions
|
169
|
+
test_file = tmpfile('foo')
|
170
|
+
if machine_state
|
171
|
+
File.open(test_file, 'w', machine_state.to_i(8)).close
|
172
|
+
end
|
173
|
+
|
174
|
+
Puppet[:noop] = noop_mode
|
175
|
+
params = { :path => test_file, :backup => false }
|
176
|
+
params.merge!(manifest_settings)
|
177
|
+
resource = Puppet::Type.type(:file).new params
|
178
|
+
|
179
|
+
@harness.cache(resource, :mode, yaml_mode) if yaml_mode
|
180
|
+
@harness.cache(resource, :ensure, yaml_ensure) if yaml_ensure
|
181
|
+
|
182
|
+
fake_time = Time.utc(2011, 'jan', 3, 12, 24, 0)
|
183
|
+
Time.stubs(:now).returns(fake_time) # So that Puppet::Resource::Status objects will compare properly
|
184
|
+
|
185
|
+
resource.expects(:err).never # make sure no exceptions get swallowed
|
186
|
+
status = @harness.evaluate(resource) # do the thing
|
187
|
+
|
188
|
+
# check that the state of the machine has been properly updated
|
189
|
+
expected_logs = []
|
190
|
+
expected_status_events = []
|
191
|
+
if auditing_mode
|
192
|
+
@harness.cached(resource, :mode).should == (machine_state || :absent)
|
193
|
+
else
|
194
|
+
@harness.cached(resource, :mode).should == yaml_mode
|
195
|
+
end
|
196
|
+
if auditing_ensure
|
197
|
+
@harness.cached(resource, :ensure).should == (machine_state ? :file : :absent)
|
198
|
+
else
|
199
|
+
@harness.cached(resource, :ensure).should == yaml_ensure
|
200
|
+
end
|
201
|
+
if ensure_property == :file
|
202
|
+
file_would_be_there_if_not_noop = true
|
203
|
+
elsif ensure_property == nil
|
204
|
+
file_would_be_there_if_not_noop = machine_state != nil
|
205
|
+
else # ensure_property == :absent
|
206
|
+
file_would_be_there_if_not_noop = false
|
207
|
+
end
|
208
|
+
file_should_be_there = noop_mode ? machine_state != nil : file_would_be_there_if_not_noop
|
209
|
+
File.exists?(test_file).should == file_should_be_there
|
210
|
+
if file_should_be_there
|
211
|
+
if noop_mode
|
212
|
+
expected_file_mode = machine_state
|
213
|
+
else
|
214
|
+
expected_file_mode = mode_property || machine_state
|
215
|
+
end
|
216
|
+
if !expected_file_mode
|
217
|
+
# we didn't specify a mode and the file was created, so mode comes from umode
|
218
|
+
else
|
219
|
+
file_mode = File.stat(test_file).mode & 0777
|
220
|
+
file_mode.should == expected_file_mode.to_i(8)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# Test log output for the "mode" parameter
|
225
|
+
previously_recorded_mode_already_logged = false
|
226
|
+
mode_status_msg = nil
|
227
|
+
if machine_state && file_would_be_there_if_not_noop && mode_property && machine_state != mode_property
|
228
|
+
if noop_mode
|
229
|
+
what_happened = "current_value #{machine_state}, should be #{mode_property} (noop)"
|
230
|
+
expected_status = 'noop'
|
231
|
+
else
|
232
|
+
what_happened = "mode changed '#{machine_state}' to '#{mode_property}'"
|
233
|
+
expected_status = 'success'
|
234
|
+
end
|
235
|
+
if auditing_mode && yaml_mode && yaml_mode != machine_state
|
236
|
+
previously_recorded_mode_already_logged = true
|
237
|
+
mode_status_msg = "#{what_happened} (previously recorded value was #{yaml_mode})"
|
238
|
+
else
|
239
|
+
mode_status_msg = what_happened
|
240
|
+
end
|
241
|
+
expected_logs << "notice: /#{resource}/mode: #{mode_status_msg}"
|
242
|
+
end
|
243
|
+
if @harness.cached(resource, :mode) && @harness.cached(resource, :mode) != yaml_mode
|
244
|
+
if yaml_mode
|
245
|
+
unless previously_recorded_mode_already_logged
|
246
|
+
mode_status_msg = "audit change: previously recorded value #{yaml_mode} has been changed to #{@harness.cached(resource, :mode)}"
|
247
|
+
expected_logs << "notice: /#{resource}/mode: #{mode_status_msg}"
|
248
|
+
expected_status = 'audit'
|
249
|
+
end
|
250
|
+
else
|
251
|
+
expected_logs << "notice: /#{resource}/mode: audit change: newly-recorded value #{@harness.cached(resource, :mode)}"
|
252
|
+
end
|
253
|
+
end
|
254
|
+
if mode_status_msg
|
255
|
+
expected_status_events << Puppet::Transaction::Event.new(
|
256
|
+
:source_description => "/#{resource}/mode", :resource => resource, :file => nil,
|
257
|
+
:line => nil, :tags => %w{file}, :desired_value => mode_property,
|
258
|
+
:historical_value => yaml_mode, :message => mode_status_msg, :name => :mode_changed,
|
259
|
+
:previous_value => machine_state || :absent, :property => :mode, :status => expected_status,
|
260
|
+
:audited => auditing_mode)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Test log output for the "ensure" parameter
|
264
|
+
previously_recorded_ensure_already_logged = false
|
265
|
+
ensure_status_msg = nil
|
266
|
+
if file_would_be_there_if_not_noop != (machine_state != nil)
|
267
|
+
if noop_mode
|
268
|
+
what_happened = "current_value #{machine_state ? 'file' : 'absent'}, should be #{file_would_be_there_if_not_noop ? 'file' : 'absent'} (noop)"
|
269
|
+
expected_status = 'noop'
|
270
|
+
else
|
271
|
+
what_happened = file_would_be_there_if_not_noop ? 'created' : 'removed'
|
272
|
+
expected_status = 'success'
|
273
|
+
end
|
274
|
+
if auditing_ensure && yaml_ensure && yaml_ensure != (machine_state ? :file : :absent)
|
275
|
+
previously_recorded_ensure_already_logged = true
|
276
|
+
ensure_status_msg = "#{what_happened} (previously recorded value was #{yaml_ensure})"
|
277
|
+
else
|
278
|
+
ensure_status_msg = "#{what_happened}"
|
279
|
+
end
|
280
|
+
expected_logs << "notice: /#{resource}/ensure: #{ensure_status_msg}"
|
281
|
+
end
|
282
|
+
if @harness.cached(resource, :ensure) && @harness.cached(resource, :ensure) != yaml_ensure
|
283
|
+
if yaml_ensure
|
284
|
+
unless previously_recorded_ensure_already_logged
|
285
|
+
ensure_status_msg = "audit change: previously recorded value #{yaml_ensure} has been changed to #{@harness.cached(resource, :ensure)}"
|
286
|
+
expected_logs << "notice: /#{resource}/ensure: #{ensure_status_msg}"
|
287
|
+
expected_status = 'audit'
|
288
|
+
end
|
289
|
+
else
|
290
|
+
expected_logs << "notice: /#{resource}/ensure: audit change: newly-recorded value #{@harness.cached(resource, :ensure)}"
|
291
|
+
end
|
292
|
+
end
|
293
|
+
if ensure_status_msg
|
294
|
+
if ensure_property == :file
|
295
|
+
ensure_event_name = :file_created
|
296
|
+
elsif ensure_property == nil
|
297
|
+
ensure_event_name = :file_changed
|
298
|
+
else # ensure_property == :absent
|
299
|
+
ensure_event_name = :file_removed
|
300
|
+
end
|
301
|
+
expected_status_events << Puppet::Transaction::Event.new(
|
302
|
+
:source_description => "/#{resource}/ensure", :resource => resource, :file => nil,
|
303
|
+
:line => nil, :tags => %w{file}, :desired_value => ensure_property,
|
304
|
+
:historical_value => yaml_ensure, :message => ensure_status_msg, :name => ensure_event_name,
|
305
|
+
:previous_value => machine_state ? :file : :absent, :property => :ensure,
|
306
|
+
:status => expected_status, :audited => auditing_ensure)
|
307
|
+
end
|
308
|
+
|
309
|
+
# Actually check the logs.
|
310
|
+
@logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ expected_logs
|
311
|
+
|
312
|
+
# All the log messages should show up as events except the "newly-recorded" ones.
|
313
|
+
expected_event_logs = @logs.reject {|l| l.message =~ /newly-recorded/ }
|
314
|
+
status.events.map {|e| e.message}.should =~ expected_event_logs.map {|l| l.message }
|
315
|
+
events_to_hash(status.events).should =~ events_to_hash(expected_status_events)
|
316
|
+
|
317
|
+
# Check change count - this is the number of changes that actually occurred.
|
318
|
+
expected_change_count = 0
|
319
|
+
if (machine_state != nil) != file_should_be_there
|
320
|
+
expected_change_count = 1
|
321
|
+
elsif machine_state != nil
|
322
|
+
if expected_file_mode != machine_state
|
323
|
+
expected_change_count = 1
|
324
|
+
end
|
325
|
+
end
|
326
|
+
status.change_count.should == expected_change_count
|
327
|
+
|
328
|
+
# Check out of sync count - this is the number
|
329
|
+
# of changes that would have occurred in
|
330
|
+
# non-noop mode.
|
331
|
+
expected_out_of_sync_count = 0
|
332
|
+
if (machine_state != nil) != file_would_be_there_if_not_noop
|
333
|
+
expected_out_of_sync_count = 1
|
334
|
+
elsif machine_state != nil
|
335
|
+
if mode_property != nil && mode_property != machine_state
|
336
|
+
expected_out_of_sync_count = 1
|
337
|
+
end
|
338
|
+
end
|
339
|
+
if !noop_mode
|
340
|
+
expected_out_of_sync_count.should == expected_change_count
|
341
|
+
end
|
342
|
+
status.out_of_sync_count.should == expected_out_of_sync_count
|
343
|
+
|
344
|
+
# Check legacy summary fields
|
345
|
+
status.changed.should == (expected_change_count != 0)
|
346
|
+
status.out_of_sync.should == (expected_out_of_sync_count != 0)
|
347
|
+
|
348
|
+
# Check the :synced field on state.yml
|
349
|
+
synced_should_be_set = !noop_mode && status.changed
|
350
|
+
(@harness.cached(resource, :synced) != nil).should == synced_should_be_set
|
351
|
+
end; end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end; end
|
357
|
+
end
|
358
|
+
end; end
|
359
|
+
end; end
|
360
|
+
|
361
|
+
it "should not apply changes if allow_changes?() returns false" do
|
362
|
+
test_file = tmpfile('foo')
|
363
|
+
resource = Puppet::Type.type(:file).new :path => test_file, :backup => false, :ensure => :file
|
364
|
+
resource.expects(:err).never # make sure no exceptions get swallowed
|
365
|
+
@harness.expects(:allow_changes?).with(resource).returns false
|
366
|
+
status = @harness.evaluate(resource)
|
367
|
+
File.exists?(test_file).should == false
|
287
368
|
end
|
288
369
|
end
|
289
370
|
|