chef 12.5.1 → 12.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -1
- data/README.md +6 -4
- data/Rakefile +1 -4
- data/chef-windows.gemspec +21 -0
- data/chef.gemspec +58 -0
- data/lib/chef/api_client/registration.rb +9 -4
- data/lib/chef/application.rb +3 -84
- data/lib/chef/application/apply.rb +9 -2
- data/lib/chef/application/client.rb +8 -3
- data/lib/chef/application/solo.rb +7 -1
- data/lib/chef/application/windows_service.rb +21 -6
- data/lib/chef/application/windows_service_manager.rb +2 -3
- data/lib/chef/audit/runner.rb +1 -0
- data/lib/chef/chef_class.rb +1 -11
- data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
- data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
- data/lib/chef/client.rb +28 -1
- data/lib/chef/cookbook/cookbook_collection.rb +14 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +115 -9
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
- data/lib/chef/cookbook_version.rb +6 -2
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/digester.rb +5 -1
- data/lib/chef/dsl/chef_provisioning.rb +57 -0
- data/lib/chef/dsl/cheffish.rb +64 -0
- data/lib/chef/dsl/declare_resource.rb +108 -0
- data/lib/chef/dsl/platform_introspection.rb +3 -3
- data/lib/chef/dsl/recipe.rb +3 -73
- data/lib/chef/dsl/resources.rb +27 -1
- data/lib/chef/event_dispatch/base.rb +3 -0
- data/lib/chef/event_dispatch/dispatcher.rb +5 -0
- data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
- data/lib/chef/exceptions.rb +21 -1
- data/lib/chef/file_access_control/unix.rb +12 -12
- data/lib/chef/file_content_management/deploy/cp.rb +2 -2
- data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
- data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
- data/lib/chef/formatters/base.rb +7 -0
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
- data/lib/chef/formatters/indentable_output_stream.rb +5 -0
- data/lib/chef/http.rb +19 -3
- data/lib/chef/http/decompressor.rb +2 -2
- data/lib/chef/json_compat.rb +1 -0
- data/lib/chef/knife.rb +16 -2
- data/lib/chef/knife/bootstrap.rb +55 -10
- data/lib/chef/knife/cookbook_site_install.rb +5 -1
- data/lib/chef/knife/core/bootstrap_context.rb +2 -1
- data/lib/chef/knife/core/node_presenter.rb +1 -1
- data/lib/chef/knife/ssh.rb +30 -16
- data/lib/chef/knife/ssl_check.rb +4 -2
- data/lib/chef/knife/ssl_fetch.rb +3 -2
- data/lib/chef/knife/status.rb +14 -1
- data/lib/chef/log.rb +14 -0
- data/lib/chef/mixin/get_source_from_package.rb +7 -2
- data/lib/chef/mixin/properties.rb +302 -0
- data/lib/chef/mixin/proxified_socket.rb +38 -0
- data/lib/chef/mixin/subclass_directive.rb +37 -0
- data/lib/chef/node.rb +13 -5
- data/lib/chef/platform/query_helpers.rb +14 -3
- data/lib/chef/platform/service_helpers.rb +20 -38
- data/lib/chef/policy_builder/expand_node_object.rb +3 -0
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/property.rb +51 -12
- data/lib/chef/provider.rb +40 -35
- data/lib/chef/provider/deploy.rb +1 -1
- data/lib/chef/provider/dsc_resource.rb +54 -20
- data/lib/chef/provider/execute.rb +25 -4
- data/lib/chef/provider/group.rb +1 -1
- data/lib/chef/provider/lwrp_base.rb +1 -0
- data/lib/chef/provider/package.rb +76 -30
- data/lib/chef/provider/package/dpkg.rb +152 -69
- data/lib/chef/provider/package/openbsd.rb +6 -8
- data/lib/chef/provider/package/solaris.rb +2 -0
- data/lib/chef/provider/package/windows.rb +95 -14
- data/lib/chef/provider/package/windows/exe.rb +129 -0
- data/lib/chef/provider/package/windows/msi.rb +37 -13
- data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
- data/lib/chef/provider/package/yum.rb +13 -3
- data/lib/chef/provider/powershell_script.rb +3 -0
- data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
- data/lib/chef/provider/remote_file/http.rb +1 -1
- data/lib/chef/provider/script.rb +1 -0
- data/lib/chef/provider/service.rb +13 -10
- data/lib/chef/provider/service/solaris.rb +43 -17
- data/lib/chef/provider/service/upstart.rb +3 -3
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/dscl.rb +111 -100
- data/lib/chef/provider/user/windows.rb +5 -3
- data/lib/chef/recipe.rb +3 -5
- data/lib/chef/resource.rb +77 -320
- data/lib/chef/resource/action_class.rb +4 -0
- data/lib/chef/resource/dpkg_package.rb +4 -3
- data/lib/chef/resource/dsc_resource.rb +40 -2
- data/lib/chef/resource/execute.rb +9 -1
- data/lib/chef/resource/ksh.rb +32 -0
- data/lib/chef/resource/lwrp_base.rb +6 -10
- data/lib/chef/resource/package.rb +8 -9
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/resource_notification.rb +14 -1
- data/lib/chef/resource/script.rb +1 -1
- data/lib/chef/resource/windows_package.rb +1 -1
- data/lib/chef/resource_builder.rb +14 -7
- data/lib/chef/resource_reporter.rb +6 -0
- data/lib/chef/resources.rb +1 -7
- data/lib/chef/rest.rb +1 -1
- data/lib/chef/run_context.rb +45 -2
- data/lib/chef/run_list/run_list_expansion.rb +47 -0
- data/lib/chef/runner.rb +25 -0
- data/lib/chef/search/query.rb +16 -2
- data/lib/chef/util/diff.rb +2 -2
- data/lib/chef/util/powershell/ps_credential.rb +2 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api/file.rb +51 -1
- data/lib/chef/win32/file.rb +5 -0
- data/lib/chef/win32/file/version_info.rb +93 -0
- data/lib/chef/win32/mutex.rb +1 -1
- data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
- data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
- data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
- data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
- data/spec/functional/application_spec.rb +1 -1
- data/spec/functional/audit/runner_spec.rb +4 -0
- data/spec/functional/knife/ssh_spec.rb +5 -5
- data/spec/functional/notifications_spec.rb +74 -4
- data/spec/functional/resource/aix_service_spec.rb +2 -2
- data/spec/functional/resource/dpkg_package_spec.rb +339 -0
- data/spec/functional/resource/ifconfig_spec.rb +3 -1
- data/spec/functional/resource/mount_spec.rb +5 -2
- data/spec/functional/resource/package_spec.rb +1 -1
- data/spec/functional/resource/user/windows_spec.rb +8 -0
- data/spec/functional/resource/windows_package_spec.rb +177 -0
- data/spec/functional/win32/version_info_spec.rb +50 -0
- data/spec/integration/client/client_spec.rb +80 -0
- data/spec/integration/knife/download_spec.rb +9 -0
- data/spec/integration/knife/upload_spec.rb +28 -1
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
- data/spec/integration/recipes/resource_action_spec.rb +211 -116
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
- data/spec/integration/solo/solo_spec.rb +34 -0
- data/spec/spec_helper.rb +11 -1
- data/spec/support/platform_helpers.rb +8 -0
- data/spec/support/shared/integration/integration_helper.rb +6 -0
- data/spec/support/shared/unit/execute_resource.rb +5 -0
- data/spec/support/shared/unit/platform_introspector.rb +7 -0
- data/spec/tiny_server.rb +6 -2
- data/spec/unit/api_client/registration_spec.rb +5 -4
- data/spec/unit/application_spec.rb +1 -181
- data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
- data/spec/unit/cookbook/metadata_spec.rb +122 -2
- data/spec/unit/http_spec.rb +102 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -13
- data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
- data/spec/unit/knife/ssl_check_spec.rb +7 -3
- data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
- data/spec/unit/knife/status_spec.rb +13 -13
- data/spec/unit/knife_spec.rb +26 -2
- data/spec/unit/lwrp_spec.rb +1 -1
- data/spec/unit/mixin/properties_spec.rb +97 -0
- data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
- data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
- data/spec/unit/node_spec.rb +9 -1
- data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
- data/spec/unit/property/validation_spec.rb +14 -12
- data/spec/unit/property_spec.rb +56 -0
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/dsc_resource_spec.rb +63 -24
- data/spec/unit/provider/execute_spec.rb +95 -28
- data/spec/unit/provider/package/dpkg_spec.rb +185 -96
- data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
- data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
- data/spec/unit/provider/package/windows_spec.rb +227 -26
- data/spec/unit/provider/package/yum_spec.rb +6 -0
- data/spec/unit/provider/package_spec.rb +495 -366
- data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
- data/spec/unit/provider/script_spec.rb +2 -2
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
- data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
- data/spec/unit/provider/user/dscl_spec.rb +14 -0
- data/spec/unit/provider/user/windows_spec.rb +2 -2
- data/spec/unit/provider/user_spec.rb +9 -0
- data/spec/unit/provider_resolver_spec.rb +6 -30
- data/spec/unit/recipe_spec.rb +46 -20
- data/spec/unit/resource/chef_gem_spec.rb +1 -1
- data/spec/unit/resource/dsc_resource_spec.rb +14 -3
- data/spec/unit/resource/ksh_spec.rb +40 -0
- data/spec/unit/resource/registry_key_spec.rb +2 -2
- data/spec/unit/resource/resource_notification_spec.rb +44 -45
- data/spec/unit/resource_reporter_spec.rb +7 -0
- data/spec/unit/resource_spec.rb +268 -253
- data/spec/unit/rest_spec.rb +2 -2
- data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
- data/spec/unit/search/query_spec.rb +19 -1
- data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
- data/spec/unit/windows_service_spec.rb +83 -38
- data/tasks/external_tests.rb +19 -9
- data/tasks/rspec.rb +1 -1
- metadata +64 -15
- data/spec/support/pedant/Gemfile +0 -3
- data/spec/support/pedant/pedant_config.rb +0 -129
- data/spec/support/pedant/run_pedant.rb +0 -63
- data/spec/support/pedant/stickywicket.pem +0 -27
- data/spec/unit/provider/package_spec.rbe +0 -0
@@ -50,6 +50,9 @@ describe Chef::ResourceReporter do
|
|
50
50
|
@events = Chef::EventDispatch::Dispatcher.new
|
51
51
|
@run_context = Chef::RunContext.new(@node, {}, @events)
|
52
52
|
@run_status = Chef::RunStatus.new(@node, @events)
|
53
|
+
@run_list = Chef::RunList.new
|
54
|
+
@run_list << 'recipe[lobster]' << 'role[rage]' << 'recipe[fist]'
|
55
|
+
@expansion = Chef::RunList::RunListExpansion.new("_default", @run_list.run_list_items)
|
53
56
|
@run_id = @run_status.run_id
|
54
57
|
allow(Time).to receive(:now).and_return(@start_time, @end_time)
|
55
58
|
end
|
@@ -424,6 +427,10 @@ describe Chef::ResourceReporter do
|
|
424
427
|
expect(@report["run_list"]).to eq(Chef::JSONCompat.to_json(@run_status.node.run_list))
|
425
428
|
end
|
426
429
|
|
430
|
+
it "includes the expanded_run_list" do
|
431
|
+
expect(@report).to have_key("expanded_run_list")
|
432
|
+
end
|
433
|
+
|
427
434
|
it "includes the end_time" do
|
428
435
|
expect(@report).to have_key("end_time")
|
429
436
|
expect(@report["end_time"]).to eq(@run_status.end_time.to_s)
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -22,25 +22,24 @@
|
|
22
22
|
require 'spec_helper'
|
23
23
|
|
24
24
|
describe Chef::Resource do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
25
|
+
let(:cookbook_repo_path) { File.join(CHEF_SPEC_DATA, 'cookbooks') }
|
26
|
+
let(:cookbook_collection) { Chef::CookbookCollection.new(Chef::CookbookLoader.new(cookbook_repo_path)) }
|
27
|
+
let(:node) { Chef::Node.new }
|
28
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
29
|
+
let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) }
|
30
|
+
let(:resource) { resource_class.new("funk", run_context) }
|
31
|
+
let(:resource_class) { Chef::Resource }
|
33
32
|
|
34
33
|
it "should mixin shell_out" do
|
35
|
-
expect(
|
34
|
+
expect(resource.respond_to?(:shell_out)).to be true
|
36
35
|
end
|
37
36
|
|
38
37
|
it "should mixin shell_out!" do
|
39
|
-
expect(
|
38
|
+
expect(resource.respond_to?(:shell_out!)).to be true
|
40
39
|
end
|
41
40
|
|
42
41
|
it "should mixin shell_out_with_systems_locale" do
|
43
|
-
expect(
|
42
|
+
expect(resource.respond_to?(:shell_out_with_systems_locale)).to be true
|
44
43
|
end
|
45
44
|
|
46
45
|
describe "when inherited" do
|
@@ -86,30 +85,29 @@ describe Chef::Resource do
|
|
86
85
|
end
|
87
86
|
|
88
87
|
describe "when no identity attribute has been declared" do
|
89
|
-
|
90
|
-
@resource_sans_id = Chef::Resource.new("my-name")
|
91
|
-
end
|
88
|
+
let(:resource_sans_id) { Chef::Resource.new("my-name") }
|
92
89
|
|
93
90
|
# Would rather force identity attributes to be set for everything,
|
94
91
|
# but that's not plausible for back compat reasons.
|
95
92
|
it "uses the name as the identity" do
|
96
|
-
expect(
|
93
|
+
expect(resource_sans_id.identity).to eq("my-name")
|
97
94
|
end
|
98
95
|
end
|
99
96
|
|
100
97
|
describe "when an identity attribute has been declared" do
|
101
|
-
|
102
|
-
|
98
|
+
let(:file_resource) {
|
99
|
+
file_resource_class = Class.new(Chef::Resource) do
|
103
100
|
identity_attr :path
|
104
101
|
attr_accessor :path
|
105
102
|
end
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
file_resource = file_resource_class.new("identity-attr-test")
|
105
|
+
file_resource.path = "/tmp/foo.txt"
|
106
|
+
file_resource
|
107
|
+
}
|
110
108
|
|
111
109
|
it "gives the value of its identity attribute" do
|
112
|
-
expect(
|
110
|
+
expect(file_resource.identity).to eq("/tmp/foo.txt")
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
@@ -142,8 +140,8 @@ describe Chef::Resource do
|
|
142
140
|
end
|
143
141
|
|
144
142
|
describe "when a set of state attributes has been declared" do
|
145
|
-
|
146
|
-
|
143
|
+
let(:file_resource) {
|
144
|
+
file_resource_class = Class.new(Chef::Resource) do
|
147
145
|
|
148
146
|
state_attrs :checksum, :owner, :group, :mode
|
149
147
|
|
@@ -153,15 +151,16 @@ describe Chef::Resource do
|
|
153
151
|
attr_accessor :mode
|
154
152
|
end
|
155
153
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
154
|
+
file_resource = file_resource_class.new("describe-state-test")
|
155
|
+
file_resource.checksum = "abc123"
|
156
|
+
file_resource.owner = "root"
|
157
|
+
file_resource.group = "wheel"
|
158
|
+
file_resource.mode = "0644"
|
159
|
+
file_resource
|
160
|
+
}
|
162
161
|
|
163
162
|
it "describes its state" do
|
164
|
-
resource_state =
|
163
|
+
resource_state = file_resource.state
|
165
164
|
expect(resource_state.keys).to match_array([:checksum, :owner, :group, :mode])
|
166
165
|
expect(resource_state[:checksum]).to eq("abc123")
|
167
166
|
expect(resource_state[:owner]).to eq("root")
|
@@ -171,157 +170,160 @@ describe Chef::Resource do
|
|
171
170
|
end
|
172
171
|
|
173
172
|
describe "load_from" do
|
173
|
+
let(:prior_resource) {
|
174
|
+
prior_resource = Chef::Resource.new("funk")
|
175
|
+
prior_resource.supports(:funky => true)
|
176
|
+
prior_resource.source_line
|
177
|
+
prior_resource.allowed_actions << :funkytown
|
178
|
+
prior_resource.action(:funkytown)
|
179
|
+
prior_resource
|
180
|
+
}
|
174
181
|
before(:each) do
|
175
|
-
|
176
|
-
|
177
|
-
@prior_resource.source_line
|
178
|
-
@prior_resource.allowed_actions << :funkytown
|
179
|
-
@prior_resource.action(:funkytown)
|
180
|
-
@resource.allowed_actions << :funkytown
|
181
|
-
@run_context.resource_collection << @prior_resource
|
182
|
+
resource.allowed_actions << :funkytown
|
183
|
+
run_context.resource_collection << prior_resource
|
182
184
|
end
|
183
185
|
|
184
186
|
it "should load the attributes of a prior resource" do
|
185
|
-
|
186
|
-
expect(
|
187
|
+
resource.load_from(prior_resource)
|
188
|
+
expect(resource.supports).to eq({ :funky => true })
|
187
189
|
end
|
188
190
|
|
189
191
|
it "should not inherit the action from the prior resource" do
|
190
|
-
|
191
|
-
expect(
|
192
|
+
resource.load_from(prior_resource)
|
193
|
+
expect(resource.action).not_to eq(prior_resource.action)
|
192
194
|
end
|
193
195
|
end
|
194
196
|
|
195
197
|
describe "name" do
|
196
198
|
it "should have a name" do
|
197
|
-
expect(
|
199
|
+
expect(resource.name).to eql("funk")
|
198
200
|
end
|
199
201
|
|
200
202
|
it "should let you set a new name" do
|
201
|
-
|
202
|
-
expect(
|
203
|
+
resource.name "monkey"
|
204
|
+
expect(resource.name).to eql("monkey")
|
203
205
|
end
|
204
206
|
|
205
207
|
it "coerces arrays to names" do
|
206
|
-
expect(
|
208
|
+
expect(resource.name ['a', 'b']).to eql('a, b')
|
207
209
|
end
|
208
210
|
|
209
211
|
it "should coerce objects to a string" do
|
210
|
-
expect(
|
212
|
+
expect(resource.name Object.new).to be_a(String)
|
211
213
|
end
|
212
214
|
end
|
213
215
|
|
214
216
|
describe "noop" do
|
215
217
|
it "should accept true or false for noop" do
|
216
|
-
expect {
|
217
|
-
expect {
|
218
|
-
expect {
|
218
|
+
expect { resource.noop true }.not_to raise_error
|
219
|
+
expect { resource.noop false }.not_to raise_error
|
220
|
+
expect { resource.noop "eat it" }.to raise_error(ArgumentError)
|
219
221
|
end
|
220
222
|
end
|
221
223
|
|
222
224
|
describe "notifies" do
|
223
225
|
it "should make notified resources appear in the actions hash" do
|
224
|
-
|
225
|
-
|
226
|
-
expect(
|
226
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
|
227
|
+
resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee")
|
228
|
+
expect(resource.delayed_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
|
227
229
|
end
|
228
230
|
|
229
231
|
it "should make notified resources be capable of acting immediately" do
|
230
|
-
|
231
|
-
|
232
|
-
expect(
|
232
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
|
233
|
+
resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee"), :immediate
|
234
|
+
expect(resource.immediate_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
|
233
235
|
end
|
234
236
|
|
235
237
|
it "should raise an exception if told to act in other than :delay or :immediate(ly)" do
|
236
|
-
|
238
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
|
237
239
|
expect {
|
238
|
-
|
240
|
+
resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee"), :someday
|
239
241
|
}.to raise_error(ArgumentError)
|
240
242
|
end
|
241
243
|
|
242
244
|
it "should allow multiple notified resources appear in the actions hash" do
|
243
|
-
|
244
|
-
|
245
|
-
expect(
|
245
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
|
246
|
+
resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee")
|
247
|
+
expect(resource.delayed_notifications.detect{|e| e.resource.name == "coffee" && e.action == :reload}).not_to be_nil
|
246
248
|
|
247
|
-
|
248
|
-
|
249
|
-
expect(
|
249
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("beans")
|
250
|
+
resource.notifies :reload, run_context.resource_collection.find(:zen_master => "beans")
|
251
|
+
expect(resource.delayed_notifications.detect{|e| e.resource.name == "beans" && e.action == :reload}).not_to be_nil
|
250
252
|
end
|
251
253
|
|
252
254
|
it "creates a notification for a resource that is not yet in the resource collection" do
|
253
|
-
|
254
|
-
expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart,
|
255
|
-
expect(
|
255
|
+
resource.notifies(:restart, :service => 'apache')
|
256
|
+
expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, resource)
|
257
|
+
expect(resource.delayed_notifications).to include(expected_notification)
|
256
258
|
end
|
257
259
|
|
258
260
|
it "notifies another resource immediately" do
|
259
|
-
|
260
|
-
expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart,
|
261
|
-
expect(
|
261
|
+
resource.notifies_immediately(:restart, :service => 'apache')
|
262
|
+
expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, resource)
|
263
|
+
expect(resource.immediate_notifications).to include(expected_notification)
|
262
264
|
end
|
263
265
|
|
264
266
|
it "notifies a resource to take action at the end of the chef run" do
|
265
|
-
|
266
|
-
expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart,
|
267
|
-
expect(
|
267
|
+
resource.notifies_delayed(:restart, :service => "apache")
|
268
|
+
expected_notification = Chef::Resource::Notification.new({:service => "apache"}, :restart, resource)
|
269
|
+
expect(resource.delayed_notifications).to include(expected_notification)
|
268
270
|
end
|
269
271
|
|
270
272
|
it "notifies a resource with an array for its name via its prettified string name" do
|
271
|
-
|
272
|
-
|
273
|
-
expect(
|
273
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new(["coffee", "tea"])
|
274
|
+
resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee, tea")
|
275
|
+
expect(resource.delayed_notifications.detect{|e| e.resource.name == "coffee, tea" && e.action == :reload}).not_to be_nil
|
274
276
|
end
|
275
277
|
end
|
276
278
|
|
277
279
|
describe "subscribes" do
|
278
280
|
it "should make resources appear in the actions hash of subscribed nodes" do
|
279
|
-
|
280
|
-
zr =
|
281
|
-
|
281
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
|
282
|
+
zr = run_context.resource_collection.find(:zen_master => "coffee")
|
283
|
+
resource.subscribes :reload, zr
|
282
284
|
expect(zr.delayed_notifications.detect{|e| e.resource.name == "funk" && e.action == :reload}).not_to be_nil
|
283
285
|
end
|
284
286
|
|
285
287
|
it "should make resources appear in the actions hash of subscribed nodes" do
|
286
|
-
|
287
|
-
zr =
|
288
|
-
|
289
|
-
expect(zr.delayed_notifications.detect{|e| e.resource.name ==
|
288
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
|
289
|
+
zr = run_context.resource_collection.find(:zen_master => "coffee")
|
290
|
+
resource.subscribes :reload, zr
|
291
|
+
expect(zr.delayed_notifications.detect{|e| e.resource.name == resource.name && e.action == :reload}).not_to be_nil
|
290
292
|
|
291
|
-
|
292
|
-
zrb =
|
293
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("bean")
|
294
|
+
zrb = run_context.resource_collection.find(:zen_master => "bean")
|
293
295
|
zrb.subscribes :reload, zr
|
294
|
-
expect(zr.delayed_notifications.detect{|e| e.resource.name ==
|
296
|
+
expect(zr.delayed_notifications.detect{|e| e.resource.name == resource.name && e.action == :reload}).not_to be_nil
|
295
297
|
end
|
296
298
|
|
297
299
|
it "should make subscribed resources be capable of acting immediately" do
|
298
|
-
|
299
|
-
zr =
|
300
|
-
|
301
|
-
expect(zr.immediate_notifications.detect{|e| e.resource.name ==
|
300
|
+
run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee")
|
301
|
+
zr = run_context.resource_collection.find(:zen_master => "coffee")
|
302
|
+
resource.subscribes :reload, zr, :immediately
|
303
|
+
expect(zr.immediate_notifications.detect{|e| e.resource.name == resource.name && e.action == :reload}).not_to be_nil
|
302
304
|
end
|
303
305
|
end
|
304
306
|
|
305
307
|
describe "defined_at" do
|
306
308
|
it "should correctly parse source_line on unix-like operating systems" do
|
307
|
-
|
308
|
-
expect(
|
309
|
+
resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
|
310
|
+
expect(resource.defined_at).to eq("/some/path/to/file.rb line 80")
|
309
311
|
end
|
310
312
|
|
311
313
|
it "should correctly parse source_line on Windows" do
|
312
|
-
|
313
|
-
expect(
|
314
|
+
resource.source_line = "C:/some/path/to/file.rb:80 in 1`wombat_tears'"
|
315
|
+
expect(resource.defined_at).to eq("C:/some/path/to/file.rb line 80")
|
314
316
|
end
|
315
317
|
|
316
318
|
it "should include the cookbook and recipe when it knows it" do
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
expect(
|
319
|
+
resource.source_line = "/some/path/to/file.rb:80:in `wombat_tears'"
|
320
|
+
resource.recipe_name = "wombats"
|
321
|
+
resource.cookbook_name = "animals"
|
322
|
+
expect(resource.defined_at).to eq("animals::wombats line 80")
|
321
323
|
end
|
322
324
|
|
323
325
|
it "should recognize dynamically defined resources" do
|
324
|
-
expect(
|
326
|
+
expect(resource.defined_at).to eq("dynamically defined")
|
325
327
|
end
|
326
328
|
end
|
327
329
|
|
@@ -345,7 +347,7 @@ describe Chef::Resource do
|
|
345
347
|
expect(r.declared_type).to eq :d
|
346
348
|
end
|
347
349
|
|
348
|
-
it "and there are no provides lines,
|
350
|
+
it "and there are no provides lines, resource_name is used" do
|
349
351
|
c = Class.new(Chef::Resource) do
|
350
352
|
def initialize(*args, &block)
|
351
353
|
@resource_name = :blah
|
@@ -419,26 +421,39 @@ describe Chef::Resource do
|
|
419
421
|
end
|
420
422
|
|
421
423
|
it "should allow arguments preceded by is to methods" do
|
422
|
-
|
423
|
-
expect(
|
424
|
+
resource.noop(resource.is(true))
|
425
|
+
expect(resource.noop).to eql(true)
|
424
426
|
end
|
425
427
|
end
|
426
428
|
|
427
429
|
describe "to_json" do
|
428
430
|
it "should serialize to json" do
|
429
|
-
json =
|
431
|
+
json = resource.to_json
|
430
432
|
expect(json).to match(/json_class/)
|
431
433
|
expect(json).to match(/instance_vars/)
|
432
434
|
end
|
433
435
|
|
434
436
|
include_examples "to_json equivalent to Chef::JSONCompat.to_json" do
|
435
|
-
let(:jsonable) {
|
437
|
+
let(:jsonable) { resource }
|
436
438
|
end
|
437
439
|
end
|
438
440
|
|
439
441
|
describe "to_hash" do
|
442
|
+
context "when the resource has a property with a default" do
|
443
|
+
let(:resource_class) { Class.new(Chef::Resource) { property :a, default: 1 } }
|
444
|
+
it "should include the default in the hash" do
|
445
|
+
expect(resource.to_hash.keys.sort).to eq([:a, :allowed_actions, :params, :provider, :updated,
|
446
|
+
:updated_by_last_action, :before, :supports,
|
447
|
+
:noop, :ignore_failure, :name, :source_line,
|
448
|
+
:action, :retries, :retry_delay, :elapsed_time,
|
449
|
+
:default_guard_interpreter, :guard_interpreter, :sensitive].sort)
|
450
|
+
expect(resource.to_hash[:name]).to eq "funk"
|
451
|
+
expect(resource.to_hash[:a]).to eq 1
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
440
455
|
it "should convert to a hash" do
|
441
|
-
hash =
|
456
|
+
hash = resource.to_hash
|
442
457
|
expected_keys = [ :allowed_actions, :params, :provider, :updated,
|
443
458
|
:updated_by_last_action, :before, :supports,
|
444
459
|
:noop, :ignore_failure, :name, :source_line,
|
@@ -452,80 +467,83 @@ describe Chef::Resource do
|
|
452
467
|
|
453
468
|
describe "self.json_create" do
|
454
469
|
it "should deserialize itself from json" do
|
455
|
-
json = Chef::JSONCompat.to_json(
|
470
|
+
json = Chef::JSONCompat.to_json(resource)
|
456
471
|
serialized_node = Chef::JSONCompat.from_json(json)
|
457
472
|
expect(serialized_node).to be_a_kind_of(Chef::Resource)
|
458
|
-
expect(serialized_node.name).to eql(
|
473
|
+
expect(serialized_node.name).to eql(resource.name)
|
459
474
|
end
|
460
475
|
end
|
461
476
|
|
462
477
|
describe "supports" do
|
463
478
|
it "should allow you to set what features this resource supports" do
|
464
479
|
support_hash = { :one => :two }
|
465
|
-
|
466
|
-
expect(
|
480
|
+
resource.supports(support_hash)
|
481
|
+
expect(resource.supports).to eql(support_hash)
|
467
482
|
end
|
468
483
|
|
469
484
|
it "should return the current value of supports" do
|
470
|
-
expect(
|
485
|
+
expect(resource.supports).to eq({})
|
471
486
|
end
|
472
487
|
end
|
473
488
|
|
474
489
|
describe "ignore_failure" do
|
475
490
|
it "should default to throwing an error if a provider fails for a resource" do
|
476
|
-
expect(
|
491
|
+
expect(resource.ignore_failure).to eq(false)
|
477
492
|
end
|
478
493
|
|
479
494
|
it "should allow you to set whether a provider should throw exceptions with ignore_failure" do
|
480
|
-
|
481
|
-
expect(
|
495
|
+
resource.ignore_failure(true)
|
496
|
+
expect(resource.ignore_failure).to eq(true)
|
482
497
|
end
|
483
498
|
|
484
499
|
it "should allow you to epic_fail" do
|
485
|
-
|
486
|
-
expect(
|
500
|
+
resource.epic_fail(true)
|
501
|
+
expect(resource.epic_fail).to eq(true)
|
487
502
|
end
|
488
503
|
end
|
489
504
|
|
490
505
|
describe "retries" do
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
506
|
+
let(:retriable_resource) {
|
507
|
+
retriable_resource = Chef::Resource::Cat.new("precious", run_context)
|
508
|
+
retriable_resource.provider = Chef::Provider::SnakeOil
|
509
|
+
retriable_resource.action = :purr
|
510
|
+
retriable_resource
|
511
|
+
}
|
495
512
|
|
496
|
-
|
497
|
-
|
513
|
+
before do
|
514
|
+
node.automatic_attrs[:platform] = "fubuntu"
|
515
|
+
node.automatic_attrs[:platform_version] = '10.04'
|
498
516
|
end
|
499
517
|
|
500
518
|
it "should default to not retrying if a provider fails for a resource" do
|
501
|
-
expect(
|
519
|
+
expect(retriable_resource.retries).to eq(0)
|
502
520
|
end
|
503
521
|
|
504
522
|
it "should allow you to set how many retries a provider should attempt after a failure" do
|
505
|
-
|
506
|
-
expect(
|
523
|
+
retriable_resource.retries(2)
|
524
|
+
expect(retriable_resource.retries).to eq(2)
|
507
525
|
end
|
508
526
|
|
509
527
|
it "should default to a retry delay of 2 seconds" do
|
510
|
-
expect(
|
528
|
+
expect(retriable_resource.retry_delay).to eq(2)
|
511
529
|
end
|
512
530
|
|
513
531
|
it "should allow you to set the retry delay" do
|
514
|
-
|
515
|
-
expect(
|
532
|
+
retriable_resource.retry_delay(10)
|
533
|
+
expect(retriable_resource.retry_delay).to eq(10)
|
516
534
|
end
|
517
535
|
|
518
536
|
it "should keep given value of retries intact after the provider fails for a resource" do
|
519
|
-
|
520
|
-
|
537
|
+
retriable_resource.retries(3)
|
538
|
+
retriable_resource.retry_delay(0) # No need to wait.
|
521
539
|
|
522
|
-
provider = Chef::Provider::SnakeOil.new(
|
540
|
+
provider = Chef::Provider::SnakeOil.new(retriable_resource, run_context)
|
523
541
|
allow(Chef::Provider::SnakeOil).to receive(:new).and_return(provider)
|
524
542
|
allow(provider).to receive(:action_purr).and_raise
|
525
543
|
|
526
|
-
expect(
|
527
|
-
expect {
|
528
|
-
expect(
|
544
|
+
expect(retriable_resource).to receive(:sleep).exactly(3).times
|
545
|
+
expect { retriable_resource.run_action(:purr) }.to raise_error
|
546
|
+
expect(retriable_resource.retries).to eq(3)
|
529
547
|
end
|
530
548
|
end
|
531
549
|
|
@@ -560,28 +578,28 @@ describe Chef::Resource do
|
|
560
578
|
|
561
579
|
describe "when updated by a provider" do
|
562
580
|
before do
|
563
|
-
|
581
|
+
resource.updated_by_last_action(true)
|
564
582
|
end
|
565
583
|
|
566
584
|
it "records that it was updated" do
|
567
|
-
expect(
|
585
|
+
expect(resource).to be_updated
|
568
586
|
end
|
569
587
|
|
570
588
|
it "records that the last action updated the resource" do
|
571
|
-
expect(
|
589
|
+
expect(resource).to be_updated_by_last_action
|
572
590
|
end
|
573
591
|
|
574
592
|
describe "and then run again without being updated" do
|
575
593
|
before do
|
576
|
-
|
594
|
+
resource.updated_by_last_action(false)
|
577
595
|
end
|
578
596
|
|
579
597
|
it "reports that it is updated" do
|
580
|
-
expect(
|
598
|
+
expect(resource).to be_updated
|
581
599
|
end
|
582
600
|
|
583
601
|
it "reports that it was not updated by the last action" do
|
584
|
-
expect(
|
602
|
+
expect(resource).not_to be_updated_by_last_action
|
585
603
|
end
|
586
604
|
|
587
605
|
end
|
@@ -589,72 +607,75 @@ describe Chef::Resource do
|
|
589
607
|
end
|
590
608
|
|
591
609
|
describe "when invoking its action" do
|
610
|
+
let(:resource) {
|
611
|
+
resource = Chef::Resource.new("provided", run_context)
|
612
|
+
resource.provider = Chef::Provider::SnakeOil
|
613
|
+
resource
|
614
|
+
}
|
592
615
|
before do
|
593
|
-
|
594
|
-
|
595
|
-
@node.automatic_attrs[:platform] = "fubuntu"
|
596
|
-
@node.automatic_attrs[:platform_version] = '10.04'
|
616
|
+
node.automatic_attrs[:platform] = "fubuntu"
|
617
|
+
node.automatic_attrs[:platform_version] = '10.04'
|
597
618
|
end
|
598
619
|
|
599
620
|
it "does not run only_if if no only_if command is given" do
|
600
621
|
expect_any_instance_of(Chef::Resource::Conditional).not_to receive(:evaluate)
|
601
|
-
|
602
|
-
|
622
|
+
resource.only_if.clear
|
623
|
+
resource.run_action(:purr)
|
603
624
|
end
|
604
625
|
|
605
626
|
it "runs runs an only_if when one is given" do
|
606
627
|
snitch_variable = nil
|
607
|
-
|
608
|
-
expect(
|
628
|
+
resource.only_if { snitch_variable = true }
|
629
|
+
expect(resource.only_if.first.positivity).to eq(:only_if)
|
609
630
|
#Chef::Mixin::Command.should_receive(:only_if).with(true, {}).and_return(false)
|
610
|
-
|
631
|
+
resource.run_action(:purr)
|
611
632
|
expect(snitch_variable).to be_truthy
|
612
633
|
end
|
613
634
|
|
614
635
|
it "runs multiple only_if conditionals" do
|
615
636
|
snitch_var1, snitch_var2 = nil, nil
|
616
|
-
|
617
|
-
|
618
|
-
|
637
|
+
resource.only_if { snitch_var1 = 1 }
|
638
|
+
resource.only_if { snitch_var2 = 2 }
|
639
|
+
resource.run_action(:purr)
|
619
640
|
expect(snitch_var1).to eq(1)
|
620
641
|
expect(snitch_var2).to eq(2)
|
621
642
|
end
|
622
643
|
|
623
644
|
it "accepts command options for only_if conditionals" do
|
624
645
|
expect_any_instance_of(Chef::Resource::Conditional).to receive(:evaluate_command).at_least(1).times
|
625
|
-
|
626
|
-
expect(
|
627
|
-
|
646
|
+
resource.only_if("true", :cwd => '/tmp')
|
647
|
+
expect(resource.only_if.first.command_opts).to eq({:cwd => '/tmp'})
|
648
|
+
resource.run_action(:purr)
|
628
649
|
end
|
629
650
|
|
630
651
|
it "runs not_if as a command when it is a string" do
|
631
652
|
expect_any_instance_of(Chef::Resource::Conditional).to receive(:evaluate_command).at_least(1).times
|
632
|
-
|
633
|
-
|
653
|
+
resource.not_if "pwd"
|
654
|
+
resource.run_action(:purr)
|
634
655
|
end
|
635
656
|
|
636
657
|
it "runs not_if as a block when it is a ruby block" do
|
637
658
|
expect_any_instance_of(Chef::Resource::Conditional).to receive(:evaluate_block).at_least(1).times
|
638
|
-
|
639
|
-
|
659
|
+
resource.not_if { puts 'foo' }
|
660
|
+
resource.run_action(:purr)
|
640
661
|
end
|
641
662
|
|
642
663
|
it "does not run not_if if no not_if command is given" do
|
643
664
|
expect_any_instance_of(Chef::Resource::Conditional).not_to receive(:evaluate)
|
644
|
-
|
645
|
-
|
665
|
+
resource.not_if.clear
|
666
|
+
resource.run_action(:purr)
|
646
667
|
end
|
647
668
|
|
648
669
|
it "accepts command options for not_if conditionals" do
|
649
|
-
|
650
|
-
expect(
|
670
|
+
resource.not_if("pwd" , :cwd => '/tmp')
|
671
|
+
expect(resource.not_if.first.command_opts).to eq({:cwd => '/tmp'})
|
651
672
|
end
|
652
673
|
|
653
674
|
it "accepts multiple not_if conditionals" do
|
654
675
|
snitch_var1, snitch_var2 = true, true
|
655
|
-
|
656
|
-
|
657
|
-
|
676
|
+
resource.not_if {snitch_var1 = nil}
|
677
|
+
resource.not_if {snitch_var2 = false}
|
678
|
+
resource.run_action(:purr)
|
658
679
|
expect(snitch_var1).to be_nil
|
659
680
|
expect(snitch_var2).to be_falsey
|
660
681
|
end
|
@@ -662,13 +683,11 @@ describe Chef::Resource do
|
|
662
683
|
it "reports 0 elapsed time if actual elapsed time is < 0" do
|
663
684
|
expected = Time.now
|
664
685
|
allow(Time).to receive(:now).and_return(expected, expected - 1)
|
665
|
-
|
666
|
-
expect(
|
686
|
+
resource.run_action(:purr)
|
687
|
+
expect(resource.elapsed_time).to eq(0)
|
667
688
|
end
|
668
689
|
|
669
690
|
describe "guard_interpreter attribute" do
|
670
|
-
let(:resource) { @resource }
|
671
|
-
|
672
691
|
it "should be set to :default by default" do
|
673
692
|
expect(resource.guard_interpreter).to eq(:default)
|
674
693
|
end
|
@@ -691,106 +710,108 @@ describe Chef::Resource do
|
|
691
710
|
|
692
711
|
describe "should_skip?" do
|
693
712
|
before do
|
694
|
-
|
713
|
+
resource = Chef::Resource::Cat.new("sugar", run_context)
|
695
714
|
end
|
696
715
|
|
697
716
|
it "should return false by default" do
|
698
|
-
expect(
|
717
|
+
expect(resource.should_skip?(:purr)).to be_falsey
|
699
718
|
end
|
700
719
|
|
701
720
|
it "should return false when only_if is met" do
|
702
|
-
|
703
|
-
expect(
|
721
|
+
resource.only_if { true }
|
722
|
+
expect(resource.should_skip?(:purr)).to be_falsey
|
704
723
|
end
|
705
724
|
|
706
725
|
it "should return true when only_if is not met" do
|
707
|
-
|
708
|
-
expect(
|
726
|
+
resource.only_if { false }
|
727
|
+
expect(resource.should_skip?(:purr)).to be_truthy
|
709
728
|
end
|
710
729
|
|
711
730
|
it "should return true when not_if is met" do
|
712
|
-
|
713
|
-
expect(
|
731
|
+
resource.not_if { true }
|
732
|
+
expect(resource.should_skip?(:purr)).to be_truthy
|
714
733
|
end
|
715
734
|
|
716
735
|
it "should return false when not_if is not met" do
|
717
|
-
|
718
|
-
expect(
|
736
|
+
resource.not_if { false }
|
737
|
+
expect(resource.should_skip?(:purr)).to be_falsey
|
719
738
|
end
|
720
739
|
|
721
740
|
it "should return true when only_if is met but also not_if is met" do
|
722
|
-
|
723
|
-
|
724
|
-
expect(
|
741
|
+
resource.only_if { true }
|
742
|
+
resource.not_if { true }
|
743
|
+
expect(resource.should_skip?(:purr)).to be_truthy
|
725
744
|
end
|
726
745
|
|
727
746
|
it "should return true when one of multiple only_if's is not met" do
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
expect(
|
747
|
+
resource.only_if { true }
|
748
|
+
resource.only_if { false }
|
749
|
+
resource.only_if { true }
|
750
|
+
expect(resource.should_skip?(:purr)).to be_truthy
|
732
751
|
end
|
733
752
|
|
734
753
|
it "should return true when one of multiple not_if's is met" do
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
expect(
|
754
|
+
resource.not_if { false }
|
755
|
+
resource.not_if { true }
|
756
|
+
resource.not_if { false }
|
757
|
+
expect(resource.should_skip?(:purr)).to be_truthy
|
739
758
|
end
|
740
759
|
|
741
760
|
it "should return true when action is :nothing" do
|
742
|
-
expect(
|
761
|
+
expect(resource.should_skip?(:nothing)).to be_truthy
|
743
762
|
end
|
744
763
|
|
745
764
|
it "should return true when action is :nothing ignoring only_if/not_if conditionals" do
|
746
|
-
|
747
|
-
|
748
|
-
expect(
|
765
|
+
resource.only_if { true }
|
766
|
+
resource.not_if { false }
|
767
|
+
expect(resource.should_skip?(:nothing)).to be_truthy
|
749
768
|
end
|
750
769
|
|
751
770
|
it "should print \"skipped due to action :nothing\" message for doc formatter when action is :nothing" do
|
752
771
|
fdoc = Chef::Formatters.new(:doc, STDOUT, STDERR)
|
753
|
-
allow(
|
772
|
+
allow(run_context).to receive(:events).and_return(fdoc)
|
754
773
|
expect(fdoc).to receive(:puts).with(" (skipped due to action :nothing)", anything())
|
755
|
-
|
774
|
+
resource.should_skip?(:nothing)
|
756
775
|
end
|
757
776
|
|
758
777
|
end
|
759
778
|
|
760
779
|
describe "when resource action is :nothing" do
|
780
|
+
let(:resource1) {
|
781
|
+
resource1 = Chef::Resource::Cat.new("sugar", run_context)
|
782
|
+
resource1.action = :nothing
|
783
|
+
resource1
|
784
|
+
}
|
761
785
|
before do
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
@node.automatic_attrs[:platform] = "fubuntu"
|
766
|
-
@node.automatic_attrs[:platform_version] = '10.04'
|
786
|
+
node.automatic_attrs[:platform] = "fubuntu"
|
787
|
+
node.automatic_attrs[:platform_version] = '10.04'
|
767
788
|
end
|
768
789
|
|
769
790
|
it "should not run only_if/not_if conditionals (CHEF-972)" do
|
770
791
|
snitch_var1 = 0
|
771
|
-
|
772
|
-
|
773
|
-
|
792
|
+
resource1.only_if { snitch_var1 = 1 }
|
793
|
+
resource1.not_if { snitch_var1 = 2 }
|
794
|
+
resource1.run_action(:nothing)
|
774
795
|
expect(snitch_var1).to eq(0)
|
775
796
|
end
|
776
797
|
|
777
798
|
it "should run only_if/not_if conditionals when notified to run another action (CHEF-972)" do
|
778
799
|
snitch_var1 = snitch_var2 = 0
|
779
|
-
|
800
|
+
runner = Chef::Runner.new(run_context)
|
780
801
|
Chef::Platform.set(
|
781
802
|
:resource => :cat,
|
782
803
|
:provider => Chef::Provider::SnakeOil
|
783
804
|
)
|
784
805
|
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
806
|
+
resource1.only_if { snitch_var1 = 1 }
|
807
|
+
resource1.not_if { snitch_var2 = 2 }
|
808
|
+
resource2 = Chef::Resource::Cat.new("coffee", run_context)
|
809
|
+
resource2.notifies :purr, resource1
|
810
|
+
resource2.action = :purr
|
790
811
|
|
791
|
-
|
792
|
-
|
793
|
-
|
812
|
+
run_context.resource_collection << resource1
|
813
|
+
run_context.resource_collection << resource2
|
814
|
+
runner.converge
|
794
815
|
|
795
816
|
expect(snitch_var1).to eq(1)
|
796
817
|
expect(snitch_var2).to eq(2)
|
@@ -838,10 +859,10 @@ describe Chef::Resource do
|
|
838
859
|
|
839
860
|
before(:each) do
|
840
861
|
Chef::Resource::Klz1 = klz1
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
862
|
+
node = Chef::Node.new
|
863
|
+
node.name("bumblebee")
|
864
|
+
node.automatic[:platform] = "autobots"
|
865
|
+
node.automatic[:platform_version] = "6.1"
|
845
866
|
Object.const_set('Soundwave', klz1)
|
846
867
|
klz1.provides :soundwave
|
847
868
|
end
|
@@ -852,7 +873,7 @@ describe Chef::Resource do
|
|
852
873
|
end
|
853
874
|
|
854
875
|
it "returns a resource by short_name if nothing else matches" do
|
855
|
-
expect(Chef::Resource.resource_for_node(:soundwave,
|
876
|
+
expect(Chef::Resource.resource_for_node(:soundwave, node)).to eql(klz1)
|
856
877
|
end
|
857
878
|
end
|
858
879
|
|
@@ -861,10 +882,9 @@ describe Chef::Resource do
|
|
861
882
|
|
862
883
|
before(:each) do
|
863
884
|
Chef::Resource::Klz2 = klz2
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
@node.automatic[:platform_version] = "6.1"
|
885
|
+
node.name("bumblebee")
|
886
|
+
node.automatic[:platform] = "autobots"
|
887
|
+
node.automatic[:platform_version] = "6.1"
|
868
888
|
klz2.provides :dinobot, :platform => ['autobots']
|
869
889
|
Object.const_set('Grimlock', klz2)
|
870
890
|
klz2.provides :grimlock
|
@@ -876,7 +896,7 @@ describe Chef::Resource do
|
|
876
896
|
end
|
877
897
|
|
878
898
|
it "returns a resource by short_name and node" do
|
879
|
-
expect(Chef::Resource.resource_for_node(:dinobot,
|
899
|
+
expect(Chef::Resource.resource_for_node(:dinobot, node)).to eql(klz2)
|
880
900
|
end
|
881
901
|
end
|
882
902
|
|
@@ -887,69 +907,64 @@ describe Chef::Resource do
|
|
887
907
|
describe "with a string resource spec" do
|
888
908
|
|
889
909
|
it "creates a delayed notification when timing is not specified" do
|
890
|
-
|
891
|
-
expect(
|
910
|
+
resource.notifies(:run, "execute[foo]")
|
911
|
+
expect(run_context.delayed_notification_collection.size).to eq(1)
|
892
912
|
end
|
893
913
|
|
894
914
|
it "creates a delayed notification when :delayed is not specified" do
|
895
|
-
|
896
|
-
expect(
|
915
|
+
resource.notifies(:run, "execute[foo]", :delayed)
|
916
|
+
expect(run_context.delayed_notification_collection.size).to eq(1)
|
897
917
|
end
|
898
918
|
|
899
919
|
it "creates an immediate notification when :immediate is specified" do
|
900
|
-
|
901
|
-
expect(
|
920
|
+
resource.notifies(:run, "execute[foo]", :immediate)
|
921
|
+
expect(run_context.immediate_notification_collection.size).to eq(1)
|
902
922
|
end
|
903
923
|
|
904
924
|
it "creates an immediate notification when :immediately is specified" do
|
905
|
-
|
906
|
-
expect(
|
925
|
+
resource.notifies(:run, "execute[foo]", :immediately)
|
926
|
+
expect(run_context.immediate_notification_collection.size).to eq(1)
|
907
927
|
end
|
908
928
|
|
909
929
|
describe "with a syntax error in the resource spec" do
|
910
930
|
|
911
931
|
it "raises an exception immmediately" do
|
912
932
|
expect do
|
913
|
-
|
933
|
+
resource.notifies(:run, "typo[missing-closing-bracket")
|
914
934
|
end.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
|
915
935
|
end
|
916
936
|
end
|
917
937
|
end
|
918
938
|
|
919
939
|
describe "with a resource reference" do
|
920
|
-
|
921
|
-
@notified_resource = Chef::Resource.new("punk", @run_context)
|
922
|
-
end
|
940
|
+
let(:notified_resource) { Chef::Resource.new("punk", run_context) }
|
923
941
|
|
924
942
|
it "creates a delayed notification when timing is not specified" do
|
925
|
-
|
926
|
-
expect(
|
943
|
+
resource.notifies(:run, notified_resource)
|
944
|
+
expect(run_context.delayed_notification_collection.size).to eq(1)
|
927
945
|
end
|
928
946
|
|
929
947
|
it "creates a delayed notification when :delayed is not specified" do
|
930
|
-
|
931
|
-
expect(
|
948
|
+
resource.notifies(:run, notified_resource, :delayed)
|
949
|
+
expect(run_context.delayed_notification_collection.size).to eq(1)
|
932
950
|
end
|
933
951
|
|
934
952
|
it "creates an immediate notification when :immediate is specified" do
|
935
|
-
|
936
|
-
expect(
|
953
|
+
resource.notifies(:run, notified_resource, :immediate)
|
954
|
+
expect(run_context.immediate_notification_collection.size).to eq(1)
|
937
955
|
end
|
938
956
|
|
939
957
|
it "creates an immediate notification when :immediately is specified" do
|
940
|
-
|
941
|
-
expect(
|
958
|
+
resource.notifies(:run, notified_resource, :immediately)
|
959
|
+
expect(run_context.immediate_notification_collection.size).to eq(1)
|
942
960
|
end
|
943
961
|
end
|
944
962
|
|
945
963
|
end
|
946
964
|
|
947
965
|
describe "resource sensitive attribute" do
|
948
|
-
|
949
|
-
|
950
|
-
@resource_file = Chef::Resource::File.new("/nonexistent/CHEF-5098/file", @run_context)
|
951
|
-
@action = :create
|
952
|
-
end
|
966
|
+
let(:resource_file) { Chef::Resource::File.new("/nonexistent/CHEF-5098/file", run_context) }
|
967
|
+
let(:action) { :create }
|
953
968
|
|
954
969
|
def compiled_resource_data(resource, action, err)
|
955
970
|
error_inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(resource, action, err)
|
@@ -960,19 +975,19 @@ describe Chef::Resource do
|
|
960
975
|
end
|
961
976
|
|
962
977
|
it "set to false by default" do
|
963
|
-
expect(
|
978
|
+
expect(resource.sensitive).to be_falsey
|
964
979
|
end
|
965
980
|
|
966
981
|
it "when set to false should show compiled resource for failed resource" do
|
967
|
-
expect {
|
968
|
-
expect(compiled_resource_data(
|
982
|
+
expect { resource_file.run_action(action) }.to raise_error { |err|
|
983
|
+
expect(compiled_resource_data(resource_file, action, err)).to match 'path "/nonexistent/CHEF-5098/file"'
|
969
984
|
}
|
970
985
|
end
|
971
986
|
|
972
987
|
it "when set to true should show compiled resource for failed resource" do
|
973
|
-
|
974
|
-
expect {
|
975
|
-
expect(compiled_resource_data(
|
988
|
+
resource_file.sensitive true
|
989
|
+
expect { resource_file.run_action(action) }.to raise_error { |err|
|
990
|
+
expect(compiled_resource_data(resource_file, action, err)).to eql("suppressed sensitive resource output")
|
976
991
|
}
|
977
992
|
end
|
978
993
|
|