chef 12.3.0 → 12.4.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +86 -7
- data/distro/common/markdown/man1/chef-shell.mkd +4 -4
- data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
- data/distro/common/markdown/man1/knife-client.mkd +1 -1
- data/distro/common/markdown/man1/knife-configure.mkd +1 -1
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
- data/distro/common/markdown/man1/knife-cookbook.mkd +4 -4
- data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
- data/distro/common/markdown/man1/knife-environment.mkd +3 -3
- data/distro/common/markdown/man1/knife-exec.mkd +1 -1
- data/distro/common/markdown/man1/knife-index.mkd +1 -1
- data/distro/common/markdown/man1/knife-node.mkd +1 -1
- data/distro/common/markdown/man1/knife-role.mkd +3 -3
- data/distro/common/markdown/man1/knife-search.mkd +2 -2
- data/distro/common/markdown/man1/knife-ssh.mkd +1 -1
- data/distro/common/markdown/man1/knife-status.mkd +1 -1
- data/distro/common/markdown/man1/knife-tag.mkd +1 -1
- data/distro/common/markdown/man1/knife.mkd +2 -2
- data/distro/common/markdown/man8/chef-client.mkd +1 -2
- data/distro/common/markdown/man8/chef-expander.mkd +1 -2
- data/distro/common/markdown/man8/chef-expanderctl.mkd +1 -2
- data/distro/common/markdown/man8/chef-server-webui.mkd +1 -1
- data/distro/common/markdown/man8/chef-server.mkd +1 -2
- data/distro/common/markdown/man8/chef-solo.mkd +2 -2
- data/distro/common/markdown/man8/chef-solr.mkd +1 -1
- data/lib/chef/client.rb +2 -2
- data/lib/chef/config.rb +17 -709
- data/lib/chef/cookbook/metadata.rb +9 -5
- data/lib/chef/cookbook_loader.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +2 -18
- data/lib/chef/dsl/definitions.rb +44 -0
- data/lib/chef/dsl/recipe.rb +50 -35
- data/lib/chef/dsl/resources.rb +28 -0
- data/lib/chef/event_dispatch/dispatcher.rb +2 -0
- data/lib/chef/event_loggers/windows_eventlog.rb +1 -11
- data/lib/chef/exceptions.rb +4 -0
- data/lib/chef/file_access_control/unix.rb +5 -0
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +17 -0
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +21 -9
- data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -0
- data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +4 -0
- data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +11 -1
- data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +2 -0
- data/lib/chef/http/authenticator.rb +3 -0
- data/lib/chef/http/basic_client.rb +10 -6
- data/lib/chef/http/json_input.rb +6 -1
- data/lib/chef/key.rb +271 -0
- data/lib/chef/knife.rb +11 -1
- data/lib/chef/knife/bootstrap.rb +6 -0
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +166 -23
- data/lib/chef/knife/client_key_create.rb +67 -0
- data/lib/chef/knife/client_key_delete.rb +76 -0
- data/lib/chef/knife/client_key_edit.rb +80 -0
- data/lib/chef/knife/client_key_list.rb +69 -0
- data/lib/chef/knife/client_key_show.rb +76 -0
- data/lib/chef/knife/key_create.rb +108 -0
- data/lib/chef/knife/key_create_base.rb +50 -0
- data/lib/chef/knife/key_delete.rb +55 -0
- data/lib/chef/knife/key_edit.rb +114 -0
- data/lib/chef/knife/key_edit_base.rb +55 -0
- data/lib/chef/knife/key_list.rb +88 -0
- data/lib/chef/knife/key_list_base.rb +45 -0
- data/lib/chef/knife/key_show.rb +53 -0
- data/lib/chef/knife/ssh.rb +26 -28
- data/lib/chef/knife/user_key_create.rb +69 -0
- data/lib/chef/knife/user_key_delete.rb +76 -0
- data/lib/chef/knife/user_key_edit.rb +80 -0
- data/lib/chef/knife/user_key_list.rb +69 -0
- data/lib/chef/knife/user_key_show.rb +76 -0
- data/lib/chef/log.rb +2 -0
- data/lib/chef/log/syslog.rb +46 -0
- data/lib/chef/log/winevt.rb +99 -0
- data/lib/chef/mixin/provides.rb +8 -1
- data/lib/chef/mixin/unformatter.rb +32 -0
- data/lib/chef/mixin/uris.rb +33 -0
- data/lib/chef/mixin/wstring.rb +31 -0
- data/lib/chef/node.rb +21 -2
- data/lib/chef/platform/provider_mapping.rb +8 -4
- data/lib/chef/platform/query_helpers.rb +1 -5
- data/lib/chef/platform/service_helpers.rb +21 -21
- data/lib/chef/provider.rb +33 -0
- data/lib/chef/provider/cron/unix.rb +1 -0
- data/lib/chef/provider/file.rb +5 -3
- data/lib/chef/provider/lwrp_base.rb +76 -58
- data/lib/chef/provider/ohai.rb +1 -0
- data/lib/chef/provider/package.rb +7 -4
- data/lib/chef/provider/package/aix.rb +1 -0
- data/lib/chef/provider/package/smartos.rb +5 -5
- data/lib/chef/provider/package/windows.rb +90 -6
- data/lib/chef/provider/package/yum.rb +102 -32
- data/lib/chef/provider/reboot.rb +1 -0
- data/lib/chef/provider/registry_key.rb +2 -0
- data/lib/chef/provider/remote_file.rb +1 -0
- data/lib/chef/provider/remote_file/content.rb +5 -1
- data/lib/chef/provider/remote_file/fetcher.rb +22 -8
- data/lib/chef/provider/remote_file/network_file.rb +48 -0
- data/lib/chef/provider/service/aix.rb +13 -12
- data/lib/chef/provider_resolver.rb +87 -0
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +67 -8
- data/lib/chef/resource/bash.rb +1 -0
- data/lib/chef/resource/bff_package.rb +1 -2
- data/lib/chef/resource/breakpoint.rb +1 -0
- data/lib/chef/resource/csh.rb +1 -0
- data/lib/chef/resource/deploy.rb +1 -0
- data/lib/chef/resource/erl_call.rb +1 -0
- data/lib/chef/resource/execute.rb +1 -0
- data/lib/chef/resource/file.rb +18 -0
- data/lib/chef/resource/http_request.rb +1 -0
- data/lib/chef/resource/ifconfig.rb +1 -2
- data/lib/chef/resource/log.rb +1 -2
- data/lib/chef/resource/lwrp_base.rb +106 -87
- data/lib/chef/resource/ohai.rb +1 -0
- data/lib/chef/resource/package.rb +1 -0
- data/lib/chef/resource/perl.rb +1 -0
- data/lib/chef/resource/portage_package.rb +1 -0
- data/lib/chef/resource/python.rb +1 -0
- data/lib/chef/resource/reboot.rb +2 -0
- data/lib/chef/resource/registry_key.rb +1 -0
- data/lib/chef/resource/remote_file.rb +1 -1
- data/lib/chef/resource/route.rb +1 -2
- data/lib/chef/resource/ruby.rb +1 -0
- data/lib/chef/resource/ruby_block.rb +1 -0
- data/lib/chef/resource/scm.rb +1 -0
- data/lib/chef/resource/script.rb +1 -0
- data/lib/chef/resource/service.rb +1 -0
- data/lib/chef/resource/subversion.rb +1 -0
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
- data/lib/chef/resource/windows_package.rb +24 -2
- data/lib/chef/resource/windows_script.rb +1 -0
- data/lib/chef/resource/yum_package.rb +1 -1
- data/lib/chef/resource_definition.rb +1 -0
- data/lib/chef/resource_reporter.rb +3 -10
- data/lib/chef/resource_resolver.rb +20 -10
- data/lib/chef/run_context.rb +1 -0
- data/lib/chef/run_list/versioned_recipe_list.rb +18 -0
- data/lib/chef/run_status.rb +2 -4
- data/lib/chef/shell.rb +1 -1
- data/lib/chef/util/path_helper.rb +3 -204
- data/lib/chef/util/windows/net_user.rb +73 -118
- data/lib/chef/version.rb +8 -4
- data/lib/chef/win32/api.rb +2 -1
- data/lib/chef/win32/api/installer.rb +1 -1
- data/lib/chef/win32/api/net.rb +115 -2
- data/lib/chef/win32/api/security.rb +24 -0
- data/lib/chef/win32/api/unicode.rb +1 -1
- data/lib/chef/win32/eventlog.rb +31 -0
- data/lib/chef/win32/net.rb +190 -0
- data/lib/chef/win32/security.rb +51 -2
- data/lib/chef/win32/security/sid.rb +17 -0
- data/spec/data/lwrp/providers/buck_passer.rb +18 -2
- data/spec/data/lwrp/providers/buck_passer_2.rb +18 -2
- data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +14 -2
- data/spec/data/lwrp_override/resources/foo.rb +5 -0
- data/spec/functional/knife/ssh_spec.rb +2 -2
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/aixinit_service_spec.rb +1 -1
- data/spec/functional/resource/user/windows_spec.rb +125 -0
- data/spec/functional/shell_spec.rb +25 -10
- data/spec/functional/win32/sid_spec.rb +55 -0
- data/spec/integration/client/client_spec.rb +53 -29
- data/spec/integration/knife/deps_spec.rb +8 -14
- data/spec/integration/knife/upload_spec.rb +18 -0
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
- data/spec/integration/recipes/provider_choice.rb +41 -0
- data/spec/integration/recipes/recipe_dsl_spec.rb +259 -0
- data/spec/spec_helper.rb +6 -1
- data/spec/support/key_helpers.rb +104 -0
- data/spec/support/lib/chef/resource/cat.rb +1 -0
- data/spec/support/lib/chef/resource/one_two_three_four.rb +2 -0
- data/spec/support/lib/chef/resource/zen_follower.rb +1 -0
- data/spec/support/lib/chef/resource/zen_master.rb +2 -0
- data/spec/support/mock/platform.rb +1 -1
- data/spec/support/pedant/Gemfile.lock +67 -0
- data/spec/support/shared/functional/securable_resource.rb +34 -12
- data/spec/support/shared/integration/integration_helper.rb +6 -5
- data/spec/support/shared/unit/provider/file.rb +31 -8
- data/spec/unit/application/client_spec.rb +2 -2
- data/spec/unit/client_spec.rb +21 -4
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
- data/spec/unit/cookbook/metadata_spec.rb +15 -0
- data/spec/unit/cookbook/syntax_check_spec.rb +1 -1
- data/spec/unit/cookbook_loader_spec.rb +1 -1
- data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -21
- data/spec/unit/data_bag_spec.rb +1 -1
- data/spec/unit/event_dispatch/dispatcher_spec.rb +61 -0
- data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +75 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +149 -112
- data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +7 -0
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
- data/spec/unit/http/authenticator_spec.rb +69 -0
- data/spec/unit/http/basic_client_spec.rb +16 -0
- data/spec/unit/key_spec.rb +634 -0
- data/spec/unit/knife/bootstrap_spec.rb +14 -1
- data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
- data/spec/unit/knife/core/ui_spec.rb +1 -1
- data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
- data/spec/unit/knife/environment_from_file_spec.rb +1 -1
- data/spec/unit/knife/key_create_spec.rb +224 -0
- data/spec/unit/knife/key_delete_spec.rb +135 -0
- data/spec/unit/knife/key_edit_spec.rb +267 -0
- data/spec/unit/knife/key_helper.rb +74 -0
- data/spec/unit/knife/key_list_spec.rb +216 -0
- data/spec/unit/knife/key_show_spec.rb +126 -0
- data/spec/unit/knife/ssh_spec.rb +23 -26
- data/spec/unit/knife_spec.rb +33 -1
- data/spec/unit/log/syslog_spec.rb +53 -0
- data/spec/unit/log/winevt_spec.rb +55 -0
- data/spec/unit/lwrp_spec.rb +105 -51
- data/spec/unit/mixin/path_sanity_spec.rb +2 -2
- data/spec/unit/mixin/template_spec.rb +2 -2
- data/spec/unit/mixin/unformatter_spec.rb +61 -0
- data/spec/unit/mixin/uris_spec.rb +45 -0
- data/spec/unit/platform/query_helpers_spec.rb +1 -1
- data/spec/unit/policy_builder/policyfile_spec.rb +7 -3
- data/spec/unit/provider/deploy/revision_spec.rb +1 -1
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +1 -1
- data/spec/unit/provider/execute_spec.rb +1 -1
- data/spec/unit/provider/package/aix_spec.rb +20 -8
- data/spec/unit/provider/package/smartos_spec.rb +50 -40
- data/spec/unit/provider/package/windows_spec.rb +104 -25
- data/spec/unit/provider/package/yum_spec.rb +111 -1
- data/spec/unit/provider/package_spec.rb +6 -0
- data/spec/unit/provider/remote_file/fetcher_spec.rb +20 -1
- data/spec/unit/provider/remote_file/network_file_spec.rb +45 -0
- data/spec/unit/provider/service/aix_service_spec.rb +26 -11
- data/spec/unit/provider/user/dscl_spec.rb +1 -1
- data/spec/unit/provider_spec.rb +20 -0
- data/spec/unit/recipe_spec.rb +1 -1
- data/spec/unit/resource/batch_spec.rb +1 -0
- data/spec/unit/resource/powershell_spec.rb +1 -0
- data/spec/unit/resource/remote_file_spec.rb +10 -0
- data/spec/unit/resource/windows_package_spec.rb +16 -2
- data/spec/unit/resource_spec.rb +40 -24
- data/spec/unit/rest_spec.rb +10 -20
- data/spec/unit/role_spec.rb +1 -1
- data/spec/unit/run_context_spec.rb +31 -0
- data/spec/unit/shell_spec.rb +4 -4
- data/tasks/external_tests.rb +29 -0
- data/tasks/rspec.rb +14 -1
- metadata +105 -28
- data/spec/unit/config_spec.rb +0 -544
- data/spec/unit/util/path_helper_spec.rb +0 -255
data/spec/unit/knife_spec.rb
CHANGED
@@ -30,11 +30,20 @@ describe Chef::Knife do
|
|
30
30
|
|
31
31
|
let(:knife) { Chef::Knife.new }
|
32
32
|
|
33
|
+
let(:config_location) { File.expand_path("~/.chef/config.rb") }
|
34
|
+
|
35
|
+
let(:config_loader) do
|
36
|
+
instance_double("WorkstationConfigLoader", load: nil, no_config_found?: false, config_location: config_location)
|
37
|
+
end
|
38
|
+
|
33
39
|
before(:each) do
|
34
40
|
Chef::Log.logger = Logger.new(StringIO.new)
|
35
41
|
|
36
42
|
Chef::Config[:node_name] = "webmonkey.example.com"
|
37
43
|
|
44
|
+
allow(Chef::WorkstationConfigLoader).to receive(:new).and_return(config_loader)
|
45
|
+
allow(config_loader).to receive(:explicit_config_file=)
|
46
|
+
|
38
47
|
# Prevent gratuitous code reloading:
|
39
48
|
allow(Chef::Knife).to receive(:load_commands)
|
40
49
|
allow(knife.ui).to receive(:puts)
|
@@ -130,7 +139,8 @@ describe Chef::Knife do
|
|
130
139
|
"Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
131
140
|
'X-Chef-Version' => Chef::VERSION,
|
132
141
|
"Host"=>"api.opscode.piab",
|
133
|
-
"X-REMOTE-REQUEST-ID"=>request_id
|
142
|
+
"X-REMOTE-REQUEST-ID"=>request_id,
|
143
|
+
'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}}
|
134
144
|
|
135
145
|
let(:request_id) {"1234"}
|
136
146
|
|
@@ -251,6 +261,18 @@ describe Chef::Knife do
|
|
251
261
|
:default => "default-value")
|
252
262
|
end
|
253
263
|
|
264
|
+
it "sets the default log_location to STDERR for Chef::Log warnings" do
|
265
|
+
knife_command = KnifeSpecs::TestYourself.new([])
|
266
|
+
knife_command.configure_chef
|
267
|
+
expect(Chef::Config[:log_location]).to eq(STDERR)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "sets the default log_level to warn so we can issue Chef::Log.warn" do
|
271
|
+
knife_command = KnifeSpecs::TestYourself.new([])
|
272
|
+
knife_command.configure_chef
|
273
|
+
expect(Chef::Config[:log_level]).to eql(:warn)
|
274
|
+
end
|
275
|
+
|
254
276
|
it "prefers the default value if no config or command line value is present" do
|
255
277
|
knife_command = KnifeSpecs::TestYourself.new([]) #empty argv
|
256
278
|
knife_command.configure_chef
|
@@ -374,6 +396,16 @@ describe Chef::Knife do
|
|
374
396
|
expect(stderr.string).to match(%r[Response: nothing to see here])
|
375
397
|
end
|
376
398
|
|
399
|
+
it "formats 406s (non-supported API version error) nicely" do
|
400
|
+
response = Net::HTTPNotAcceptable.new("1.1", "406", "Not Acceptable")
|
401
|
+
response.instance_variable_set(:@read, true) # I hate you, net/http.
|
402
|
+
allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(:error => "sad trombone", :min_version => "0", :max_version => "1"))
|
403
|
+
allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("406 Not Acceptable", response))
|
404
|
+
knife.run_with_pretty_exceptions
|
405
|
+
expect(stderr.string).to include('The version of Chef that Knife is using is not supported by the Chef server you sent this request to')
|
406
|
+
expect(stderr.string).to include("This version of Chef requires a server API version of #{Chef::HTTP::Authenticator::SERVER_API_VERSION}")
|
407
|
+
end
|
408
|
+
|
377
409
|
it "formats 500s nicely" do
|
378
410
|
response = Net::HTTPInternalServerError.new("1.1", "500", "Internal Server Error")
|
379
411
|
response.instance_variable_set(:@read, true) # I hate you, net/http.
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Author:: SAWANOBORI Yukihiko (<sawanoboriyu@higanworks.com>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
require 'chef'
|
21
|
+
|
22
|
+
describe "Chef::Log::Syslog", :unix_only => true do
|
23
|
+
let(:syslog) { Chef::Log::Syslog.new }
|
24
|
+
let(:app) { Chef::Application.new }
|
25
|
+
|
26
|
+
before do
|
27
|
+
Chef::Log.init(MonoLogger.new(syslog))
|
28
|
+
@old_log_level = Chef::Log.level
|
29
|
+
Chef::Log.level = :info
|
30
|
+
@old_loggers = Chef::Log.loggers
|
31
|
+
Chef::Log.use_log_devices([syslog])
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
Chef::Log.level = @old_log_level
|
36
|
+
Chef::Log.use_log_devices(@old_loggers)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should send message with severity info to syslog." do
|
40
|
+
expect(syslog).to receive(:info).with("*** Chef 12.4.0.dev.0 ***")
|
41
|
+
Chef::Log.info("*** Chef 12.4.0.dev.0 ***")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should send message with severity warning to syslog." do
|
45
|
+
expect(syslog).to receive(:warn).with("No config file found or specified on command line, using command line options.")
|
46
|
+
Chef::Log.warn("No config file found or specified on command line, using command line options.")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should fallback into send message with severity info to syslog when wrong format." do
|
50
|
+
expect(syslog).to receive(:info).with("chef message")
|
51
|
+
syslog.write("chef message")
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jay Mundrawala (jdm@chef.io)
|
3
|
+
# Author:: SAWANOBORI Yukihiko (<sawanoboriyu@higanworks.com>)
|
4
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe Chef::Log::WinEvt do
|
23
|
+
let(:evtlog) { instance_double("Win32::EventLog")}
|
24
|
+
let(:winevt) { Chef::Log::WinEvt.new(evtlog) }
|
25
|
+
let(:app) { Chef::Application.new }
|
26
|
+
|
27
|
+
before do
|
28
|
+
|
29
|
+
Chef::Log.init(MonoLogger.new(winevt))
|
30
|
+
@old_log_level = Chef::Log.level
|
31
|
+
Chef::Log.level = :info
|
32
|
+
@old_loggers = Chef::Log.loggers
|
33
|
+
Chef::Log.use_log_devices([winevt])
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
Chef::Log.level = @old_log_level
|
38
|
+
Chef::Log.use_log_devices(@old_loggers)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should send message with severity info to Windows Event Log." do
|
42
|
+
expect(winevt).to receive(:info).with("*** Chef 12.4.0.dev.0 ***")
|
43
|
+
Chef::Log.info("*** Chef 12.4.0.dev.0 ***")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should send message with severity warning to Windows Event Log." do
|
47
|
+
expect(winevt).to receive(:warn).with("No config file found or specified on command line, using command line options.")
|
48
|
+
Chef::Log.warn("No config file found or specified on command line, using command line options.")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should fallback into send message with severity info to Windows Event Log when wrong format." do
|
52
|
+
expect(winevt).to receive(:info).with("chef message")
|
53
|
+
winevt.write("chef message")
|
54
|
+
end
|
55
|
+
end
|
data/spec/unit/lwrp_spec.rb
CHANGED
@@ -17,20 +17,40 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'spec_helper'
|
20
|
+
require 'tmpdir'
|
21
|
+
require 'fileutils'
|
22
|
+
require 'chef/mixin/convert_to_class_name'
|
20
23
|
|
21
24
|
module LwrpConstScopingConflict
|
22
25
|
end
|
23
26
|
|
24
27
|
describe "LWRP" do
|
28
|
+
include Chef::Mixin::ConvertToClassName
|
29
|
+
|
25
30
|
before do
|
26
31
|
@original_VERBOSE = $VERBOSE
|
27
32
|
$VERBOSE = nil
|
33
|
+
Chef::Resource::LWRPBase.class_eval { @loaded_lwrps = {} }
|
28
34
|
end
|
29
35
|
|
30
36
|
after do
|
31
37
|
$VERBOSE = @original_VERBOSE
|
32
38
|
end
|
33
39
|
|
40
|
+
def get_lwrp(name)
|
41
|
+
Chef::Resource.resource_for_node(name, Chef::Node.new)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_lwrp_provider(name)
|
45
|
+
old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
|
46
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
47
|
+
begin
|
48
|
+
Chef::Provider.const_get(convert_to_class_name(name.to_s))
|
49
|
+
ensure
|
50
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = old_treat_deprecation_warnings_as_errors
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
34
54
|
describe "when overriding an existing class" do
|
35
55
|
before :each do
|
36
56
|
allow($stderr).to receive(:write)
|
@@ -43,7 +63,6 @@ describe "LWRP" do
|
|
43
63
|
expect(Chef::Log).not_to receive(:debug).with(/anymore/)
|
44
64
|
Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
|
45
65
|
Object.send(:remove_const, 'LwrpFoo')
|
46
|
-
Chef::Resource.send(:remove_const, 'LwrpFoo')
|
47
66
|
end
|
48
67
|
|
49
68
|
it "should not skip loading a provider when there's a top level symbol of the same name" do
|
@@ -53,7 +72,6 @@ describe "LWRP" do
|
|
53
72
|
expect(Chef::Log).not_to receive(:debug).with(/anymore/)
|
54
73
|
Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
|
55
74
|
Object.send(:remove_const, 'LwrpBuckPasser')
|
56
|
-
Chef::Provider.send(:remove_const, 'LwrpBuckPasser')
|
57
75
|
end
|
58
76
|
|
59
77
|
# @todo: we need a before block to manually remove_const all of the LWRPs that we
|
@@ -67,7 +85,6 @@ describe "LWRP" do
|
|
67
85
|
|
68
86
|
Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file|
|
69
87
|
expect(Chef::Log).to receive(:info).with(/Skipping/)
|
70
|
-
expect(Chef::Log).to receive(:debug).with(/anymore/)
|
71
88
|
Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
|
72
89
|
end
|
73
90
|
end
|
@@ -79,7 +96,6 @@ describe "LWRP" do
|
|
79
96
|
|
80
97
|
Dir[File.expand_path( "lwrp/providers/*", CHEF_SPEC_DATA)].each do |file|
|
81
98
|
expect(Chef::Log).to receive(:info).with(/Skipping/)
|
82
|
-
expect(Chef::Log).to receive(:debug).with(/anymore/)
|
83
99
|
Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil)
|
84
100
|
end
|
85
101
|
end
|
@@ -90,7 +106,7 @@ describe "LWRP" do
|
|
90
106
|
Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file|
|
91
107
|
Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
|
92
108
|
end
|
93
|
-
first_lwr_foo_class =
|
109
|
+
first_lwr_foo_class = get_lwrp(:lwrp_foo)
|
94
110
|
expect(Chef::Resource.resource_classes).to include(first_lwr_foo_class)
|
95
111
|
Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file|
|
96
112
|
Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
|
@@ -106,40 +122,78 @@ describe "LWRP" do
|
|
106
122
|
|
107
123
|
end
|
108
124
|
|
125
|
+
context "When an LWRP resource lwrp_foo is loaded" do
|
126
|
+
before do
|
127
|
+
@tmpdir = Dir.mktmpdir("lwrp_test")
|
128
|
+
@lwrp_path = File.join(@tmpdir, "foo.rb")
|
129
|
+
content = IO.read(File.expand_path("../../data/lwrp/resources/foo.rb", __FILE__))
|
130
|
+
IO.write(@lwrp_path, content)
|
131
|
+
Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil)
|
132
|
+
@original_resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new)
|
133
|
+
end
|
134
|
+
|
135
|
+
after do
|
136
|
+
FileUtils.remove_entry @tmpdir
|
137
|
+
end
|
138
|
+
|
139
|
+
context "And the LWRP is asked to load again, this time with different code" do
|
140
|
+
before do
|
141
|
+
content = IO.read(File.expand_path("../../data/lwrp_override/resources/foo.rb", __FILE__))
|
142
|
+
IO.write(@lwrp_path, content)
|
143
|
+
Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "Should load the old content, and not the new" do
|
147
|
+
resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new)
|
148
|
+
expect(resource).to eq @original_resource
|
149
|
+
expect(resource.default_action).to eq([:pass_buck])
|
150
|
+
expect(Chef.method_defined?(:method_created_by_override_lwrp_foo)).to be_falsey
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
109
155
|
describe "Lightweight Chef::Resource" do
|
110
156
|
|
111
157
|
before do
|
112
158
|
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "resources", "*"))].each do |file|
|
113
159
|
Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil)
|
114
160
|
end
|
161
|
+
end
|
115
162
|
|
116
|
-
|
117
|
-
|
118
|
-
end
|
163
|
+
it "should load the resource into a properly-named class and emit a warning about deprecation when accessing it" do
|
164
|
+
expect { Chef::Resource::LwrpFoo }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
|
119
165
|
end
|
120
166
|
|
121
|
-
it "should
|
122
|
-
expect(Chef::
|
167
|
+
it "should be resolvable with Chef::ResourceResolver.resolve(:lwrp_foo)" do
|
168
|
+
expect(Chef::ResourceResolver.resolve(:lwrp_foo, node: Chef::Node.new)).to eq(get_lwrp(:lwrp_foo))
|
123
169
|
end
|
124
170
|
|
125
171
|
it "should set resource_name" do
|
126
|
-
expect(
|
172
|
+
expect(get_lwrp(:lwrp_foo).new("blah").resource_name).to eql(:lwrp_foo)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should output the resource_name in .to_s" do
|
176
|
+
expect(get_lwrp(:lwrp_foo).new("blah").to_s).to eq "lwrp_foo[blah]"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should have a class that outputs a reasonable string" do
|
180
|
+
expect(get_lwrp(:lwrp_foo).to_s).to eq "LWRP resource lwrp_foo from cookbook lwrp"
|
127
181
|
end
|
128
182
|
|
129
183
|
it "should add the specified actions to the allowed_actions array" do
|
130
|
-
expect(
|
184
|
+
expect(get_lwrp(:lwrp_foo).new("blah").allowed_actions).to include(:pass_buck, :twiddle_thumbs)
|
131
185
|
end
|
132
186
|
|
133
187
|
it "should set the specified action as the default action" do
|
134
|
-
expect(
|
188
|
+
expect(get_lwrp(:lwrp_foo).new("blah").action).to eq([:pass_buck])
|
135
189
|
end
|
136
190
|
|
137
191
|
it "should create a method for each attribute" do
|
138
|
-
expect(
|
192
|
+
expect(get_lwrp(:lwrp_foo).new("blah").methods.map{ |m| m.to_sym}).to include(:monkey)
|
139
193
|
end
|
140
194
|
|
141
195
|
it "should build attribute methods that respect validation rules" do
|
142
|
-
expect {
|
196
|
+
expect { get_lwrp(:lwrp_foo).new("blah").monkey(42) }.to raise_error(ArgumentError)
|
143
197
|
end
|
144
198
|
|
145
199
|
it "should have access to the run context and node during class definition" do
|
@@ -151,7 +205,7 @@ describe "LWRP" do
|
|
151
205
|
Chef::Resource::LWRPBase.build_from_file("lwrp", file, run_context)
|
152
206
|
end
|
153
207
|
|
154
|
-
cls =
|
208
|
+
cls = get_lwrp(:lwrp_nodeattr)
|
155
209
|
expect(cls.node).to be_kind_of(Chef::Node)
|
156
210
|
expect(cls.run_context).to be_kind_of(Chef::RunContext)
|
157
211
|
expect(cls.node[:penguin_name]).to eql("jackass")
|
@@ -235,7 +289,7 @@ describe "LWRP" do
|
|
235
289
|
end
|
236
290
|
|
237
291
|
it "delegates #default_action to the parent" do
|
238
|
-
expect(child.default_action).to eq(:eat)
|
292
|
+
expect(child.default_action).to eq([:eat])
|
239
293
|
end
|
240
294
|
end
|
241
295
|
|
@@ -252,7 +306,7 @@ describe "LWRP" do
|
|
252
306
|
end
|
253
307
|
|
254
308
|
it "does not delegate #default_action to the parent" do
|
255
|
-
expect(child.default_action).to eq(:dont_eat)
|
309
|
+
expect(child.default_action).to eq([:dont_eat])
|
256
310
|
end
|
257
311
|
end
|
258
312
|
|
@@ -291,48 +345,48 @@ describe "LWRP" do
|
|
291
345
|
end
|
292
346
|
|
293
347
|
before(:each) do
|
294
|
-
Dir[File.expand_path(File.
|
348
|
+
Dir[File.expand_path(File.expand_path("../../data/lwrp/resources/*", __FILE__))].each do |file|
|
295
349
|
Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context)
|
296
350
|
end
|
297
351
|
|
298
|
-
Dir[File.expand_path(File.
|
299
|
-
Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context)
|
300
|
-
end
|
301
|
-
|
302
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp", "providers", "*"))].each do |file|
|
303
|
-
Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context)
|
304
|
-
end
|
305
|
-
|
306
|
-
Dir[File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "lwrp_override", "providers", "*"))].each do |file|
|
352
|
+
Dir[File.expand_path(File.expand_path("../../data/lwrp/providers/*", __FILE__))].each do |file|
|
307
353
|
Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context)
|
308
354
|
end
|
309
|
-
|
310
355
|
end
|
311
356
|
|
312
357
|
it "should properly handle a new_resource reference" do
|
313
|
-
resource =
|
358
|
+
resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
|
314
359
|
resource.monkey("bob")
|
315
|
-
resource.provider(:lwrp_monkey_name_printer)
|
316
|
-
resource.run_context = @run_context
|
360
|
+
resource.provider(get_lwrp_provider(:lwrp_monkey_name_printer))
|
317
361
|
|
318
362
|
provider = Chef::Platform.provider_for_resource(resource, :twiddle_thumbs)
|
319
363
|
provider.action_twiddle_thumbs
|
320
364
|
end
|
321
365
|
|
322
|
-
|
323
|
-
|
324
|
-
|
366
|
+
context "resource class created" do
|
367
|
+
before do
|
368
|
+
@old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
|
369
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
370
|
+
end
|
371
|
+
after do
|
372
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = @old_treat_deprecation_warnings_as_errors
|
373
|
+
end
|
325
374
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
375
|
+
it "should load the provider into a properly-named class" do
|
376
|
+
expect(Chef::Provider.const_get("LwrpBuckPasser")).to be_kind_of(Class)
|
377
|
+
expect(Chef::Provider::LwrpBuckPasser <= Chef::Provider::LWRPBase).to be_truthy
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should create a method for each action" do
|
381
|
+
expect(get_lwrp_provider(:lwrp_buck_passer).instance_methods).to include(:action_pass_buck)
|
382
|
+
expect(get_lwrp_provider(:lwrp_thumb_twiddler).instance_methods).to include(:action_twiddle_thumbs)
|
383
|
+
end
|
330
384
|
end
|
331
385
|
|
332
386
|
it "should insert resources embedded in the provider into the middle of the resource collection" do
|
333
|
-
injector =
|
387
|
+
injector = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
|
334
388
|
injector.action(:pass_buck)
|
335
|
-
injector.provider(:lwrp_buck_passer)
|
389
|
+
injector.provider(get_lwrp_provider(:lwrp_buck_passer))
|
336
390
|
dummy = Chef::Resource::ZenMaster.new("keanu reeves", @run_context)
|
337
391
|
dummy.provider(Chef::Provider::Easy)
|
338
392
|
@run_context.resource_collection.insert(injector)
|
@@ -347,13 +401,13 @@ describe "LWRP" do
|
|
347
401
|
end
|
348
402
|
|
349
403
|
it "should insert embedded resources from multiple providers, including from the last position, properly into the resource collection" do
|
350
|
-
injector =
|
404
|
+
injector = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
|
351
405
|
injector.action(:pass_buck)
|
352
|
-
injector.provider(:lwrp_buck_passer)
|
406
|
+
injector.provider(get_lwrp_provider(:lwrp_buck_passer))
|
353
407
|
|
354
|
-
injector2 =
|
408
|
+
injector2 = get_lwrp(:lwrp_bar).new("tank", @run_context)
|
355
409
|
injector2.action(:pass_buck)
|
356
|
-
injector2.provider(:lwrp_buck_passer_2)
|
410
|
+
injector2.provider(get_lwrp_provider(:lwrp_buck_passer_2))
|
357
411
|
|
358
412
|
dummy = Chef::Resource::ZenMaster.new("keanu reeves", @run_context)
|
359
413
|
dummy.provider(Chef::Provider::Easy)
|
@@ -374,9 +428,9 @@ describe "LWRP" do
|
|
374
428
|
end
|
375
429
|
|
376
430
|
it "should properly handle a new_resource reference" do
|
377
|
-
resource =
|
431
|
+
resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
|
378
432
|
resource.monkey("bob")
|
379
|
-
resource.provider(:lwrp_monkey_name_printer)
|
433
|
+
resource.provider(get_lwrp_provider(:lwrp_monkey_name_printer))
|
380
434
|
|
381
435
|
provider = Chef::Platform.provider_for_resource(resource, :twiddle_thumbs)
|
382
436
|
provider.action_twiddle_thumbs
|
@@ -385,9 +439,9 @@ describe "LWRP" do
|
|
385
439
|
end
|
386
440
|
|
387
441
|
it "should properly handle an embedded Resource accessing the enclosing Provider's scope" do
|
388
|
-
resource =
|
442
|
+
resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
|
389
443
|
resource.monkey("bob")
|
390
|
-
resource.provider(:lwrp_embedded_resource_accesses_providers_scope)
|
444
|
+
resource.provider(get_lwrp_provider(:lwrp_embedded_resource_accesses_providers_scope))
|
391
445
|
|
392
446
|
provider = Chef::Platform.provider_for_resource(resource, :twiddle_thumbs)
|
393
447
|
#provider = @runner.build_provider(resource)
|
@@ -404,10 +458,10 @@ describe "LWRP" do
|
|
404
458
|
# Side effect of lwrp_inline_compiler provider for testing notifications.
|
405
459
|
$interior_ruby_block_2 = nil
|
406
460
|
# resource type doesn't matter, so make an existing resource type work with provider.
|
407
|
-
@resource =
|
461
|
+
@resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
|
408
462
|
@resource.allowed_actions << :test
|
409
463
|
@resource.action(:test)
|
410
|
-
@resource.provider(:lwrp_inline_compiler)
|
464
|
+
@resource.provider(get_lwrp_provider(:lwrp_inline_compiler))
|
411
465
|
end
|
412
466
|
|
413
467
|
it "does not add interior resources to the exterior resource collection" do
|