chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -1
- data/lib/chef/api_client.rb +130 -26
- data/lib/chef/application.rb +0 -1
- data/lib/chef/application/client.rb +8 -19
- data/lib/chef/audit/audit_reporter.rb +12 -7
- data/lib/chef/audit/logger.rb +36 -0
- data/lib/chef/audit/runner.rb +4 -2
- data/lib/chef/chef_class.rb +62 -11
- data/lib/chef/client.rb +587 -207
- data/lib/chef/config.rb +0 -1
- data/lib/chef/dsl/recipe.rb +45 -56
- data/lib/chef/dsl/resources.rb +3 -2
- data/lib/chef/event_dispatch/base.rb +7 -2
- data/lib/chef/exceptions.rb +4 -1
- data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
- data/lib/chef/formatters/doc.rb +15 -7
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
- data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
- data/lib/chef/http/authenticator.rb +7 -2
- data/lib/chef/knife.rb +16 -4
- data/lib/chef/knife/client_create.rb +55 -31
- data/lib/chef/knife/core/generic_presenter.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/osc_user_create.rb +97 -0
- data/lib/chef/knife/osc_user_delete.rb +51 -0
- data/lib/chef/knife/osc_user_edit.rb +58 -0
- data/lib/chef/knife/osc_user_list.rb +47 -0
- data/lib/chef/knife/osc_user_reregister.rb +64 -0
- data/lib/chef/knife/osc_user_show.rb +54 -0
- data/lib/chef/knife/user_create.rb +95 -36
- data/lib/chef/knife/user_delete.rb +52 -2
- data/lib/chef/knife/user_edit.rb +37 -7
- data/lib/chef/knife/user_list.rb +3 -0
- data/lib/chef/knife/user_reregister.rb +39 -8
- data/lib/chef/knife/user_show.rb +30 -1
- data/lib/chef/mixin/api_version_request_handling.rb +66 -0
- data/lib/chef/mixin/convert_to_class_name.rb +10 -4
- data/lib/chef/mixin/deprecation.rb +24 -0
- data/lib/chef/mixin/powershell_out.rb +98 -0
- data/lib/chef/mixin/provides.rb +5 -18
- data/lib/chef/mixin/uris.rb +11 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
- data/lib/chef/mixin/windows_env_helper.rb +11 -2
- data/lib/chef/node_map.rb +130 -75
- data/lib/chef/osc_user.rb +194 -0
- data/lib/chef/platform/provider_mapping.rb +2 -269
- data/lib/chef/platform/provider_priority_map.rb +6 -69
- data/lib/chef/platform/query_helpers.rb +5 -0
- data/lib/chef/platform/resource_priority_map.rb +12 -15
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/provider.rb +19 -0
- data/lib/chef/provider/directory.rb +3 -0
- data/lib/chef/provider/dsc_resource.rb +8 -1
- data/lib/chef/provider/file.rb +1 -0
- data/lib/chef/provider/group/aix.rb +1 -0
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/group/gpasswd.rb +1 -0
- data/lib/chef/provider/group/groupmod.rb +1 -1
- data/lib/chef/provider/group/pw.rb +1 -0
- data/lib/chef/provider/group/suse.rb +2 -0
- data/lib/chef/provider/group/usermod.rb +2 -1
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -0
- data/lib/chef/provider/ifconfig/aix.rb +1 -0
- data/lib/chef/provider/ifconfig/debian.rb +2 -0
- data/lib/chef/provider/ifconfig/redhat.rb +1 -0
- data/lib/chef/provider/lwrp_base.rb +4 -0
- data/lib/chef/provider/mount.rb +0 -1
- data/lib/chef/provider/mount/aix.rb +1 -0
- data/lib/chef/provider/mount/mount.rb +2 -0
- data/lib/chef/provider/mount/solaris.rb +2 -0
- data/lib/chef/provider/package.rb +55 -0
- data/lib/chef/provider/package/aix.rb +7 -7
- data/lib/chef/provider/package/apt.rb +3 -3
- data/lib/chef/provider/package/dpkg.rb +4 -4
- data/lib/chef/provider/package/easy_install.rb +5 -5
- data/lib/chef/provider/package/freebsd/base.rb +2 -2
- data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
- data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
- data/lib/chef/provider/package/freebsd/port.rb +4 -4
- data/lib/chef/provider/package/homebrew.rb +2 -2
- data/lib/chef/provider/package/ips.rb +4 -4
- data/lib/chef/provider/package/macports.rb +5 -6
- data/lib/chef/provider/package/openbsd.rb +4 -5
- data/lib/chef/provider/package/pacman.rb +4 -4
- data/lib/chef/provider/package/portage.rb +2 -0
- data/lib/chef/provider/package/rpm.rb +7 -8
- data/lib/chef/provider/package/rubygems.rb +5 -12
- data/lib/chef/provider/package/smartos.rb +4 -4
- data/lib/chef/provider/package/solaris.rb +7 -7
- data/lib/chef/provider/package/windows/msi.rb +1 -1
- data/lib/chef/provider/package/yum.rb +4 -6
- data/lib/chef/provider/package/zypper.rb +16 -14
- data/lib/chef/provider/powershell_script.rb +129 -47
- data/lib/chef/provider/remote_file/content.rb +4 -1
- data/lib/chef/provider/remote_file/local_file.rb +10 -4
- data/lib/chef/provider/service.rb +44 -0
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/init.rb +1 -0
- data/lib/chef/provider/service/macosx.rb +1 -1
- data/lib/chef/provider/service/windows.rb +0 -1
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/aix.rb +3 -2
- data/lib/chef/provider/user/pw.rb +1 -0
- data/lib/chef/provider/user/solaris.rb +2 -0
- data/lib/chef/provider/user/useradd.rb +1 -0
- data/lib/chef/provider_resolver.rb +87 -134
- data/lib/chef/resource.rb +274 -68
- data/lib/chef/resource/apt_package.rb +0 -2
- data/lib/chef/resource/bash.rb +0 -2
- data/lib/chef/resource/batch.rb +1 -1
- data/lib/chef/resource/bff_package.rb +0 -7
- data/lib/chef/resource/breakpoint.rb +3 -6
- data/lib/chef/resource/chef_gem.rb +0 -3
- data/lib/chef/resource/cookbook_file.rb +1 -3
- data/lib/chef/resource/cron.rb +2 -4
- data/lib/chef/resource/csh.rb +0 -2
- data/lib/chef/resource/deploy.rb +9 -6
- data/lib/chef/resource/deploy_revision.rb +0 -14
- data/lib/chef/resource/directory.rb +2 -4
- data/lib/chef/resource/dpkg_package.rb +0 -5
- data/lib/chef/resource/dsc_resource.rb +2 -3
- data/lib/chef/resource/dsc_script.rb +2 -3
- data/lib/chef/resource/easy_install_package.rb +0 -7
- data/lib/chef/resource/env.rb +3 -3
- data/lib/chef/resource/erl_call.rb +2 -5
- data/lib/chef/resource/execute.rb +2 -4
- data/lib/chef/resource/file.rb +2 -4
- data/lib/chef/resource/freebsd_package.rb +0 -5
- data/lib/chef/resource/gem_package.rb +0 -3
- data/lib/chef/resource/git.rb +0 -3
- data/lib/chef/resource/group.rb +2 -4
- data/lib/chef/resource/homebrew_package.rb +0 -2
- data/lib/chef/resource/http_request.rb +3 -4
- data/lib/chef/resource/ifconfig.rb +3 -4
- data/lib/chef/resource/ips_package.rb +2 -2
- data/lib/chef/resource/link.rb +3 -5
- data/lib/chef/resource/log.rb +2 -4
- data/lib/chef/resource/lwrp_base.rb +10 -61
- data/lib/chef/resource/macosx_service.rb +1 -2
- data/lib/chef/resource/macports_package.rb +0 -7
- data/lib/chef/resource/mdadm.rb +2 -5
- data/lib/chef/resource/mount.rb +2 -4
- data/lib/chef/resource/ohai.rb +2 -4
- data/lib/chef/resource/openbsd_package.rb +0 -6
- data/lib/chef/resource/package.rb +9 -6
- data/lib/chef/resource/pacman_package.rb +0 -7
- data/lib/chef/resource/paludis_package.rb +2 -3
- data/lib/chef/resource/perl.rb +0 -3
- data/lib/chef/resource/portage_package.rb +0 -3
- data/lib/chef/resource/powershell_script.rb +1 -2
- data/lib/chef/resource/python.rb +0 -3
- data/lib/chef/resource/reboot.rb +1 -3
- data/lib/chef/resource/registry_key.rb +3 -5
- data/lib/chef/resource/remote_directory.rb +3 -5
- data/lib/chef/resource/remote_file.rb +4 -5
- data/lib/chef/resource/route.rb +3 -5
- data/lib/chef/resource/rpm_package.rb +0 -2
- data/lib/chef/resource/ruby.rb +0 -4
- data/lib/chef/resource/ruby_block.rb +2 -4
- data/lib/chef/resource/scm.rb +3 -5
- data/lib/chef/resource/script.rb +0 -3
- data/lib/chef/resource/service.rb +3 -5
- data/lib/chef/resource/smartos_package.rb +0 -9
- data/lib/chef/resource/solaris_package.rb +0 -10
- data/lib/chef/resource/subversion.rb +1 -3
- data/lib/chef/resource/template.rb +0 -4
- data/lib/chef/resource/timestamped_deploy.rb +0 -4
- data/lib/chef/resource/user.rb +2 -5
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
- data/lib/chef/resource/windows_package.rb +3 -3
- data/lib/chef/resource/windows_script.rb +2 -2
- data/lib/chef/resource/windows_service.rb +3 -3
- data/lib/chef/resource/yum_package.rb +0 -3
- data/lib/chef/resource/zypper_package.rb +27 -0
- data/lib/chef/resource_builder.rb +7 -0
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resource_resolver.rb +108 -62
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/rest.rb +1 -0
- data/lib/chef/server_api.rb +2 -0
- data/lib/chef/user.rb +193 -42
- data/lib/chef/util/backup.rb +9 -1
- data/lib/chef/util/path_helper.rb +0 -1
- data/lib/chef/version.rb +1 -1
- data/spec/functional/audit/runner_spec.rb +22 -42
- data/spec/functional/mixin/powershell_out_spec.rb +43 -0
- data/spec/functional/resource/execute_spec.rb +9 -2
- data/spec/functional/resource/file_spec.rb +25 -0
- data/spec/functional/resource/group_spec.rb +5 -0
- data/spec/functional/resource/link_spec.rb +5 -11
- data/spec/functional/resource/powershell_spec.rb +40 -5
- data/spec/functional/resource/user/useradd_spec.rb +10 -18
- data/spec/integration/recipes/lwrp_spec.rb +57 -0
- data/spec/integration/recipes/provider_choice.rb +2 -7
- data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
- data/spec/spec_helper.rb +1 -1
- data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
- data/spec/support/lib/chef/resource/cat.rb +0 -2
- data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
- data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
- data/spec/support/lib/chef/resource/with_state.rb +0 -9
- data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
- data/spec/support/lib/chef/resource/zen_master.rb +1 -6
- data/spec/support/shared/context/client.rb +277 -0
- data/spec/support/shared/examples/client.rb +53 -0
- data/spec/support/shared/functional/file_resource.rb +0 -4
- data/spec/support/shared/functional/securable_resource.rb +0 -24
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
- data/spec/support/shared/functional/windows_script.rb +1 -1
- data/spec/support/shared/unit/api_versioning.rb +77 -0
- data/spec/support/shared/unit/knife_shared.rb +40 -0
- data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
- data/spec/unit/api_client_spec.rb +189 -14
- data/spec/unit/application/client_spec.rb +0 -5
- data/spec/unit/audit/audit_reporter_spec.rb +58 -14
- data/spec/unit/audit/logger_spec.rb +42 -0
- data/spec/unit/audit/runner_spec.rb +2 -2
- data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
- data/spec/unit/client_spec.rb +58 -374
- data/spec/unit/cookbook_spec.rb +0 -9
- data/spec/unit/cookbook_version_spec.rb +0 -20
- data/spec/unit/deprecation_spec.rb +55 -0
- data/spec/unit/dsl/resources_spec.rb +85 -0
- data/spec/unit/exceptions_spec.rb +2 -2
- data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
- data/spec/unit/formatters/doc_spec.rb +46 -0
- data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
- data/spec/unit/http/authenticator_spec.rb +11 -2
- data/spec/unit/knife/client_create_spec.rb +122 -51
- data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
- data/spec/unit/knife/core/ui_spec.rb +14 -0
- data/spec/unit/knife/osc_user_create_spec.rb +93 -0
- data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
- data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
- data/spec/unit/knife/osc_user_list_spec.rb +37 -0
- data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
- data/spec/unit/knife/osc_user_show_spec.rb +46 -0
- data/spec/unit/knife/user_create_spec.rb +177 -51
- data/spec/unit/knife/user_delete_spec.rb +34 -8
- data/spec/unit/knife/user_edit_spec.rb +31 -12
- data/spec/unit/knife/user_list_spec.rb +7 -3
- data/spec/unit/knife/user_reregister_spec.rb +38 -17
- data/spec/unit/knife/user_show_spec.rb +35 -11
- data/spec/unit/knife_spec.rb +10 -4
- data/spec/unit/lwrp_spec.rb +228 -54
- data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
- data/spec/unit/mixin/command_spec.rb +1 -2
- data/spec/unit/mixin/powershell_out_spec.rb +70 -0
- data/spec/unit/mixin/uris_spec.rb +23 -11
- data/spec/unit/node_map_spec.rb +4 -1
- data/spec/unit/osc_user_spec.rb +276 -0
- data/spec/unit/platform_spec.rb +0 -60
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +199 -135
- data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
- data/spec/unit/provider/package/aix_spec.rb +16 -16
- data/spec/unit/provider/package/dpkg_spec.rb +2 -2
- data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
- data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
- data/spec/unit/provider/package/ips_spec.rb +22 -22
- data/spec/unit/provider/package/macports_spec.rb +10 -10
- data/spec/unit/provider/package/openbsd_spec.rb +4 -26
- data/spec/unit/provider/package/pacman_spec.rb +5 -5
- data/spec/unit/provider/package/rpm_spec.rb +14 -14
- data/spec/unit/provider/package/rubygems_spec.rb +10 -44
- data/spec/unit/provider/package/smartos_spec.rb +4 -4
- data/spec/unit/provider/package/solaris_spec.rb +11 -11
- data/spec/unit/provider/package/zypper_spec.rb +125 -90
- data/spec/unit/provider/package_spec.rb +34 -0
- data/spec/unit/provider/powershell_spec.rb +53 -11
- data/spec/unit/provider/remote_directory_spec.rb +2 -2
- data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
- data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
- data/spec/unit/provider/user_spec.rb +3 -3
- data/spec/unit/provider_resolver_spec.rb +463 -327
- data/spec/unit/recipe_spec.rb +42 -15
- data/spec/unit/resource/breakpoint_spec.rb +1 -1
- data/spec/unit/resource/erl_call_spec.rb +1 -1
- data/spec/unit/resource/file_spec.rb +1 -1
- data/spec/unit/resource/ifconfig_spec.rb +10 -6
- data/spec/unit/resource/remote_file_spec.rb +5 -0
- data/spec/unit/resource/route_spec.rb +1 -1
- data/spec/unit/resource/ruby_block_spec.rb +2 -2
- data/spec/unit/resource/template_spec.rb +1 -1
- data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
- data/spec/unit/resource/windows_service_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +99 -13
- data/spec/unit/rest_spec.rb +5 -5
- data/spec/unit/run_context_spec.rb +41 -0
- data/spec/unit/runner_spec.rb +2 -2
- data/spec/unit/user_spec.rb +406 -93
- data/tasks/maintainers.rb +69 -0
- metadata +37 -4
@@ -165,11 +165,6 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
|
|
165
165
|
before do
|
166
166
|
allow(Chef::Log).to receive(:warn)
|
167
167
|
end
|
168
|
-
|
169
|
-
it "emits a warning that audit mode is an experimental feature" do
|
170
|
-
expect(Chef::Log).to receive(:warn).with(/Audit mode is an experimental feature/)
|
171
|
-
app.reconfigure
|
172
|
-
end
|
173
168
|
end
|
174
169
|
|
175
170
|
shared_examples "unrecognized setting" do
|
@@ -88,6 +88,29 @@ describe Chef::Audit::AuditReporter do
|
|
88
88
|
reporter.run_completed(node)
|
89
89
|
end
|
90
90
|
|
91
|
+
context "when audit phase failed" do
|
92
|
+
|
93
|
+
let(:audit_error) { double("AuditError", :class => "Chef::Exceptions::AuditError",
|
94
|
+
:message => "Audit phase failed with error message: derpderpderp",
|
95
|
+
:backtrace => ["/path/recipe.rb:57", "/path/library.rb:106"]) }
|
96
|
+
|
97
|
+
before do
|
98
|
+
reporter.instance_variable_set(:@audit_phase_error, audit_error)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "reports an error" do
|
102
|
+
reporter.run_completed(node)
|
103
|
+
expect(run_data).to have_key(:error)
|
104
|
+
expect(run_data).to have_key(:error)
|
105
|
+
expect(run_data[:error]).to eq <<-EOM.strip!
|
106
|
+
Chef::Exceptions::AuditError: Audit phase failed with error message: derpderpderp
|
107
|
+
/path/recipe.rb:57
|
108
|
+
/path/library.rb:106
|
109
|
+
EOM
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
91
114
|
context "when unable to post to server" do
|
92
115
|
|
93
116
|
let(:error) do
|
@@ -215,9 +238,13 @@ describe Chef::Audit::AuditReporter do
|
|
215
238
|
let(:audit_data) { Chef::Audit::AuditData.new(node.name, run_id) }
|
216
239
|
let(:run_data) { audit_data.to_hash }
|
217
240
|
|
218
|
-
let(:
|
219
|
-
:message => "
|
220
|
-
:backtrace => ["
|
241
|
+
let(:audit_error) { double("AuditError", :class => "Chef::Exceptions::AuditError",
|
242
|
+
:message => "Audit phase failed with error message: derpderpderp",
|
243
|
+
:backtrace => ["/path/recipe.rb:57", "/path/library.rb:106"]) }
|
244
|
+
|
245
|
+
let(:run_error) { double("RunError", :class => "Chef::Exceptions::RunError",
|
246
|
+
:message => "This error shouldn't be reported.",
|
247
|
+
:backtrace => ["fix it", "fix it", "fix it"]) }
|
221
248
|
|
222
249
|
before do
|
223
250
|
allow(reporter).to receive(:auditing_enabled?).and_return(true)
|
@@ -226,15 +253,32 @@ describe Chef::Audit::AuditReporter do
|
|
226
253
|
allow(audit_data).to receive(:to_hash).and_return(run_data)
|
227
254
|
end
|
228
255
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
256
|
+
context "when no prior exception is stored" do
|
257
|
+
it "reports no error" do
|
258
|
+
expect(rest).to receive(:create_url)
|
259
|
+
expect(rest).to receive(:post)
|
260
|
+
reporter.run_failed(run_error)
|
261
|
+
expect(run_data).to_not have_key(:error)
|
262
|
+
end
|
236
263
|
end
|
237
264
|
|
265
|
+
context "when some prior exception is stored" do
|
266
|
+
before do
|
267
|
+
reporter.instance_variable_set(:@audit_phase_error, audit_error)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "reports the prior error" do
|
271
|
+
expect(rest).to receive(:create_url)
|
272
|
+
expect(rest).to receive(:post)
|
273
|
+
reporter.run_failed(run_error)
|
274
|
+
expect(run_data).to have_key(:error)
|
275
|
+
expect(run_data[:error]).to eq <<-EOM.strip!
|
276
|
+
Chef::Exceptions::AuditError: Audit phase failed with error message: derpderpderp
|
277
|
+
/path/recipe.rb:57
|
278
|
+
/path/library.rb:106
|
279
|
+
EOM
|
280
|
+
end
|
281
|
+
end
|
238
282
|
end
|
239
283
|
|
240
284
|
shared_context "audit data" do
|
@@ -270,14 +314,14 @@ describe Chef::Audit::AuditReporter do
|
|
270
314
|
|
271
315
|
it "notifies audit phase finished to debug log" do
|
272
316
|
expect(Chef::Log).to receive(:debug).with(/Audit Reporter completed/)
|
273
|
-
reporter.audit_phase_complete
|
317
|
+
reporter.audit_phase_complete("Output from audit mode")
|
274
318
|
end
|
275
319
|
|
276
320
|
it "collects audit data" do
|
277
321
|
ordered_control_groups.each do |_name, group|
|
278
322
|
expect(audit_data).to receive(:add_control_group).with(group)
|
279
323
|
end
|
280
|
-
reporter.audit_phase_complete
|
324
|
+
reporter.audit_phase_complete("Output from audit mode")
|
281
325
|
end
|
282
326
|
end
|
283
327
|
|
@@ -288,14 +332,14 @@ describe Chef::Audit::AuditReporter do
|
|
288
332
|
|
289
333
|
it "notifies audit phase failed to debug log" do
|
290
334
|
expect(Chef::Log).to receive(:debug).with(/Audit Reporter failed/)
|
291
|
-
reporter.audit_phase_failed(error)
|
335
|
+
reporter.audit_phase_failed(error, "Output from audit mode")
|
292
336
|
end
|
293
337
|
|
294
338
|
it "collects audit data" do
|
295
339
|
ordered_control_groups.each do |_name, group|
|
296
340
|
expect(audit_data).to receive(:add_control_group).with(group)
|
297
341
|
end
|
298
|
-
reporter.audit_phase_failed(error)
|
342
|
+
reporter.audit_phase_failed(error, "Output from audit mode")
|
299
343
|
end
|
300
344
|
end
|
301
345
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
|
20
|
+
describe Chef::Audit::Logger do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
Chef::Audit::Logger.instance_variable_set(:@buffer, nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'calling puts creates @buffer and adds the message' do
|
27
|
+
Chef::Audit::Logger.puts("Output message")
|
28
|
+
expect(Chef::Audit::Logger.read_buffer).to eq("Output message\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'calling puts multiple times adds to the message' do
|
32
|
+
Chef::Audit::Logger.puts("Output message")
|
33
|
+
Chef::Audit::Logger.puts("Output message")
|
34
|
+
Chef::Audit::Logger.puts("Output message")
|
35
|
+
expect(Chef::Audit::Logger.read_buffer).to eq("Output message\nOutput message\nOutput message\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'calling it before @buffer is set returns an empty string' do
|
39
|
+
expect(Chef::Audit::Logger.read_buffer).to eq("")
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -68,8 +68,8 @@ describe Chef::Audit::Runner do
|
|
68
68
|
in_sub_process do
|
69
69
|
runner.send(:setup)
|
70
70
|
|
71
|
-
expect(RSpec.configuration.output_stream).to eq(
|
72
|
-
expect(RSpec.configuration.error_stream).to eq(
|
71
|
+
expect(RSpec.configuration.output_stream).to eq(Chef::Audit::Logger)
|
72
|
+
expect(RSpec.configuration.error_stream).to eq(Chef::Audit::Logger)
|
73
73
|
|
74
74
|
expect(RSpec.configuration.formatters.size).to eq(2)
|
75
75
|
expect(RSpec.configuration.formatters).to include(instance_of(Chef::Audit::AuditEventProxy))
|
@@ -157,7 +157,7 @@ describe Chef::ChefFS::FilePattern do
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
-
context 'with simple pattern "a\*\b"', :
|
160
|
+
context 'with simple pattern "a\*\b"', :skip => (Chef::Platform.windows?) do
|
161
161
|
let(:pattern) { Chef::ChefFS::FilePattern.new('a\*\b') }
|
162
162
|
it 'match?' do
|
163
163
|
expect(pattern.match?('a*b')).to be_truthy
|
@@ -264,7 +264,7 @@ describe Chef::ChefFS::FilePattern do
|
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
267
|
-
context 'with star pattern "/abc/d[a-z][0-9]f/ghi"', :
|
267
|
+
context 'with star pattern "/abc/d[a-z][0-9]f/ghi"', :skip => (Chef::Platform.windows?) do
|
268
268
|
let(:pattern) { Chef::ChefFS::FilePattern.new('/abc/d[a-z][0-9]f/ghi') }
|
269
269
|
it 'match?' do
|
270
270
|
expect(pattern.match?('/abc/de1f/ghi')).to be_truthy
|
@@ -352,11 +352,7 @@ describe Chef::ChefFS::FilePattern do
|
|
352
352
|
expect(pattern.could_match_children?('/abc/def/ghi')).to be_truthy
|
353
353
|
expect(pattern.could_match_children?('abc')).to be_falsey
|
354
354
|
end
|
355
|
-
|
356
|
-
pending 'Make could_match_children? more rigorous'
|
357
|
-
# At the moment, we return false for this, but in the end it would be nice to return true:
|
358
|
-
expect(pattern.could_match_children?('/xyz')).to be_falsey
|
359
|
-
end
|
355
|
+
|
360
356
|
it 'exact_child_name_under' do
|
361
357
|
expect(pattern.exact_child_name_under('/')).to eq(nil)
|
362
358
|
expect(pattern.exact_child_name_under('/abc')).to eq(nil)
|
@@ -440,14 +436,6 @@ describe Chef::ChefFS::FilePattern do
|
|
440
436
|
expect(p('/.').exact_path).to eq('/')
|
441
437
|
expect(p('/.').match?('/')).to be_truthy
|
442
438
|
end
|
443
|
-
it 'handles dot by itself', :pending => "decide what to do with dot by itself" do
|
444
|
-
expect(p('.').normalized_pattern).to eq('.')
|
445
|
-
expect(p('.').exact_path).to eq('.')
|
446
|
-
expect(p('.').match?('.')).to be_truthy
|
447
|
-
expect(p('./').normalized_pattern).to eq('.')
|
448
|
-
expect(p('./').exact_path).to eq('.')
|
449
|
-
expect(p('./').match?('.')).to be_truthy
|
450
|
-
end
|
451
439
|
it 'handles dotdot' do
|
452
440
|
expect(p('abc/../def').normalized_pattern).to eq('def')
|
453
441
|
expect(p('abc/../def').exact_path).to eq('def')
|
data/spec/unit/client_spec.rb
CHANGED
@@ -19,6 +19,8 @@
|
|
19
19
|
#
|
20
20
|
|
21
21
|
require 'spec_helper'
|
22
|
+
require 'spec/support/shared/context/client'
|
23
|
+
require 'spec/support/shared/examples/client'
|
22
24
|
|
23
25
|
require 'chef/run_context'
|
24
26
|
require 'chef/rest'
|
@@ -28,55 +30,7 @@ class FooError < RuntimeError
|
|
28
30
|
end
|
29
31
|
|
30
32
|
describe Chef::Client do
|
31
|
-
|
32
|
-
let(:hostname) { "hostname" }
|
33
|
-
let(:machinename) { "machinename.example.org" }
|
34
|
-
let(:fqdn) { "hostname.example.org" }
|
35
|
-
|
36
|
-
let(:ohai_data) do
|
37
|
-
{ :fqdn => fqdn,
|
38
|
-
:hostname => hostname,
|
39
|
-
:machinename => machinename,
|
40
|
-
:platform => 'example-platform',
|
41
|
-
:platform_version => 'example-platform-1.0',
|
42
|
-
:data => {}
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
let(:ohai_system) do
|
47
|
-
ohai_system = double( "Ohai::System",
|
48
|
-
:all_plugins => true,
|
49
|
-
:data => ohai_data)
|
50
|
-
allow(ohai_system).to receive(:[]) do |key|
|
51
|
-
ohai_data[key]
|
52
|
-
end
|
53
|
-
ohai_system
|
54
|
-
end
|
55
|
-
|
56
|
-
let(:node) do
|
57
|
-
Chef::Node.new.tap do |n|
|
58
|
-
n.name(fqdn)
|
59
|
-
n.chef_environment("_default")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:json_attribs) { nil }
|
64
|
-
let(:client_opts) { {} }
|
65
|
-
|
66
|
-
let(:client) do
|
67
|
-
Chef::Config[:event_loggers] = []
|
68
|
-
Chef::Client.new(json_attribs, client_opts).tap do |c|
|
69
|
-
c.node = node
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
before do
|
74
|
-
Chef::Log.logger = Logger.new(StringIO.new)
|
75
|
-
|
76
|
-
# Node/Ohai data
|
77
|
-
#Chef::Config[:node_name] = fqdn
|
78
|
-
allow(Ohai::System).to receive(:new).and_return(ohai_system)
|
79
|
-
end
|
33
|
+
include_context "client"
|
80
34
|
|
81
35
|
context "when minimal ohai is configured" do
|
82
36
|
before do
|
@@ -88,7 +42,6 @@ describe Chef::Client do
|
|
88
42
|
expect(ohai_system).to receive(:all_plugins).with(expected_filter)
|
89
43
|
client.run_ohai
|
90
44
|
end
|
91
|
-
|
92
45
|
end
|
93
46
|
|
94
47
|
describe "authentication protocol selection" do
|
@@ -117,7 +70,6 @@ describe Chef::Client do
|
|
117
70
|
|
118
71
|
describe "configuring output formatters" do
|
119
72
|
context "when no formatter has been configured" do
|
120
|
-
|
121
73
|
context "and STDOUT is a TTY" do
|
122
74
|
before do
|
123
75
|
allow(STDOUT).to receive(:tty?).and_return(true)
|
@@ -203,135 +155,12 @@ describe Chef::Client do
|
|
203
155
|
end
|
204
156
|
|
205
157
|
describe "a full client run" do
|
206
|
-
shared_context "a client run" do
|
207
|
-
let(:http_node_load) { double("Chef::REST (node)") }
|
208
|
-
let(:http_cookbook_sync) { double("Chef::REST (cookbook sync)") }
|
209
|
-
let(:http_node_save) { double("Chef::REST (node save)") }
|
210
|
-
let(:runner) { double("Chef::Runner") }
|
211
|
-
let(:audit_runner) { instance_double("Chef::Audit::Runner", :failed? => false) }
|
212
|
-
|
213
|
-
let(:api_client_exists?) { false }
|
214
|
-
|
215
|
-
let(:stdout) { StringIO.new }
|
216
|
-
let(:stderr) { StringIO.new }
|
217
|
-
|
218
|
-
let(:enable_fork) { false }
|
219
|
-
|
220
|
-
def stub_for_register
|
221
|
-
# --Client.register
|
222
|
-
# Make sure Client#register thinks the client key doesn't
|
223
|
-
# exist, so it tries to register and create one.
|
224
|
-
allow(File).to receive(:exists?).and_call_original
|
225
|
-
expect(File).to receive(:exists?).
|
226
|
-
with(Chef::Config[:client_key]).
|
227
|
-
exactly(:once).
|
228
|
-
and_return(api_client_exists?)
|
229
|
-
|
230
|
-
unless api_client_exists?
|
231
|
-
# Client.register will register with the validation client name.
|
232
|
-
expect_any_instance_of(Chef::ApiClient::Registration).to receive(:run)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
def stub_for_node_load
|
237
|
-
# Client.register will then turn around create another
|
238
|
-
# Chef::REST object, this time with the client key it got from the
|
239
|
-
# previous step.
|
240
|
-
expect(Chef::REST).to receive(:new).
|
241
|
-
with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key]).
|
242
|
-
exactly(:once).
|
243
|
-
and_return(http_node_load)
|
244
|
-
|
245
|
-
# --Client#build_node
|
246
|
-
# looks up the node, which we will return, then later saves it.
|
247
|
-
expect(Chef::Node).to receive(:find_or_create).with(fqdn).and_return(node)
|
248
|
-
|
249
|
-
# --ResourceReporter#node_load_completed
|
250
|
-
# gets a run id from the server for storing resource history
|
251
|
-
# (has its own tests, so stubbing it here.)
|
252
|
-
expect_any_instance_of(Chef::ResourceReporter).to receive(:node_load_completed)
|
253
|
-
end
|
254
|
-
|
255
|
-
def stub_for_sync_cookbooks
|
256
|
-
# --Client#setup_run_context
|
257
|
-
# ---Client#sync_cookbooks -- downloads the list of cookbooks to sync
|
258
|
-
#
|
259
|
-
expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks)
|
260
|
-
expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(http_cookbook_sync)
|
261
|
-
expect(http_cookbook_sync).to receive(:post).
|
262
|
-
with("environments/_default/cookbook_versions", {:run_list => []}).
|
263
|
-
and_return({})
|
264
|
-
end
|
265
|
-
|
266
|
-
def stub_for_converge
|
267
|
-
# --Client#converge
|
268
|
-
expect(Chef::Runner).to receive(:new).and_return(runner)
|
269
|
-
expect(runner).to receive(:converge).and_return(true)
|
270
|
-
end
|
271
|
-
|
272
|
-
def stub_for_audit
|
273
|
-
# -- Client#run_audits
|
274
|
-
expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
|
275
|
-
expect(audit_runner).to receive(:run).and_return(true)
|
276
|
-
end
|
277
|
-
|
278
|
-
def stub_for_node_save
|
279
|
-
allow(node).to receive(:data_for_save).and_return(node.for_json)
|
280
|
-
|
281
|
-
# --Client#save_updated_node
|
282
|
-
expect(Chef::REST).to receive(:new).with(Chef::Config[:chef_server_url], fqdn, Chef::Config[:client_key], validate_utf8: false).and_return(http_node_save)
|
283
|
-
expect(http_node_save).to receive(:put_rest).with("nodes/#{fqdn}", node.for_json).and_return(true)
|
284
|
-
end
|
285
|
-
|
286
|
-
def stub_for_run
|
287
|
-
expect_any_instance_of(Chef::RunLock).to receive(:acquire)
|
288
|
-
expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
|
289
|
-
expect_any_instance_of(Chef::RunLock).to receive(:release)
|
290
|
-
|
291
|
-
# Post conditions: check that node has been filled in correctly
|
292
|
-
expect(client).to receive(:run_started)
|
293
|
-
expect(client).to receive(:run_completed_successfully)
|
294
|
-
|
295
|
-
# --ResourceReporter#run_completed
|
296
|
-
# updates the server with the resource history
|
297
|
-
# (has its own tests, so stubbing it here.)
|
298
|
-
expect_any_instance_of(Chef::ResourceReporter).to receive(:run_completed)
|
299
|
-
# --AuditReporter#run_completed
|
300
|
-
# posts the audit data to server.
|
301
|
-
# (has its own tests, so stubbing it here.)
|
302
|
-
expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_completed)
|
303
|
-
end
|
304
|
-
|
305
|
-
before do
|
306
|
-
Chef::Config[:client_fork] = enable_fork
|
307
|
-
Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
|
308
|
-
Chef::Config[:why_run] = false
|
309
|
-
Chef::Config[:audit_mode] = :enabled
|
310
|
-
|
311
|
-
stub_const("Chef::Client::STDOUT_FD", stdout)
|
312
|
-
stub_const("Chef::Client::STDERR_FD", stderr)
|
313
|
-
|
314
|
-
stub_for_register
|
315
|
-
stub_for_node_load
|
316
|
-
stub_for_sync_cookbooks
|
317
|
-
stub_for_converge
|
318
|
-
stub_for_audit
|
319
|
-
stub_for_node_save
|
320
|
-
stub_for_run
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
158
|
shared_examples_for "a successful client run" do
|
325
159
|
include_context "a client run"
|
160
|
+
include_context "converge completed"
|
161
|
+
include_context "audit phase completed"
|
326
162
|
|
327
|
-
|
328
|
-
# This is what we're testing.
|
329
|
-
client.run
|
330
|
-
|
331
|
-
# fork is stubbed, so we can see the outcome of the run
|
332
|
-
expect(node.automatic_attrs[:platform]).to eq("example-platform")
|
333
|
-
expect(node.automatic_attrs[:platform_version]).to eq("example-platform-1.0")
|
334
|
-
end
|
163
|
+
include_examples "a completed run"
|
335
164
|
end
|
336
165
|
|
337
166
|
describe "when running chef-client without fork" do
|
@@ -339,24 +168,19 @@ describe Chef::Client do
|
|
339
168
|
end
|
340
169
|
|
341
170
|
describe "when the client key already exists" do
|
342
|
-
|
343
|
-
|
171
|
+
include_examples "a successful client run" do
|
172
|
+
let(:api_client_exists?) { true }
|
173
|
+
end
|
344
174
|
end
|
345
175
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
it "should permit spaces in overriding run list" do
|
176
|
+
context "when an override run list is given" do
|
177
|
+
it "permits spaces in overriding run list" do
|
350
178
|
Chef::Client.new(nil, :override_runlist => 'role[a], role[b]')
|
351
179
|
end
|
352
180
|
|
353
|
-
describe "
|
181
|
+
describe "calling run" do
|
354
182
|
include_examples "a successful client run" do
|
355
|
-
|
356
|
-
before do
|
357
|
-
# Client will try to compile and run override_recipe
|
358
|
-
expect_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile)
|
359
|
-
end
|
183
|
+
let(:client_opts) { {:override_runlist => "recipe[override_recipe]"} }
|
360
184
|
|
361
185
|
def stub_for_sync_cookbooks
|
362
186
|
# --Client#setup_run_context
|
@@ -373,13 +197,22 @@ describe Chef::Client do
|
|
373
197
|
# Expect NO node save
|
374
198
|
expect(node).not_to receive(:save)
|
375
199
|
end
|
200
|
+
|
201
|
+
before do
|
202
|
+
# Client will try to compile and run override_recipe
|
203
|
+
expect_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile)
|
204
|
+
end
|
376
205
|
end
|
377
206
|
end
|
378
207
|
end
|
379
208
|
|
380
209
|
describe "when a permanent run list is passed as an option" do
|
381
|
-
|
210
|
+
it "sets the new run list on the node" do
|
211
|
+
client.run
|
212
|
+
expect(node.run_list).to eq(Chef::RunList.new(new_runlist))
|
213
|
+
end
|
382
214
|
|
215
|
+
include_examples "a successful client run" do
|
383
216
|
let(:new_runlist) { "recipe[new_run_list_recipe]" }
|
384
217
|
let(:client_opts) { {:runlist => new_runlist} }
|
385
218
|
|
@@ -399,214 +232,61 @@ describe Chef::Client do
|
|
399
232
|
# do not create a fixture for this.
|
400
233
|
expect_any_instance_of(Chef::RunContext::CookbookCompiler).to receive(:compile)
|
401
234
|
end
|
402
|
-
|
403
|
-
it "sets the new run list on the node" do
|
404
|
-
client.run
|
405
|
-
expect(node.run_list).to eq(Chef::RunList.new(new_runlist))
|
406
|
-
end
|
407
235
|
end
|
408
236
|
end
|
409
237
|
|
410
|
-
describe "when converge
|
411
|
-
include_context "a client run"
|
412
|
-
|
413
|
-
def stub_for_converge
|
414
|
-
expect(Chef::Runner).to receive(:new).and_return(runner)
|
415
|
-
expect(runner).to receive(:converge).and_raise(e)
|
416
|
-
expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
|
417
|
-
end
|
418
|
-
|
419
|
-
def stub_for_node_save
|
420
|
-
expect(client).to_not receive(:save_updated_node)
|
421
|
-
end
|
422
|
-
|
423
|
-
def stub_for_run
|
424
|
-
expect_any_instance_of(Chef::RunLock).to receive(:acquire)
|
425
|
-
expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
|
426
|
-
expect_any_instance_of(Chef::RunLock).to receive(:release)
|
427
|
-
|
428
|
-
# Post conditions: check that node has been filled in correctly
|
429
|
-
expect(client).to receive(:run_started)
|
430
|
-
expect(client).to receive(:run_failed)
|
431
|
-
|
432
|
-
expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
|
433
|
-
expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed)
|
434
|
-
end
|
435
|
-
end
|
238
|
+
describe "when converge completes successfully" do
|
239
|
+
include_context "a client run"
|
240
|
+
include_context "converge completed"
|
436
241
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
242
|
+
describe "when audit phase errors" do
|
243
|
+
include_context "audit phase failed with error"
|
244
|
+
include_examples "a completed run with audit failure" do
|
245
|
+
let(:run_errors) { [audit_error] }
|
441
246
|
end
|
442
247
|
end
|
443
|
-
end
|
444
|
-
|
445
|
-
describe "when the audit phase fails" do
|
446
|
-
context "with an exception" do
|
447
|
-
context "when audit mode is enabled" do
|
448
|
-
include_context "a client run" do
|
449
|
-
let(:e) { Exception.new }
|
450
|
-
def stub_for_audit
|
451
|
-
expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
|
452
|
-
expect(audit_runner).to receive(:run).and_raise(e)
|
453
|
-
expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
|
454
|
-
end
|
455
|
-
|
456
|
-
def stub_for_run
|
457
|
-
expect_any_instance_of(Chef::RunLock).to receive(:acquire)
|
458
|
-
expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
|
459
|
-
expect_any_instance_of(Chef::RunLock).to receive(:release)
|
460
|
-
|
461
|
-
# Post conditions: check that node has been filled in correctly
|
462
|
-
expect(client).to receive(:run_started)
|
463
|
-
expect(client).to receive(:run_failed)
|
464
|
-
|
465
|
-
expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
|
466
|
-
expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed)
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
it "should save the node after converge and raise exception" do
|
471
|
-
expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
|
472
|
-
expect(error.wrapped_errors.size).to eq(1)
|
473
|
-
expect(error.wrapped_errors[0]).to eq(e)
|
474
|
-
end
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
context "when audit mode is disabled" do
|
479
|
-
include_context "a client run" do
|
480
|
-
before do
|
481
|
-
Chef::Config[:audit_mode] = :disabled
|
482
|
-
end
|
483
|
-
|
484
|
-
let(:e) { FooError.new }
|
485
|
-
|
486
|
-
def stub_for_audit
|
487
|
-
expect(Chef::Audit::Runner).to_not receive(:new)
|
488
|
-
end
|
489
|
-
|
490
|
-
def stub_for_converge
|
491
|
-
expect(Chef::Runner).to receive(:new).and_return(runner)
|
492
|
-
expect(runner).to receive(:converge).and_raise(e)
|
493
|
-
expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(FooError)
|
494
|
-
end
|
495
|
-
|
496
|
-
def stub_for_node_save
|
497
|
-
expect(client).to_not receive(:save_updated_node)
|
498
|
-
end
|
499
|
-
|
500
|
-
def stub_for_run
|
501
|
-
expect_any_instance_of(Chef::RunLock).to receive(:acquire)
|
502
|
-
expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
|
503
|
-
expect_any_instance_of(Chef::RunLock).to receive(:release)
|
504
|
-
|
505
|
-
|
506
|
-
# Post conditions: check that node has been filled in correctly
|
507
|
-
expect(client).to receive(:run_started)
|
508
|
-
expect(client).to receive(:run_failed)
|
509
|
-
|
510
|
-
expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
|
511
|
-
|
512
|
-
end
|
513
|
-
|
514
|
-
it "re-raises an unwrapped exception" do
|
515
|
-
expect { client.run }.to raise_error(FooError)
|
516
|
-
end
|
517
|
-
end
|
518
|
-
end
|
519
|
-
|
520
248
|
|
249
|
+
describe "when audit phase completed" do
|
250
|
+
include_context "audit phase completed"
|
251
|
+
include_examples "a completed run"
|
521
252
|
end
|
522
253
|
|
523
|
-
|
524
|
-
include_context "
|
525
|
-
|
526
|
-
|
527
|
-
end
|
528
|
-
|
529
|
-
def stub_for_audit
|
530
|
-
expect(Chef::Audit::Runner).to receive(:new).and_return(audit_runner)
|
531
|
-
expect(Chef::Application).to receive(:debug_stacktrace).with an_instance_of(Chef::Exceptions::RunFailedWrappingError)
|
532
|
-
end
|
533
|
-
|
534
|
-
def stub_for_run
|
535
|
-
expect_any_instance_of(Chef::RunLock).to receive(:acquire)
|
536
|
-
expect_any_instance_of(Chef::RunLock).to receive(:save_pid)
|
537
|
-
expect_any_instance_of(Chef::RunLock).to receive(:release)
|
538
|
-
|
539
|
-
# Post conditions: check that node has been filled in correctly
|
540
|
-
expect(client).to receive(:run_started)
|
541
|
-
expect(client).to receive(:run_failed)
|
542
|
-
|
543
|
-
expect_any_instance_of(Chef::ResourceReporter).to receive(:run_failed)
|
544
|
-
expect_any_instance_of(Chef::Audit::AuditReporter).to receive(:run_failed)
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
it "should save the node after converge and raise exception" do
|
549
|
-
expect{ client.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
|
550
|
-
expect(error.wrapped_errors.size).to eq(1)
|
551
|
-
expect(error.wrapped_errors[0]).to be_instance_of(Chef::Exceptions::AuditsFailed)
|
552
|
-
end
|
254
|
+
describe "when audit phase completed with failed controls" do
|
255
|
+
include_context "audit phase completed with failed controls"
|
256
|
+
include_examples "a completed run with audit failure" do
|
257
|
+
let(:run_errors) { [audit_error] }
|
553
258
|
end
|
554
259
|
end
|
555
260
|
end
|
556
261
|
|
557
|
-
describe "when
|
558
|
-
include_context "a client run"
|
559
|
-
|
560
|
-
before do
|
561
|
-
Chef::Config[:why_run] = true
|
562
|
-
end
|
563
|
-
|
564
|
-
def stub_for_audit
|
565
|
-
expect(Chef::Audit::Runner).to_not receive(:new)
|
566
|
-
end
|
567
|
-
|
568
|
-
def stub_for_node_save
|
569
|
-
# This is how we should be mocking external calls - not letting it fall all the way through to the
|
570
|
-
# REST call
|
571
|
-
expect(node).to receive(:save)
|
572
|
-
end
|
573
|
-
|
574
|
-
it "runs successfully without enabling the audit runner" do
|
575
|
-
client.run
|
262
|
+
describe "when converge errors" do
|
263
|
+
include_context "a client run"
|
264
|
+
include_context "converge failed"
|
576
265
|
|
577
|
-
|
578
|
-
|
579
|
-
|
266
|
+
describe "when audit phase errors" do
|
267
|
+
include_context "audit phase failed with error"
|
268
|
+
include_examples "a failed run" do
|
269
|
+
let(:run_errors) { [converge_error, audit_error] }
|
580
270
|
end
|
581
271
|
end
|
582
|
-
end
|
583
|
-
|
584
|
-
describe "when audits are disabled" do
|
585
|
-
include_context "a client run" do
|
586
|
-
|
587
|
-
before do
|
588
|
-
Chef::Config[:audit_mode] = :disabled
|
589
|
-
end
|
590
272
|
|
591
|
-
|
592
|
-
|
273
|
+
describe "when audit phase completed" do
|
274
|
+
include_context "audit phase completed"
|
275
|
+
include_examples "a failed run" do
|
276
|
+
let(:run_errors) { [converge_error] }
|
593
277
|
end
|
278
|
+
end
|
594
279
|
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
expect(node.automatic_attrs[:platform]).to eq("example-platform")
|
600
|
-
expect(node.automatic_attrs[:platform_version]).to eq("example-platform-1.0")
|
280
|
+
describe "when audit phase completed with failed controls" do
|
281
|
+
include_context "audit phase completed with failed controls"
|
282
|
+
include_examples "a failed run" do
|
283
|
+
let(:run_errors) { [converge_error, audit_error] }
|
601
284
|
end
|
602
285
|
end
|
603
286
|
end
|
604
|
-
|
605
287
|
end
|
606
288
|
|
607
|
-
|
608
289
|
describe "when handling run failures" do
|
609
|
-
|
610
290
|
it "should remove the run_lock on failure of #load_node" do
|
611
291
|
@run_lock = double("Chef::RunLock", :acquire => true)
|
612
292
|
allow(Chef::RunLock).to receive(:new).and_return(@run_lock)
|
@@ -779,6 +459,7 @@ describe Chef::Client do
|
|
779
459
|
Chef::Config[:solo] = true
|
780
460
|
Chef::Config[:cookbook_path] = ["/path/to/invalid/cookbook_path"]
|
781
461
|
end
|
462
|
+
|
782
463
|
context "when any directory of cookbook_path contains no cookbook" do
|
783
464
|
it "raises CookbookNotFound error" do
|
784
465
|
expect do
|
@@ -833,7 +514,10 @@ describe Chef::Client do
|
|
833
514
|
|
834
515
|
it "should run exception handlers on early fail" do
|
835
516
|
expect(subject).to receive(:run_failed)
|
836
|
-
expect { subject.run }.to raise_error(
|
517
|
+
expect { subject.run }.to raise_error(Chef::Exceptions::RunFailedWrappingError) do |error|
|
518
|
+
expect(error.wrapped_errors.size).to eq 1
|
519
|
+
expect(error.wrapped_errors).to include(NoMethodError)
|
520
|
+
end
|
837
521
|
end
|
838
522
|
end
|
839
523
|
end
|