chef 12.5.1-universal-mingw32 → 12.6.0-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/Gemfile +6 -1
- data/README.md +6 -4
- data/Rakefile +1 -4
- data/chef-windows.gemspec +21 -0
- data/chef.gemspec +58 -0
- data/lib/chef/api_client/registration.rb +9 -4
- data/lib/chef/application.rb +3 -84
- data/lib/chef/application/apply.rb +9 -2
- data/lib/chef/application/client.rb +8 -3
- data/lib/chef/application/solo.rb +7 -1
- data/lib/chef/application/windows_service.rb +21 -6
- data/lib/chef/application/windows_service_manager.rb +2 -3
- data/lib/chef/audit/runner.rb +1 -0
- data/lib/chef/chef_class.rb +1 -11
- data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
- data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
- data/lib/chef/client.rb +28 -1
- data/lib/chef/cookbook/cookbook_collection.rb +14 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
- data/lib/chef/cookbook/metadata.rb +115 -9
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
- data/lib/chef/cookbook_version.rb +6 -2
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/digester.rb +5 -1
- data/lib/chef/dsl/chef_provisioning.rb +57 -0
- data/lib/chef/dsl/cheffish.rb +64 -0
- data/lib/chef/dsl/declare_resource.rb +108 -0
- data/lib/chef/dsl/platform_introspection.rb +3 -3
- data/lib/chef/dsl/recipe.rb +3 -73
- data/lib/chef/dsl/resources.rb +27 -1
- data/lib/chef/event_dispatch/base.rb +3 -0
- data/lib/chef/event_dispatch/dispatcher.rb +5 -0
- data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
- data/lib/chef/exceptions.rb +21 -1
- data/lib/chef/file_access_control/unix.rb +12 -12
- data/lib/chef/file_content_management/deploy/cp.rb +2 -2
- data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
- data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
- data/lib/chef/formatters/base.rb +7 -0
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
- data/lib/chef/formatters/indentable_output_stream.rb +5 -0
- data/lib/chef/http.rb +19 -3
- data/lib/chef/http/decompressor.rb +2 -2
- data/lib/chef/json_compat.rb +1 -0
- data/lib/chef/knife.rb +16 -2
- data/lib/chef/knife/bootstrap.rb +55 -10
- data/lib/chef/knife/cookbook_site_install.rb +5 -1
- data/lib/chef/knife/core/bootstrap_context.rb +2 -1
- data/lib/chef/knife/core/node_presenter.rb +1 -1
- data/lib/chef/knife/ssh.rb +30 -16
- data/lib/chef/knife/ssl_check.rb +4 -2
- data/lib/chef/knife/ssl_fetch.rb +3 -2
- data/lib/chef/knife/status.rb +14 -1
- data/lib/chef/log.rb +14 -0
- data/lib/chef/mixin/get_source_from_package.rb +7 -2
- data/lib/chef/mixin/properties.rb +302 -0
- data/lib/chef/mixin/proxified_socket.rb +38 -0
- data/lib/chef/mixin/subclass_directive.rb +37 -0
- data/lib/chef/node.rb +13 -5
- data/lib/chef/platform/query_helpers.rb +14 -3
- data/lib/chef/platform/service_helpers.rb +20 -38
- data/lib/chef/policy_builder/expand_node_object.rb +3 -0
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/property.rb +51 -12
- data/lib/chef/provider.rb +40 -35
- data/lib/chef/provider/deploy.rb +1 -1
- data/lib/chef/provider/dsc_resource.rb +54 -20
- data/lib/chef/provider/execute.rb +25 -4
- data/lib/chef/provider/group.rb +1 -1
- data/lib/chef/provider/lwrp_base.rb +1 -0
- data/lib/chef/provider/package.rb +76 -30
- data/lib/chef/provider/package/dpkg.rb +152 -69
- data/lib/chef/provider/package/openbsd.rb +6 -8
- data/lib/chef/provider/package/solaris.rb +2 -0
- data/lib/chef/provider/package/windows.rb +95 -14
- data/lib/chef/provider/package/windows/exe.rb +129 -0
- data/lib/chef/provider/package/windows/msi.rb +37 -13
- data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
- data/lib/chef/provider/package/yum.rb +13 -3
- data/lib/chef/provider/powershell_script.rb +3 -0
- data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
- data/lib/chef/provider/remote_file/http.rb +1 -1
- data/lib/chef/provider/script.rb +1 -0
- data/lib/chef/provider/service.rb +13 -10
- data/lib/chef/provider/service/solaris.rb +43 -17
- data/lib/chef/provider/service/upstart.rb +3 -3
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/dscl.rb +111 -100
- data/lib/chef/provider/user/windows.rb +5 -3
- data/lib/chef/recipe.rb +3 -5
- data/lib/chef/resource.rb +77 -320
- data/lib/chef/resource/action_class.rb +4 -0
- data/lib/chef/resource/dpkg_package.rb +4 -3
- data/lib/chef/resource/dsc_resource.rb +40 -2
- data/lib/chef/resource/execute.rb +9 -1
- data/lib/chef/resource/ksh.rb +32 -0
- data/lib/chef/resource/lwrp_base.rb +6 -10
- data/lib/chef/resource/package.rb +8 -9
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/resource_notification.rb +14 -1
- data/lib/chef/resource/script.rb +1 -1
- data/lib/chef/resource/windows_package.rb +1 -1
- data/lib/chef/resource_builder.rb +14 -7
- data/lib/chef/resource_reporter.rb +6 -0
- data/lib/chef/resources.rb +1 -7
- data/lib/chef/rest.rb +1 -1
- data/lib/chef/run_context.rb +45 -2
- data/lib/chef/run_list/run_list_expansion.rb +47 -0
- data/lib/chef/runner.rb +25 -0
- data/lib/chef/search/query.rb +16 -2
- data/lib/chef/util/diff.rb +2 -2
- data/lib/chef/util/powershell/ps_credential.rb +2 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api/file.rb +51 -1
- data/lib/chef/win32/file.rb +5 -0
- data/lib/chef/win32/file/version_info.rb +93 -0
- data/lib/chef/win32/mutex.rb +1 -1
- data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
- data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
- data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
- data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
- data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
- data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
- data/spec/functional/application_spec.rb +1 -1
- data/spec/functional/audit/runner_spec.rb +4 -0
- data/spec/functional/knife/ssh_spec.rb +5 -5
- data/spec/functional/notifications_spec.rb +74 -4
- data/spec/functional/resource/aix_service_spec.rb +2 -2
- data/spec/functional/resource/dpkg_package_spec.rb +339 -0
- data/spec/functional/resource/ifconfig_spec.rb +3 -1
- data/spec/functional/resource/mount_spec.rb +5 -2
- data/spec/functional/resource/package_spec.rb +1 -1
- data/spec/functional/resource/user/windows_spec.rb +8 -0
- data/spec/functional/resource/windows_package_spec.rb +177 -0
- data/spec/functional/win32/version_info_spec.rb +50 -0
- data/spec/integration/client/client_spec.rb +80 -0
- data/spec/integration/knife/download_spec.rb +9 -0
- data/spec/integration/knife/upload_spec.rb +28 -1
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
- data/spec/integration/recipes/resource_action_spec.rb +211 -116
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
- data/spec/integration/solo/solo_spec.rb +34 -0
- data/spec/spec_helper.rb +11 -1
- data/spec/support/platform_helpers.rb +8 -0
- data/spec/support/shared/integration/integration_helper.rb +6 -0
- data/spec/support/shared/unit/execute_resource.rb +5 -0
- data/spec/support/shared/unit/platform_introspector.rb +7 -0
- data/spec/tiny_server.rb +6 -2
- data/spec/unit/api_client/registration_spec.rb +5 -4
- data/spec/unit/application_spec.rb +1 -181
- data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
- data/spec/unit/cookbook/metadata_spec.rb +122 -2
- data/spec/unit/http_spec.rb +102 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -13
- data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
- data/spec/unit/knife/ssl_check_spec.rb +7 -3
- data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
- data/spec/unit/knife/status_spec.rb +13 -13
- data/spec/unit/knife_spec.rb +26 -2
- data/spec/unit/lwrp_spec.rb +1 -1
- data/spec/unit/mixin/properties_spec.rb +97 -0
- data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
- data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
- data/spec/unit/node_spec.rb +9 -1
- data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
- data/spec/unit/property/validation_spec.rb +14 -12
- data/spec/unit/property_spec.rb +56 -0
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/dsc_resource_spec.rb +63 -24
- data/spec/unit/provider/execute_spec.rb +95 -28
- data/spec/unit/provider/package/dpkg_spec.rb +185 -96
- data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
- data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
- data/spec/unit/provider/package/windows_spec.rb +227 -26
- data/spec/unit/provider/package/yum_spec.rb +6 -0
- data/spec/unit/provider/package_spec.rb +495 -366
- data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
- data/spec/unit/provider/script_spec.rb +2 -2
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
- data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
- data/spec/unit/provider/user/dscl_spec.rb +14 -0
- data/spec/unit/provider/user/windows_spec.rb +2 -2
- data/spec/unit/provider/user_spec.rb +9 -0
- data/spec/unit/provider_resolver_spec.rb +6 -30
- data/spec/unit/recipe_spec.rb +46 -20
- data/spec/unit/resource/chef_gem_spec.rb +1 -1
- data/spec/unit/resource/dsc_resource_spec.rb +14 -3
- data/spec/unit/resource/ksh_spec.rb +40 -0
- data/spec/unit/resource/registry_key_spec.rb +2 -2
- data/spec/unit/resource/resource_notification_spec.rb +44 -45
- data/spec/unit/resource_reporter_spec.rb +7 -0
- data/spec/unit/resource_spec.rb +268 -253
- data/spec/unit/rest_spec.rb +2 -2
- data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
- data/spec/unit/search/query_spec.rb +19 -1
- data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
- data/spec/unit/windows_service_spec.rb +83 -38
- data/tasks/external_tests.rb +19 -9
- data/tasks/rspec.rb +1 -1
- metadata +70 -21
- data/spec/support/pedant/Gemfile +0 -3
- data/spec/support/pedant/pedant_config.rb +0 -129
- data/spec/support/pedant/run_pedant.rb +0 -63
- data/spec/support/pedant/stickywicket.pem +0 -27
- data/spec/unit/provider/package_spec.rbe +0 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
3
|
+
# Author:: Matt Wrock <matt@mattwrock.com>
|
4
|
+
# Copyright:: Copyright (c) 2011, 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 'chef/mixin/shell_out'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Package
|
25
|
+
class Windows
|
26
|
+
class Exe
|
27
|
+
include Chef::Mixin::ShellOut
|
28
|
+
|
29
|
+
def initialize(resource, installer_type, uninstall_entries)
|
30
|
+
@new_resource = resource
|
31
|
+
@installer_type = installer_type
|
32
|
+
@uninstall_entries = uninstall_entries
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :new_resource
|
36
|
+
attr_reader :installer_type
|
37
|
+
attr_reader :uninstall_entries
|
38
|
+
|
39
|
+
# From Chef::Provider::Package
|
40
|
+
def expand_options(options)
|
41
|
+
options ? " #{options}" : ""
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns a version if the package is installed or nil if it is not.
|
45
|
+
def installed_version
|
46
|
+
Chef::Log.debug("#{new_resource} checking package version")
|
47
|
+
current_installed_version
|
48
|
+
end
|
49
|
+
|
50
|
+
def package_version
|
51
|
+
new_resource.version || install_file_version
|
52
|
+
end
|
53
|
+
|
54
|
+
def install_package
|
55
|
+
Chef::Log.debug("#{new_resource} installing #{new_resource.installer_type} package '#{new_resource.source}'")
|
56
|
+
shell_out!(
|
57
|
+
[
|
58
|
+
"start",
|
59
|
+
"\"\"",
|
60
|
+
"/wait",
|
61
|
+
"\"#{new_resource.source}\"",
|
62
|
+
unattended_flags,
|
63
|
+
expand_options(new_resource.options),
|
64
|
+
"& exit %%%%ERRORLEVEL%%%%"
|
65
|
+
].join(" "), timeout: new_resource.timeout, returns: new_resource.returns
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def remove_package
|
70
|
+
uninstall_version = new_resource.version || current_installed_version
|
71
|
+
uninstall_entries.select { |entry| [uninstall_version].flatten.include?(entry.display_version) }
|
72
|
+
.map { |version| version.uninstall_string }.uniq.each do |uninstall_string|
|
73
|
+
Chef::Log.debug("Registry provided uninstall string for #{new_resource} is '#{uninstall_string}'")
|
74
|
+
shell_out!(uninstall_command(uninstall_string), { returns: new_resource.returns })
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def uninstall_command(uninstall_string)
|
81
|
+
uninstall_string.delete!('"')
|
82
|
+
uninstall_string = [
|
83
|
+
%q{/d"},
|
84
|
+
::File.dirname(uninstall_string),
|
85
|
+
%q{" },
|
86
|
+
::File.basename(uninstall_string),
|
87
|
+
expand_options(new_resource.options),
|
88
|
+
" ",
|
89
|
+
unattended_flags
|
90
|
+
].join
|
91
|
+
%Q{start "" /wait #{uninstall_string} & exit %%%%ERRORLEVEL%%%%}
|
92
|
+
end
|
93
|
+
|
94
|
+
def current_installed_version
|
95
|
+
@current_installed_version ||= uninstall_entries.count == 0 ? nil : begin
|
96
|
+
uninstall_entries.map { |entry| entry.display_version }.uniq
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def install_file_version
|
101
|
+
@install_file_version ||= begin
|
102
|
+
if ::File.exist?(@new_resource.source)
|
103
|
+
version_info = Chef::ReservedNames::Win32::File.version_info(new_resource.source)
|
104
|
+
file_version = version_info.FileVersion || version_info.ProductVersion
|
105
|
+
file_version == '' ? nil : file_version
|
106
|
+
else
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# http://unattended.sourceforge.net/installers.php
|
113
|
+
def unattended_flags
|
114
|
+
case installer_type
|
115
|
+
when :installshield
|
116
|
+
'/s /sms'
|
117
|
+
when :nsis
|
118
|
+
'/S /NCRC'
|
119
|
+
when :inno
|
120
|
+
'/VERYSILENT /SUPPRESSMSGBOXES /NORESTART'
|
121
|
+
when :wise
|
122
|
+
'/s'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -29,10 +29,14 @@ class Chef
|
|
29
29
|
include Chef::ReservedNames::Win32::API::Installer if (RUBY_PLATFORM =~ /mswin|mingw32|windows/) && Chef::Platform.supports_msi?
|
30
30
|
include Chef::Mixin::ShellOut
|
31
31
|
|
32
|
-
def initialize(resource)
|
32
|
+
def initialize(resource, uninstall_entries)
|
33
33
|
@new_resource = resource
|
34
|
+
@uninstall_entries = uninstall_entries
|
34
35
|
end
|
35
36
|
|
37
|
+
attr_reader :new_resource
|
38
|
+
attr_reader :uninstall_entries
|
39
|
+
|
36
40
|
# From Chef::Provider::Package
|
37
41
|
def expand_options(options)
|
38
42
|
options ? " #{options}" : ""
|
@@ -40,27 +44,47 @@ class Chef
|
|
40
44
|
|
41
45
|
# Returns a version if the package is installed or nil if it is not.
|
42
46
|
def installed_version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
if ::File.exist?(new_resource.source)
|
48
|
+
Chef::Log.debug("#{new_resource} getting product code for package at #{new_resource.source}")
|
49
|
+
product_code = get_product_property(new_resource.source, "ProductCode")
|
50
|
+
Chef::Log.debug("#{new_resource} checking package status and version for #{product_code}")
|
51
|
+
get_installed_version(product_code)
|
52
|
+
else
|
53
|
+
uninstall_entries.count == 0 ? nil : begin
|
54
|
+
uninstall_entries.map { |entry| entry.display_version }.uniq
|
55
|
+
end
|
56
|
+
end
|
47
57
|
end
|
48
58
|
|
49
59
|
def package_version
|
50
|
-
|
51
|
-
|
60
|
+
return new_resource.version if new_resource.version
|
61
|
+
if ::File.exist?(new_resource.source)
|
62
|
+
Chef::Log.debug("#{new_resource} getting product version for package at #{new_resource.source}")
|
63
|
+
get_product_property(new_resource.source, "ProductVersion")
|
64
|
+
end
|
52
65
|
end
|
53
66
|
|
54
|
-
def install_package
|
67
|
+
def install_package
|
55
68
|
# We could use MsiConfigureProduct here, but we'll start off with msiexec
|
56
|
-
Chef::Log.debug("#{
|
57
|
-
shell_out!("msiexec /qn /i \"#{
|
69
|
+
Chef::Log.debug("#{new_resource} installing MSI package '#{new_resource.source}'")
|
70
|
+
shell_out!("msiexec /qn /i \"#{new_resource.source}\" #{expand_options(new_resource.options)}", {:timeout => new_resource.timeout, :returns => new_resource.returns})
|
58
71
|
end
|
59
72
|
|
60
|
-
def remove_package
|
73
|
+
def remove_package
|
61
74
|
# We could use MsiConfigureProduct here, but we'll start off with msiexec
|
62
|
-
|
63
|
-
|
75
|
+
if ::File.exist?(new_resource.source)
|
76
|
+
Chef::Log.debug("#{new_resource} removing MSI package '#{new_resource.source}'")
|
77
|
+
shell_out!("msiexec /qn /x \"#{new_resource.source}\" #{expand_options(new_resource.options)}", {:timeout => new_resource.timeout, :returns => new_resource.returns})
|
78
|
+
else
|
79
|
+
uninstall_version = new_resource.version || installed_version
|
80
|
+
uninstall_entries.select { |entry| [uninstall_version].flatten.include?(entry.display_version) }
|
81
|
+
.map { |version| version.uninstall_string }.uniq.each do |uninstall_string|
|
82
|
+
Chef::Log.debug("#{new_resource} removing MSI package version using '#{uninstall_string}'")
|
83
|
+
uninstall_string += expand_options(new_resource.options)
|
84
|
+
uninstall_string += " /Q" unless uninstall_string =~ / \/Q\b/
|
85
|
+
shell_out!(uninstall_string, {:timeout => new_resource.timeout, :returns => new_resource.returns})
|
86
|
+
end
|
87
|
+
end
|
64
88
|
end
|
65
89
|
end
|
66
90
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
3
|
+
# Author:: Matt Wrock <matt@mattwrock.com>
|
4
|
+
# Copyright:: Copyright (c) 2011, 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 'win32/registry' if (RUBY_PLATFORM =~ /mswin|mingw32|windows/)
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Package
|
25
|
+
class Windows
|
26
|
+
class RegistryUninstallEntry
|
27
|
+
|
28
|
+
def self.find_entries(package_name)
|
29
|
+
Chef::Log.debug("Finding uninstall entries for #{package_name}")
|
30
|
+
entries = []
|
31
|
+
[
|
32
|
+
[::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0100)],
|
33
|
+
[::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0200)],
|
34
|
+
[::Win32::Registry::HKEY_CURRENT_USER]
|
35
|
+
].each do |hkey|
|
36
|
+
desired = hkey.length > 1 ? hkey[1] : ::Win32::Registry::Constants::KEY_READ
|
37
|
+
begin
|
38
|
+
::Win32::Registry.open(hkey[0], UNINSTALL_SUBKEY, desired) do |reg|
|
39
|
+
reg.each_key do |key, _wtime|
|
40
|
+
begin
|
41
|
+
entry = reg.open(key, desired)
|
42
|
+
display_name = read_registry_property(entry, 'DisplayName')
|
43
|
+
if display_name == package_name
|
44
|
+
entries.push(RegistryUninstallEntry.new(hkey, key, entry))
|
45
|
+
end
|
46
|
+
rescue ::Win32::Registry::Error => ex
|
47
|
+
Chef::Log.debug("Registry error opening key '#{key}' on node #{desired}: #{ex}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
rescue ::Win32::Registry::Error => ex
|
52
|
+
Chef::Log.debug("Registry error opening hive '#{hkey[0]}' :: #{desired}: #{ex}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
entries
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.read_registry_property(data, property)
|
59
|
+
data[property]
|
60
|
+
rescue ::Win32::Registry::Error => ex
|
61
|
+
Chef::Log.debug("Failure to read property '#{property}'")
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def initialize(hive, key, registry_data)
|
66
|
+
Chef::Log.debug("Creating uninstall entry for #{hive}::#{key}")
|
67
|
+
@hive = hive
|
68
|
+
@key = key
|
69
|
+
@data = registry_data
|
70
|
+
@display_name = RegistryUninstallEntry.read_registry_property(registry_data, 'DisplayName')
|
71
|
+
@display_version = RegistryUninstallEntry.read_registry_property(registry_data, 'DisplayVersion')
|
72
|
+
@uninstall_string = RegistryUninstallEntry.read_registry_property(registry_data, 'UninstallString')
|
73
|
+
end
|
74
|
+
|
75
|
+
attr_reader :hive
|
76
|
+
attr_reader :key
|
77
|
+
attr_reader :display_name
|
78
|
+
attr_reader :display_version
|
79
|
+
attr_reader :uninstall_string
|
80
|
+
attr_reader :data
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
UNINSTALL_SUBKEY = 'Software\Microsoft\Windows\CurrentVersion\Uninstall'.freeze
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -785,19 +785,29 @@ class Chef
|
|
785
785
|
def python_bin
|
786
786
|
yum_executable = which(yum_binary)
|
787
787
|
if yum_executable && shabang?(yum_executable)
|
788
|
-
extract_interpreter(yum_executable)
|
788
|
+
shabang_or_fallback(extract_interpreter(yum_executable))
|
789
789
|
else
|
790
790
|
Chef::Log.warn("Yum executable not found or doesn't start with #!. Using default python.")
|
791
791
|
"/usr/bin/python"
|
792
792
|
end
|
793
793
|
rescue StandardError => e
|
794
|
-
Chef::Log.warn("An error
|
794
|
+
Chef::Log.warn("An error occurred attempting to determine correct python executable. Using default.")
|
795
795
|
Chef::Log.debug(e)
|
796
796
|
"/usr/bin/python"
|
797
797
|
end
|
798
798
|
|
799
799
|
def extract_interpreter(file)
|
800
|
-
::File.open(file, 'r', &:readline)[2..-1].
|
800
|
+
::File.open(file, 'r', &:readline)[2..-1].strip
|
801
|
+
end
|
802
|
+
|
803
|
+
# dnf based systems have a yum shim that has /bin/bash as the interpreter. Don't use this.
|
804
|
+
def shabang_or_fallback(interpreter)
|
805
|
+
if interpreter == '/bin/bash'
|
806
|
+
Chef::Log.warn("Yum executable interpreter is /bin/bash. Falling back to default python.")
|
807
|
+
"/usr/bin/python"
|
808
|
+
else
|
809
|
+
interpreter
|
810
|
+
end
|
801
811
|
end
|
802
812
|
|
803
813
|
def shabang?(file)
|
@@ -199,6 +199,9 @@ elseif ( $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0 )
|
|
199
199
|
$exitstatus = $LASTEXITCODE
|
200
200
|
}
|
201
201
|
|
202
|
+
# Print STDOUT for the script execution
|
203
|
+
Write-Output $chefscriptresult
|
204
|
+
|
202
205
|
# If this script is launched with -File, the process exit
|
203
206
|
# status of PowerShell.exe will be $exitstatus. If it was
|
204
207
|
# launched with -Command, it will be 0 if $exitstatus was 0,
|
@@ -145,18 +145,51 @@ class Chef
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def load_json_data
|
148
|
-
|
148
|
+
path = sanitized_cache_file_path(sanitized_cache_file_basename)
|
149
|
+
if Chef::FileCache.has_key?(path)
|
150
|
+
Chef::FileCache.load(path)
|
151
|
+
else
|
152
|
+
old_path = sanitized_cache_file_path(sanitized_cache_file_basename_md5)
|
153
|
+
if Chef::FileCache.has_key?(old_path)
|
154
|
+
# We found an old cache control data file. We started using sha256 instead of md5
|
155
|
+
# to name these. Upgrade the file to the new name.
|
156
|
+
Chef::Log.debug("Found old cache control data file at #{old_path}. Moving to #{path}.")
|
157
|
+
Chef::FileCache.load(old_path).tap do |data|
|
158
|
+
Chef::FileCache.store(path, data)
|
159
|
+
Chef::FileCache.delete(old_path)
|
160
|
+
end
|
161
|
+
else
|
162
|
+
raise Chef::Exceptions::FileNotFound
|
163
|
+
end
|
164
|
+
end
|
149
165
|
end
|
150
166
|
|
151
|
-
def
|
167
|
+
def sanitized_cache_file_path(basename)
|
168
|
+
"remote_file/#{basename}"
|
169
|
+
end
|
170
|
+
|
171
|
+
def scrubbed_uri
|
152
172
|
# Scrub and truncate in accordance with the goals of keeping the name
|
153
173
|
# human-readable but within the bounds of local file system
|
154
174
|
# path length limits
|
155
|
-
|
175
|
+
uri.gsub(/\W/, '_')[0..63]
|
176
|
+
end
|
177
|
+
|
178
|
+
def sanitized_cache_file_basename
|
179
|
+
uri_sha2 = Chef::Digester.instance.generate_checksum(StringIO.new(uri))
|
180
|
+
cache_file_basename(uri_sha2[0,32])
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
def sanitized_cache_file_basename_md5
|
185
|
+
# Old way of creating the file basename
|
156
186
|
uri_md5 = Chef::Digester.instance.generate_md5_checksum(StringIO.new(uri))
|
157
|
-
|
187
|
+
cache_file_basename(uri_md5)
|
158
188
|
end
|
159
189
|
|
190
|
+
def cache_file_basename(checksum)
|
191
|
+
"#{scrubbed_uri}-#{checksum}.json"
|
192
|
+
end
|
160
193
|
end
|
161
194
|
end
|
162
195
|
end
|
@@ -105,7 +105,7 @@ class Chef
|
|
105
105
|
# case you'd end up with a tar archive (no gzip) named, e.g., foo.tgz,
|
106
106
|
# which is not what you wanted.
|
107
107
|
if uri.to_s =~ /gz$/
|
108
|
-
Chef::Log.debug("
|
108
|
+
Chef::Log.debug("Turning gzip compression off due to filename ending in gz")
|
109
109
|
opts[:disable_gzip] = true
|
110
110
|
end
|
111
111
|
opts
|
data/lib/chef/provider/script.rb
CHANGED
@@ -44,16 +44,19 @@ class Chef
|
|
44
44
|
supports[:restart] = false if supports[:restart].nil?
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
# the new_resource#enabled and #running variables are not user input, but when we
|
48
|
+
# do (e.g.) action_enable we want to set new_resource.enabled so that the comparison
|
49
|
+
# between desired and current state produces the correct change in reporting.
|
50
|
+
# XXX?: the #nil? check below will likely fail if this is a cloned resource or if
|
51
|
+
# we just run multiple actions.
|
52
|
+
def load_new_resource_state
|
53
|
+
if ( @new_resource.enabled.nil? )
|
54
|
+
@new_resource.enabled(@current_resource.enabled)
|
55
|
+
end
|
56
|
+
if ( @new_resource.running.nil? )
|
57
|
+
@new_resource.running(@current_resource.running)
|
58
|
+
end
|
59
|
+
end
|
57
60
|
|
58
61
|
def shared_resource_requirements
|
59
62
|
end
|
@@ -30,35 +30,39 @@ class Chef
|
|
30
30
|
|
31
31
|
def initialize(new_resource, run_context=nil)
|
32
32
|
super
|
33
|
-
@init_command
|
34
|
-
@status_command = "/bin/svcs
|
33
|
+
@init_command = "/usr/sbin/svcadm"
|
34
|
+
@status_command = "/bin/svcs"
|
35
35
|
@maintenace = false
|
36
36
|
end
|
37
37
|
|
38
38
|
def load_current_resource
|
39
39
|
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
40
40
|
@current_resource.service_name(@new_resource.service_name)
|
41
|
-
|
42
|
-
|
41
|
+
|
42
|
+
[@init_command, @status_command].each do |cmd|
|
43
|
+
unless ::File.executable? cmd then
|
44
|
+
raise Chef::Exceptions::Service, "#{cmd} not executable!"
|
45
|
+
end
|
43
46
|
end
|
44
47
|
@status = service_status.enabled
|
48
|
+
|
45
49
|
@current_resource
|
46
50
|
end
|
47
51
|
|
48
52
|
def enable_service
|
49
|
-
shell_out!(
|
50
|
-
shell_out!(
|
53
|
+
shell_out!(default_init_command, "clear", @new_resource.service_name) if @maintenance
|
54
|
+
shell_out!(default_init_command, "enable", "-s", @new_resource.service_name)
|
51
55
|
end
|
52
56
|
|
53
57
|
def disable_service
|
54
|
-
shell_out!(
|
58
|
+
shell_out!(default_init_command, "disable", "-s", @new_resource.service_name)
|
55
59
|
end
|
56
60
|
|
57
61
|
alias_method :stop_service, :disable_service
|
58
62
|
alias_method :start_service, :enable_service
|
59
63
|
|
60
64
|
def reload_service
|
61
|
-
|
65
|
+
shell_out!(default_init_command, "refresh", @new_resource.service_name)
|
62
66
|
end
|
63
67
|
|
64
68
|
def restart_service
|
@@ -68,16 +72,38 @@ class Chef
|
|
68
72
|
end
|
69
73
|
|
70
74
|
def service_status
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
cmd = shell_out!(@status_command, "-l", @current_resource.service_name, :returns => [0, 1])
|
76
|
+
# Example output
|
77
|
+
# $ svcs -l rsyslog
|
78
|
+
# fmri svc:/application/rsyslog:default
|
79
|
+
# name rsyslog logging utility
|
80
|
+
# enabled true
|
81
|
+
# state online
|
82
|
+
# next_state none
|
83
|
+
# state_time April 2, 2015 04:25:19 PM EDT
|
84
|
+
# logfile /var/svc/log/application-rsyslog:default.log
|
85
|
+
# restarter svc:/system/svc/restarter:default
|
86
|
+
# contract_id 1115271
|
87
|
+
# dependency require_all/error svc:/milestone/multi-user:default (online)
|
88
|
+
# $
|
89
|
+
|
90
|
+
# load output into hash
|
91
|
+
status = {}
|
92
|
+
cmd.stdout.each_line do |line|
|
93
|
+
key, value = line.strip.split(/\s+/, 2)
|
94
|
+
status[key] = value
|
95
|
+
end
|
96
|
+
|
97
|
+
# check service state
|
98
|
+
@maintenance = false
|
99
|
+
case status['state']
|
100
|
+
when 'online'
|
101
|
+
@current_resource.enabled(true)
|
102
|
+
@current_resource.running(true)
|
103
|
+
when 'maintenance'
|
104
|
+
@maintenance = true
|
80
105
|
end
|
106
|
+
|
81
107
|
unless @current_resource.enabled
|
82
108
|
@current_resource.enabled(false)
|
83
109
|
@current_resource.running(false)
|