chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/chef/util/backup.rb
CHANGED
@@ -78,8 +78,16 @@ class Chef
|
|
78
78
|
Chef::Log.info("#{@new_resource} removed backup at #{backup_file}")
|
79
79
|
end
|
80
80
|
|
81
|
+
def unsorted_backup_files
|
82
|
+
# If you replace this with Dir[], you will probably break Windows.
|
83
|
+
fn = Regexp.escape(::File.basename(path))
|
84
|
+
Dir.entries(::File.dirname(backup_path)).select do |f|
|
85
|
+
!!(f =~ /\A#{fn}.chef-[0-9.]*\B/)
|
86
|
+
end.map {|f| ::File.join(::File.dirname(backup_path), f)}
|
87
|
+
end
|
88
|
+
|
81
89
|
def sorted_backup_files
|
82
|
-
|
90
|
+
unsorted_backup_files.sort { |a,b| b <=> a }
|
83
91
|
end
|
84
92
|
end
|
85
93
|
end
|
data/lib/chef/version.rb
CHANGED
@@ -46,22 +46,12 @@ describe Chef::Audit::Runner do
|
|
46
46
|
RSpec::Core::Sandbox.sandboxed { ex.run }
|
47
47
|
end
|
48
48
|
|
49
|
-
before do
|
50
|
-
Chef::Config[:log_location] = stdout
|
51
|
-
end
|
52
|
-
|
53
49
|
describe "#run" do
|
54
50
|
|
55
51
|
let(:audits) { {} }
|
56
52
|
let(:run_context) { instance_double(Chef::RunContext, :events => events, :audits => audits) }
|
57
53
|
let(:control_group_name) { "control_group_name" }
|
58
54
|
|
59
|
-
it "Correctly runs an empty controls block" do
|
60
|
-
in_sub_process do
|
61
|
-
runner.run
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
55
|
shared_context "passing audit" do
|
66
56
|
let(:audits) do
|
67
57
|
should_pass = lambda do
|
@@ -84,50 +74,40 @@ describe Chef::Audit::Runner do
|
|
84
74
|
end
|
85
75
|
end
|
86
76
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
runner.run
|
92
|
-
|
93
|
-
expect(stdout.string).to match(/1 example, 0 failures/)
|
77
|
+
describe "log location is stdout" do
|
78
|
+
before do
|
79
|
+
allow(Chef::Log).to receive(:info) do |msg|
|
80
|
+
stdout.puts(msg)
|
94
81
|
end
|
95
82
|
end
|
96
|
-
end
|
97
83
|
|
98
|
-
|
99
|
-
include_context "failing audit"
|
100
|
-
it "correctly runs" do
|
84
|
+
it "Correctly runs an empty controls block" do
|
101
85
|
in_sub_process do
|
102
86
|
runner.run
|
103
|
-
|
104
|
-
expect(stdout.string).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/)
|
105
|
-
expect(stdout.string).to match(/1 example, 1 failure/)
|
106
|
-
expect(stdout.string).to match(/# control_group_name should fail/)
|
107
87
|
end
|
108
88
|
end
|
109
|
-
end
|
110
89
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
90
|
+
context "there is a single successful control" do
|
91
|
+
include_context "passing audit"
|
92
|
+
it "correctly runs" do
|
93
|
+
in_sub_process do
|
94
|
+
runner.run
|
116
95
|
|
117
|
-
|
118
|
-
|
119
|
-
|
96
|
+
expect(stdout.string).to match(/1 example, 0 failures/)
|
97
|
+
end
|
98
|
+
end
|
120
99
|
end
|
121
100
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
101
|
+
context "there is a single failing control" do
|
102
|
+
include_context "failing audit"
|
103
|
+
it "correctly runs" do
|
104
|
+
in_sub_process do
|
105
|
+
runner.run
|
126
106
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
107
|
+
expect(stdout.string).to match(/Failure\/Error: expect\(2 - 1\)\.to eq\(0\)/)
|
108
|
+
expect(stdout.string).to match(/1 example, 1 failure/)
|
109
|
+
expect(stdout.string).to match(/# control_group_name should fail/)
|
110
|
+
end
|
131
111
|
end
|
132
112
|
end
|
133
113
|
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
require 'chef/mixin/powershell_out'
|
20
|
+
|
21
|
+
describe Chef::Mixin::PowershellOut, windows_only: true do
|
22
|
+
include Chef::Mixin::PowershellOut
|
23
|
+
|
24
|
+
describe "#powershell_out" do
|
25
|
+
it "runs a powershell command and collects stdout" do
|
26
|
+
expect(powershell_out("get-process").run_command.stdout).to match /Handles\s+NPM\(K\)\s+PM\(K\)\s+WS\(K\)\s+VM\(M\)\s+CPU\(s\)\s+Id\s+ProcessName/
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not raise exceptions when the command is invalid" do
|
30
|
+
powershell_out("this-is-not-a-valid-command").run_command
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#powershell_out!" do
|
35
|
+
it "runs a powershell command and collects stdout" do
|
36
|
+
expect(powershell_out!("get-process").run_command.stdout).to match /Handles\s+NPM\(K\)\s+PM\(K\)\s+WS\(K\)\s+VM\(M\)\s+CPU\(s\)\s+Id\s+ProcessName/
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises exceptions when the command is invalid" do
|
40
|
+
expect { powershell_out!("this-is-not-a-valid-command").run_command }.to raise_exception(Mixlib::ShellOut::ShellCommandFailed)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -137,9 +137,16 @@ describe Chef::Resource::Execute do
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
# Ensure that CommandTimeout is raised, and is caused by resource.timeout really expiring.
|
141
|
+
# https://github.com/chef/chef/issues/2985
|
142
|
+
#
|
143
|
+
# resource.timeout should be short, this is what we're testing
|
144
|
+
# resource.command ruby sleep timer should be longer than resource.timeout to give us something to timeout
|
145
|
+
# Timeout::timeout should be longer than resource.timeout, but less than the resource.command ruby sleep timer,
|
146
|
+
# so we fail if we finish on resource.command instead of resource.timeout, but raise CommandTimeout anyway (#2175).
|
140
147
|
it "times out when a timeout is set on the resource" do
|
141
|
-
Timeout::timeout(
|
142
|
-
resource.command %{ruby -e 'sleep
|
148
|
+
Timeout::timeout(30) do
|
149
|
+
resource.command %{ruby -e 'sleep 300'}
|
143
150
|
resource.timeout 0.1
|
144
151
|
expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::CommandTimeout)
|
145
152
|
end
|
@@ -86,6 +86,31 @@ describe Chef::Resource::File do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
|
90
|
+
describe "when using backup" do
|
91
|
+
before do
|
92
|
+
Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
|
93
|
+
resource_without_content.backup(1)
|
94
|
+
resource_without_content.run_action(:create)
|
95
|
+
end
|
96
|
+
|
97
|
+
let(:backup_glob) { File.join(CHEF_SPEC_BACKUP_PATH, test_file_dir.sub(/^([A-Za-z]:)/, ""), "#{file_base}*") }
|
98
|
+
|
99
|
+
let(:path) do
|
100
|
+
# Use native system path
|
101
|
+
ChefConfig::PathHelper.canonical_path(File.join(test_file_dir, make_tmpname(file_base)), false)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "only stores the number of requested backups" do
|
105
|
+
resource_without_content.content('foo')
|
106
|
+
resource_without_content.run_action(:create)
|
107
|
+
resource_without_content.content('bar')
|
108
|
+
resource_without_content.run_action(:create)
|
109
|
+
expect(Dir.glob(backup_glob).length).to eq(1)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
89
114
|
# github issue 1842.
|
90
115
|
describe "when running action :create on a relative path" do
|
91
116
|
before do
|
@@ -372,6 +372,11 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
|
|
372
372
|
let(:tested_action) { :manage }
|
373
373
|
|
374
374
|
describe "when there is no group" do
|
375
|
+
before(:each) do
|
376
|
+
group_resource.run_action(:remove)
|
377
|
+
group_should_not_exist(group_name)
|
378
|
+
end
|
379
|
+
|
375
380
|
it "raises an error on modify" do
|
376
381
|
expect { group_resource.run_action(:modify) }.to raise_error
|
377
382
|
end
|
@@ -348,8 +348,7 @@ describe Chef::Resource::Link do
|
|
348
348
|
end
|
349
349
|
it_behaves_like 'delete errors out'
|
350
350
|
end
|
351
|
-
|
352
|
-
end
|
351
|
+
|
353
352
|
it_behaves_like 'a securable resource without existing target' do
|
354
353
|
let(:path) { target_file }
|
355
354
|
def allowed_acl(sid, expected_perms)
|
@@ -360,7 +359,7 @@ describe Chef::Resource::Link do
|
|
360
359
|
end
|
361
360
|
def parent_inheritable_acls
|
362
361
|
dummy_file_path = File.join(test_file_dir, "dummy_file")
|
363
|
-
|
362
|
+
FileUtils.touch(dummy_file_path)
|
364
363
|
dummy_desc = get_security_descriptor(dummy_file_path)
|
365
364
|
FileUtils.rm_rf(dummy_file_path)
|
366
365
|
dummy_desc
|
@@ -416,8 +415,6 @@ describe Chef::Resource::Link do
|
|
416
415
|
end
|
417
416
|
end
|
418
417
|
end
|
419
|
-
context "when the link destination is not readable to this user", :skip => true do
|
420
|
-
end
|
421
418
|
context "when the link destination does not exist" do
|
422
419
|
include_context 'create symbolic link succeeds'
|
423
420
|
include_context 'delete is noop'
|
@@ -518,8 +515,6 @@ describe Chef::Resource::Link do
|
|
518
515
|
end
|
519
516
|
it_behaves_like 'delete errors out'
|
520
517
|
end
|
521
|
-
context "and the link already exists and is not writeable to this user", :skip => true do
|
522
|
-
end
|
523
518
|
context "and specifies security attributes" do
|
524
519
|
before(:each) do
|
525
520
|
resource.owner(windows? ? 'Guest' : 'nobody')
|
@@ -559,10 +554,10 @@ describe Chef::Resource::Link do
|
|
559
554
|
end
|
560
555
|
context 'and the link does not yet exist' do
|
561
556
|
it 'links to the target file' do
|
557
|
+
skip('OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks') if (os_x? or freebsd? or aix?)
|
562
558
|
resource.run_action(:create)
|
563
559
|
expect(File.exists?(target_file)).to be_truthy
|
564
560
|
# OS X gets angry about this sort of link. Bug in OS X, IMO.
|
565
|
-
pending('OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks') if (os_x? or freebsd? or aix?)
|
566
561
|
expect(symlink?(target_file)).to be_truthy
|
567
562
|
expect(readlink(target_file)).to eq(canonicalize(@other_target))
|
568
563
|
end
|
@@ -578,7 +573,7 @@ describe Chef::Resource::Link do
|
|
578
573
|
end
|
579
574
|
context 'and the link does not yet exist' do
|
580
575
|
it 'links to the target file' do
|
581
|
-
|
576
|
+
skip('OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks') if (os_x? or freebsd? or aix?)
|
582
577
|
resource.run_action(:create)
|
583
578
|
# Windows and Unix have different definitions of exists? here, and that's OK.
|
584
579
|
if windows?
|
@@ -593,8 +588,7 @@ describe Chef::Resource::Link do
|
|
593
588
|
end
|
594
589
|
end
|
595
590
|
end
|
596
|
-
|
597
|
-
end
|
591
|
+
|
598
592
|
context "when the link destination does not exist" do
|
599
593
|
context 'and the link does not yet exist' do
|
600
594
|
it 'create errors out' do
|
@@ -56,14 +56,13 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
|
|
56
56
|
resource.run_action(:run)
|
57
57
|
end
|
58
58
|
|
59
|
-
it "returns the
|
60
|
-
# This is broken on Powershell < 4.0
|
59
|
+
it "returns the exit status 27 for a powershell script that exits with 27" do
|
61
60
|
file = Tempfile.new(['foo', '.ps1'])
|
62
61
|
begin
|
63
|
-
file.write "exit
|
62
|
+
file.write "exit 27"
|
64
63
|
file.close
|
65
64
|
resource.code(". \"#{file.path}\"")
|
66
|
-
resource.returns(
|
65
|
+
resource.returns(27)
|
67
66
|
resource.run_action(:run)
|
68
67
|
ensure
|
69
68
|
file.close
|
@@ -71,6 +70,30 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
|
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
73
|
+
let (:negative_exit_status) { -27 }
|
74
|
+
let (:unsigned_exit_status) { (-negative_exit_status ^ 65535) + 1 }
|
75
|
+
it "returns the exit status -27 as a signed integer or an unsigned 16-bit 2's complement value of 65509 for a powershell script that exits with -27" do
|
76
|
+
# Versions of PowerShell prior to 4.0 return a 16-bit unsigned value --
|
77
|
+
# PowerShell 4.0 and later versions return a 32-bit signed value.
|
78
|
+
file = Tempfile.new(['foo', '.ps1'])
|
79
|
+
begin
|
80
|
+
file.write "exit #{negative_exit_status.to_s}"
|
81
|
+
file.close
|
82
|
+
resource.code(". \"#{file.path}\"")
|
83
|
+
|
84
|
+
# PowerShell earlier than 4.0 takes negative exit codes
|
85
|
+
# and returns them as the underlying unsigned 16-bit
|
86
|
+
# 2's complement representation. We cover multiple versions
|
87
|
+
# of PowerShell in this example by including both the signed
|
88
|
+
# exit code and its converted counterpart as permitted return values.
|
89
|
+
# See http://support.microsoft.com/en-us/kb/2646183/zh-cn
|
90
|
+
resource.returns([negative_exit_status, unsigned_exit_status])
|
91
|
+
expect { resource.run_action(:run) }.not_to raise_error
|
92
|
+
ensure
|
93
|
+
file.close
|
94
|
+
file.unlink
|
95
|
+
end
|
96
|
+
end
|
74
97
|
|
75
98
|
it "returns the process exit code" do
|
76
99
|
resource.code(arbitrary_nonzero_process_exit_code_content)
|
@@ -99,7 +122,19 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
|
|
99
122
|
it "returns 1 if the last command was a cmdlet that failed and was preceded by a successfully executed non-cmdlet Windows binary" do
|
100
123
|
resource.code([windows_process_exit_code_success_content, cmdlet_exit_code_not_found_content].join(';'))
|
101
124
|
resource.returns(1)
|
102
|
-
resource.run_action(:run)
|
125
|
+
expect { resource.run_action(:run) }.not_to raise_error
|
126
|
+
end
|
127
|
+
|
128
|
+
it "raises an error if the script is not syntactically correct and returns is not set to 1" do
|
129
|
+
resource.code('if({)')
|
130
|
+
resource.returns(0)
|
131
|
+
expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns 1 if the script provided to the code attribute is not syntactically correct" do
|
135
|
+
resource.code('if({)')
|
136
|
+
resource.returns(1)
|
137
|
+
expect { resource.run_action(:run) }.not_to raise_error
|
103
138
|
end
|
104
139
|
|
105
140
|
# This somewhat ambiguous case, two failures of different types,
|
@@ -65,8 +65,12 @@ describe Chef::Provider::User::Useradd, metadata do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
OHAI_SYSTEM["platform_family"] == "debian"
|
68
|
+
def self.quote_in_username_unsupported?
|
69
|
+
if OHAI_SYSTEM["platform_family"] == "debian"
|
70
|
+
false
|
71
|
+
else
|
72
|
+
"Only debian family systems support quotes in username"
|
73
|
+
end
|
70
74
|
end
|
71
75
|
|
72
76
|
def password_should_be_set
|
@@ -108,7 +112,7 @@ describe Chef::Provider::User::Useradd, metadata do
|
|
108
112
|
break if status.exitstatus != 8
|
109
113
|
|
110
114
|
sleep 1
|
111
|
-
max_retries = max_retries -1
|
115
|
+
max_retries = max_retries - 1
|
112
116
|
rescue UserNotFound
|
113
117
|
break
|
114
118
|
end
|
@@ -162,15 +166,10 @@ describe Chef::Provider::User::Useradd, metadata do
|
|
162
166
|
end
|
163
167
|
end
|
164
168
|
|
165
|
-
let(:skip) { false }
|
166
|
-
|
167
169
|
describe "action :create" do
|
168
170
|
|
169
171
|
context "when the user does not exist beforehand" do
|
170
172
|
before do
|
171
|
-
if reason = skip
|
172
|
-
pending(reason)
|
173
|
-
end
|
174
173
|
user_resource.run_action(:create)
|
175
174
|
expect(user_resource).to be_updated_by_last_action
|
176
175
|
end
|
@@ -186,14 +185,7 @@ describe Chef::Provider::User::Useradd, metadata do
|
|
186
185
|
# tabulation: '\t', etc.). Note that using a slash ('/') may break the
|
187
186
|
# default algorithm for the definition of the user's home directory.
|
188
187
|
|
189
|
-
context "and the username contains a single quote" do
|
190
|
-
let(:skip) do
|
191
|
-
if supports_quote_in_username?
|
192
|
-
false
|
193
|
-
else
|
194
|
-
"Platform #{OHAI_SYSTEM["platform"]} not expected to support username w/ quote"
|
195
|
-
end
|
196
|
-
end
|
188
|
+
context "and the username contains a single quote", skip: quote_in_username_unsupported? do
|
197
189
|
|
198
190
|
let(:username) { "t'bilisi" }
|
199
191
|
|
@@ -342,7 +334,7 @@ describe Chef::Provider::User::Useradd, metadata do
|
|
342
334
|
|
343
335
|
before do
|
344
336
|
if reason = skip
|
345
|
-
|
337
|
+
skip(reason)
|
346
338
|
end
|
347
339
|
existing_user.run_action(:create)
|
348
340
|
expect(existing_user).to be_updated_by_last_action
|
@@ -535,7 +527,7 @@ describe Chef::Provider::User::Useradd, metadata do
|
|
535
527
|
|
536
528
|
def aix_user_lock_status
|
537
529
|
lock_info = shell_out!("lsuser -a account_locked #{username}")
|
538
|
-
|
530
|
+
/\S+\s+account_locked=(\S+)/.match(lock_info.stdout)[1]
|
539
531
|
end
|
540
532
|
|
541
533
|
def user_account_should_be_locked
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'support/shared/integration/integration_helper'
|
2
|
+
require 'chef/mixin/shell_out'
|
3
|
+
|
4
|
+
describe "LWRPs" do
|
5
|
+
include IntegrationSupport
|
6
|
+
include Chef::Mixin::ShellOut
|
7
|
+
|
8
|
+
let(:chef_dir) { File.expand_path("../../../../bin", __FILE__) }
|
9
|
+
|
10
|
+
# Invoke `chef-client` as `ruby PATH/TO/chef-client`. This ensures the
|
11
|
+
# following constraints are satisfied:
|
12
|
+
# * Windows: windows can only run batch scripts as bare executables. Rubygems
|
13
|
+
# creates batch wrappers for installed gems, but we don't have batch wrappers
|
14
|
+
# in the source tree.
|
15
|
+
# * Other `chef-client` in PATH: A common case is running the tests on a
|
16
|
+
# machine that has omnibus chef installed. In that case we need to ensure
|
17
|
+
# we're running `chef-client` from the source tree and not the external one.
|
18
|
+
# cf. CHEF-4914
|
19
|
+
let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" }
|
20
|
+
|
21
|
+
when_the_repository "has a cookbook named l-w-r-p" do
|
22
|
+
before do
|
23
|
+
directory 'cookbooks/l-w-r-p' do
|
24
|
+
|
25
|
+
file 'resources/foo.rb', <<EOM
|
26
|
+
default_action :create
|
27
|
+
EOM
|
28
|
+
file 'providers/foo.rb', <<EOM
|
29
|
+
action :create do
|
30
|
+
end
|
31
|
+
EOM
|
32
|
+
|
33
|
+
file 'recipes/default.rb', <<EOM
|
34
|
+
l_w_r_p_foo "me"
|
35
|
+
EOM
|
36
|
+
|
37
|
+
end # directory 'cookbooks/x'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should complete with success" do
|
41
|
+
file 'config/client.rb', <<EOM
|
42
|
+
local_mode true
|
43
|
+
cookbook_path "#{path_to('cookbooks')}"
|
44
|
+
log_level :warn
|
45
|
+
EOM
|
46
|
+
|
47
|
+
result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'l-w-r-p::default'", :cwd => chef_dir)
|
48
|
+
actual = result.stdout.lines.map { |l| l.chomp }.join("\n")
|
49
|
+
expected = <<EOM
|
50
|
+
* l_w_r_p_foo[me] action create (up to date)
|
51
|
+
EOM
|
52
|
+
expected = expected.lines.map { |l| l.chomp }.join("\n")
|
53
|
+
expect(actual).to include(expected)
|
54
|
+
result.error!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|