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,38 @@
|
|
1
|
+
# Author:: Tyler Ball (<tball@chef.io>)
|
2
|
+
# Copyright:: Copyright (c) 2015 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 'proxifier'
|
19
|
+
|
20
|
+
class Chef
|
21
|
+
module Mixin
|
22
|
+
module ProxifiedSocket
|
23
|
+
|
24
|
+
# This looks at the environment variables and leverages Proxifier to
|
25
|
+
# make the TCPSocket respect ENV['https_proxy'] or ENV['http_proxy'] if
|
26
|
+
# they are present
|
27
|
+
def proxified_socket(host, port)
|
28
|
+
proxy = ENV['https_proxy'] || ENV['http_proxy'] || false
|
29
|
+
if proxy
|
30
|
+
Proxifier.Proxy(proxy, no_proxy: ENV['no_proxy']).open(host, port)
|
31
|
+
else
|
32
|
+
TCPSocket.new(host, port)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008-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
|
+
class Chef
|
20
|
+
module Mixin
|
21
|
+
module SubclassDirective
|
22
|
+
def subclass_directive(sym)
|
23
|
+
define_singleton_method sym do
|
24
|
+
instance_variable_set(:"@#{sym}", true)
|
25
|
+
end
|
26
|
+
|
27
|
+
define_singleton_method :"#{sym}?" do
|
28
|
+
!!instance_variable_get(:"@#{sym}")
|
29
|
+
end
|
30
|
+
|
31
|
+
define_method :"#{sym}?" do
|
32
|
+
self.class.send(:"#{sym}?")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/chef/node.rb
CHANGED
@@ -376,12 +376,12 @@ class Chef
|
|
376
376
|
normal[:tags]
|
377
377
|
end
|
378
378
|
|
379
|
-
def tag(*
|
380
|
-
|
381
|
-
|
379
|
+
def tag(*args)
|
380
|
+
args.each do |tag|
|
381
|
+
tags.push(tag.to_s) unless tags.include? tag.to_s
|
382
382
|
end
|
383
383
|
|
384
|
-
|
384
|
+
tags
|
385
385
|
end
|
386
386
|
|
387
387
|
# Extracts the run list from +attrs+ and applies it. Returns the remaining attributes
|
@@ -609,7 +609,7 @@ class Chef
|
|
609
609
|
# so then POST to create.
|
610
610
|
begin
|
611
611
|
if Chef::Config[:why_run]
|
612
|
-
Chef::Log.warn("In
|
612
|
+
Chef::Log.warn("In why-run mode, so NOT performing node save.")
|
613
613
|
else
|
614
614
|
chef_server_rest.put_rest("nodes/#{name}", data_for_save)
|
615
615
|
end
|
@@ -647,6 +647,14 @@ class Chef
|
|
647
647
|
"node[#{name}]"
|
648
648
|
end
|
649
649
|
|
650
|
+
def ==(other)
|
651
|
+
if other.kind_of?(self.class)
|
652
|
+
self.name == other.name
|
653
|
+
else
|
654
|
+
false
|
655
|
+
end
|
656
|
+
end
|
657
|
+
|
650
658
|
def <=>(other_node)
|
651
659
|
self.name <=> other_node.name
|
652
660
|
end
|
@@ -85,10 +85,12 @@ class Chef
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def supports_dsc_invoke_resource?(node)
|
88
|
-
require 'rubygems'
|
89
88
|
supports_dsc?(node) &&
|
90
|
-
|
91
|
-
|
89
|
+
supported_powershell_version?(node, "5.0.10018.0")
|
90
|
+
end
|
91
|
+
|
92
|
+
def supports_refresh_mode_enabled?(node)
|
93
|
+
supported_powershell_version?(node, "5.0.10586.0")
|
92
94
|
end
|
93
95
|
|
94
96
|
def dsc_refresh_mode_disabled?(node)
|
@@ -97,6 +99,15 @@ class Chef
|
|
97
99
|
metadata = cmdlet.run!.return_value
|
98
100
|
metadata['RefreshMode'] == 'Disabled'
|
99
101
|
end
|
102
|
+
|
103
|
+
|
104
|
+
def supported_powershell_version?(node, version_string)
|
105
|
+
return false unless node[:languages] && node[:languages][:powershell]
|
106
|
+
require 'rubygems'
|
107
|
+
Gem::Version.new(node[:languages][:powershell][:version]) >=
|
108
|
+
Gem::Version.new(version_string)
|
109
|
+
end
|
110
|
+
|
100
111
|
end
|
101
112
|
end
|
102
113
|
end
|
@@ -16,19 +16,12 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
# XXX: mixing shellout into a mixin into classes has to be code smell
|
20
|
-
require 'chef/mixin/shell_out'
|
21
|
-
require 'chef/mixin/which'
|
22
19
|
require 'chef/chef_class'
|
23
20
|
|
24
21
|
class Chef
|
25
22
|
class Platform
|
26
23
|
class ServiceHelpers
|
27
24
|
class << self
|
28
|
-
|
29
|
-
include Chef::Mixin::ShellOut
|
30
|
-
include Chef::Mixin::Which
|
31
|
-
|
32
25
|
# This helper is mostly used to sort out the mess of different
|
33
26
|
# linux mechanisms that can be used to start services. It does
|
34
27
|
# not necessarily need to linux-specific, but currently all our
|
@@ -53,23 +46,22 @@ class Chef
|
|
53
46
|
providers << :invokercd
|
54
47
|
end
|
55
48
|
|
49
|
+
if ::File.exist?(Chef.path_to("/sbin/initctl"))
|
50
|
+
providers << :upstart
|
51
|
+
end
|
52
|
+
|
56
53
|
if ::File.exist?(Chef.path_to("/sbin/insserv"))
|
57
54
|
providers << :insserv
|
58
55
|
end
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
providers << :upstart
|
57
|
+
if systemd_is_init?
|
58
|
+
providers << :systemd
|
63
59
|
end
|
64
60
|
|
65
61
|
if ::File.exist?(Chef.path_to("/sbin/chkconfig"))
|
66
62
|
providers << :redhat
|
67
63
|
end
|
68
64
|
|
69
|
-
if systemd_sanity_check?
|
70
|
-
providers << :systemd
|
71
|
-
end
|
72
|
-
|
73
65
|
providers
|
74
66
|
end
|
75
67
|
|
@@ -96,7 +88,7 @@ class Chef
|
|
96
88
|
configs << :usr_local_etc_rcd
|
97
89
|
end
|
98
90
|
|
99
|
-
if
|
91
|
+
if has_systemd_service_unit?(service_name) || has_systemd_unit?(service_name)
|
100
92
|
configs << :systemd
|
101
93
|
end
|
102
94
|
|
@@ -105,34 +97,24 @@ class Chef
|
|
105
97
|
|
106
98
|
private
|
107
99
|
|
108
|
-
def
|
109
|
-
|
100
|
+
def systemd_is_init?
|
101
|
+
::File.exist?(Chef.path_to("/proc/1/comm")) &&
|
102
|
+
::File.open(Chef.path_to("/proc/1/comm")).gets.chomp == "systemd"
|
110
103
|
end
|
111
104
|
|
112
|
-
def
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
output = shell_out!(command).stdout
|
118
|
-
# first line finds e.g. "sshd.service"
|
119
|
-
services = []
|
120
|
-
output.each_line do |line|
|
121
|
-
fields = line.split
|
122
|
-
services << fields[0] if fields[1] == "loaded" || fields[1] == "not-found"
|
105
|
+
def has_systemd_service_unit?(svc_name)
|
106
|
+
%w( /etc /usr/lib /lib /run ).any? do |load_path|
|
107
|
+
::File.exist?(
|
108
|
+
Chef.path_to("#{load_path}/systemd/system/#{svc_name.gsub(/@.*$/, '@')}.service")
|
109
|
+
)
|
123
110
|
end
|
124
|
-
# this splits off the suffix after the last dot to return "sshd"
|
125
|
-
services += services.select {|s| s.match(/\.service$/) }.map { |s| s.sub(/(.*)\.service$/, '\1') }
|
126
|
-
rescue Mixlib::ShellOut::ShellCommandFailed
|
127
|
-
[]
|
128
111
|
end
|
129
112
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
false
|
113
|
+
def has_systemd_unit?(svc_name)
|
114
|
+
# TODO: stop supporting non-service units with service resource
|
115
|
+
%w( /etc /usr/lib /lib /run ).any? do |load_path|
|
116
|
+
::File.exist?(Chef.path_to("#{load_path}/systemd/system/#{svc_name}"))
|
117
|
+
end
|
136
118
|
end
|
137
119
|
end
|
138
120
|
end
|
@@ -74,11 +74,13 @@ class Chef
|
|
74
74
|
cl = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
|
75
75
|
cl.load_cookbooks
|
76
76
|
cookbook_collection = Chef::CookbookCollection.new(cl)
|
77
|
+
cookbook_collection.validate!
|
77
78
|
run_context = Chef::RunContext.new(node, cookbook_collection, @events)
|
78
79
|
else
|
79
80
|
Chef::Cookbook::FileVendor.fetch_from_remote(api_service)
|
80
81
|
cookbook_hash = sync_cookbooks
|
81
82
|
cookbook_collection = Chef::CookbookCollection.new(cookbook_hash)
|
83
|
+
cookbook_collection.validate!
|
82
84
|
run_context = Chef::RunContext.new(node, cookbook_collection, @events)
|
83
85
|
end
|
84
86
|
|
@@ -154,6 +156,7 @@ class Chef
|
|
154
156
|
Chef::Log.info("Run List expands to [#{@expanded_run_list_with_versions.join(', ')}]")
|
155
157
|
|
156
158
|
events.node_load_completed(node, @expanded_run_list_with_versions, Chef::Config)
|
159
|
+
events.run_list_expanded(@run_list_expansion)
|
157
160
|
|
158
161
|
node
|
159
162
|
end
|
@@ -153,6 +153,7 @@ class Chef
|
|
153
153
|
Chef::Cookbook::FileVendor.fetch_from_remote(http_api)
|
154
154
|
sync_cookbooks
|
155
155
|
cookbook_collection = Chef::CookbookCollection.new(cookbooks_to_sync)
|
156
|
+
cookbook_collection.validate!
|
156
157
|
run_context = Chef::RunContext.new(node, cookbook_collection, events)
|
157
158
|
|
158
159
|
setup_chef_class(run_context)
|
data/lib/chef/property.rb
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
|
19
19
|
require 'chef/exceptions'
|
20
20
|
require 'chef/delayed_evaluator'
|
21
|
+
require 'chef/chef_class'
|
22
|
+
require 'chef/log'
|
21
23
|
|
22
24
|
class Chef
|
23
25
|
#
|
@@ -116,6 +118,10 @@ class Chef
|
|
116
118
|
options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name]
|
117
119
|
end
|
118
120
|
|
121
|
+
def to_s
|
122
|
+
name
|
123
|
+
end
|
124
|
+
|
119
125
|
#
|
120
126
|
# The name of this property.
|
121
127
|
#
|
@@ -247,16 +253,19 @@ class Chef
|
|
247
253
|
return get(resource)
|
248
254
|
end
|
249
255
|
|
250
|
-
# myprop nil is sometimes a get (backcompat)
|
251
256
|
if value.nil? && !explicitly_accepts_nil?(resource)
|
252
|
-
#
|
253
|
-
#
|
254
|
-
|
255
|
-
|
257
|
+
# In Chef 12, value(nil) does a *get* instead of a set, so we
|
258
|
+
# warn if the value would have been changed. In Chef 13, it will be
|
259
|
+
# equivalent to value = nil.
|
260
|
+
result = get(resource)
|
261
|
+
if !result.nil?
|
262
|
+
Chef.log_deprecation("#{name} nil currently does not overwrite the value of #{name}. This will change in Chef 13, and the value will be set to nil instead. Please change your code to explicitly accept nil using \"property :#{name}, [MyType, nil]\", or stop setting this value to nil.")
|
263
|
+
end
|
264
|
+
result
|
265
|
+
else
|
266
|
+
# Anything else, such as myprop(value) is a set
|
267
|
+
set(resource, value)
|
256
268
|
end
|
257
|
-
|
258
|
-
# Anything else (myprop value) is a set
|
259
|
-
set(resource, value)
|
260
269
|
end
|
261
270
|
|
262
271
|
#
|
@@ -292,6 +301,29 @@ class Chef
|
|
292
301
|
value
|
293
302
|
|
294
303
|
else
|
304
|
+
# If the user does something like this:
|
305
|
+
#
|
306
|
+
# ```
|
307
|
+
# class MyResource < Chef::Resource
|
308
|
+
# property :content
|
309
|
+
# action :create do
|
310
|
+
# file '/x.txt' do
|
311
|
+
# content content
|
312
|
+
# end
|
313
|
+
# end
|
314
|
+
# end
|
315
|
+
# ```
|
316
|
+
#
|
317
|
+
# It won't do what they expect. This checks whether you try to *read*
|
318
|
+
# `content` while we are compiling the resource.
|
319
|
+
if resource.respond_to?(:resource_initializing) &&
|
320
|
+
resource.resource_initializing &&
|
321
|
+
resource.respond_to?(:enclosing_provider) &&
|
322
|
+
resource.enclosing_provider &&
|
323
|
+
resource.enclosing_provider.respond_to?(name)
|
324
|
+
Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}")
|
325
|
+
end
|
326
|
+
|
295
327
|
if has_default?
|
296
328
|
value = default
|
297
329
|
if value.is_a?(DelayedEvaluator)
|
@@ -431,7 +463,7 @@ class Chef
|
|
431
463
|
modified_options.has_key?(:default)
|
432
464
|
options = options.reject { |k,v| k == :name_attribute || k == :name_property || k == :default }
|
433
465
|
end
|
434
|
-
|
466
|
+
self.class.new(options.merge(modified_options))
|
435
467
|
end
|
436
468
|
|
437
469
|
#
|
@@ -448,18 +480,22 @@ class Chef
|
|
448
480
|
# stack trace if you use `define_method`.
|
449
481
|
declared_in.class_eval <<-EOM, __FILE__, __LINE__+1
|
450
482
|
def #{name}(value=NOT_PASSED)
|
483
|
+
raise "Property #{name} of \#{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block_given?
|
451
484
|
self.class.properties[#{name.inspect}].call(self, value)
|
452
485
|
end
|
453
486
|
def #{name}=(value)
|
487
|
+
raise "Property #{name} of \#{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block_given?
|
454
488
|
self.class.properties[#{name.inspect}].set(self, value)
|
455
489
|
end
|
456
490
|
EOM
|
457
491
|
rescue SyntaxError
|
458
492
|
# If the name is not a valid ruby name, we use define_method.
|
459
|
-
declared_in.define_method(name) do |value=NOT_PASSED|
|
493
|
+
declared_in.define_method(name) do |value=NOT_PASSED, &block|
|
494
|
+
raise "Property #{name} of #{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block
|
460
495
|
self.class.properties[name].call(self, value)
|
461
496
|
end
|
462
|
-
declared_in.define_method("#{name}=") do |value|
|
497
|
+
declared_in.define_method("#{name}=") do |value, &block|
|
498
|
+
raise "Property #{name} of #{self} cannot be passed a block! If you meant to create a resource named #{name} instead, you'll need to first rename the property." if block
|
463
499
|
self.class.properties[name].set(self, value)
|
464
500
|
end
|
465
501
|
end
|
@@ -479,6 +515,8 @@ class Chef
|
|
479
515
|
# A type accepts nil explicitly if "is" allows nil, it validates as nil, *and* is not simply
|
480
516
|
# an empty type.
|
481
517
|
#
|
518
|
+
# A type is presumed to accept nil if it does coercion (which must handle nil).
|
519
|
+
#
|
482
520
|
# These examples accept nil explicitly:
|
483
521
|
# ```ruby
|
484
522
|
# property :a, [ String, nil ]
|
@@ -510,7 +548,8 @@ class Chef
|
|
510
548
|
#
|
511
549
|
# @api private
|
512
550
|
def explicitly_accepts_nil?(resource)
|
513
|
-
options.has_key?(:
|
551
|
+
options.has_key?(:coerce) ||
|
552
|
+
(options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false))
|
514
553
|
end
|
515
554
|
|
516
555
|
def get_value(resource)
|
data/lib/chef/provider.rb
CHANGED
@@ -204,26 +204,39 @@ class Chef
|
|
204
204
|
specified_properties = properties.select { |property| new_resource.property_is_set?(property) }
|
205
205
|
modified = specified_properties.select { |p| new_resource.send(p) != current_resource.send(p) }
|
206
206
|
if modified.empty?
|
207
|
-
|
207
|
+
properties_str = if sensitive
|
208
|
+
specified_properties.join(", ")
|
209
|
+
else
|
210
|
+
specified_properties.map { |p| "#{p}=#{new_resource.send(p).inspect}" }.join(", ")
|
211
|
+
end
|
212
|
+
Chef::Log.debug("Skipping update of #{new_resource.to_s}: has not changed any of the specified properties #{properties_str}.")
|
208
213
|
return false
|
209
214
|
end
|
210
215
|
|
211
216
|
# Print the pretty green text and run the block
|
212
217
|
property_size = modified.map { |p| p.size }.max
|
213
|
-
modified
|
218
|
+
modified.map! do |p|
|
219
|
+
properties_str = if sensitive
|
220
|
+
'(suppressed sensitive property)'
|
221
|
+
else
|
222
|
+
"#{new_resource.send(p).inspect} (was #{current_resource.send(p).inspect})"
|
223
|
+
end
|
224
|
+
" set #{p.to_s.ljust(property_size)} to #{properties_str}"
|
225
|
+
end
|
214
226
|
converge_by([ "update #{current_resource.identity}" ] + modified, &converge_block)
|
215
227
|
|
216
228
|
else
|
217
229
|
# The resource doesn't exist. Mark that we are *creating* this, and
|
218
230
|
# write down any properties we are setting.
|
219
231
|
property_size = properties.map { |p| p.size }.max
|
220
|
-
created =
|
221
|
-
|
222
|
-
if
|
223
|
-
|
232
|
+
created = properties.map do |property|
|
233
|
+
default = ' (default value)' unless new_resource.property_is_set?(property)
|
234
|
+
properties_str = if sensitive
|
235
|
+
'(suppressed sensitive property)'
|
224
236
|
else
|
225
|
-
|
237
|
+
new_resource.send(property).inspect
|
226
238
|
end
|
239
|
+
" set #{property.to_s.ljust(property_size)} to #{properties_str}#{default}"
|
227
240
|
end
|
228
241
|
|
229
242
|
converge_by([ "create #{new_resource.identity}" ] + created, &converge_block)
|
@@ -338,10 +351,20 @@ class Chef
|
|
338
351
|
# @api private
|
339
352
|
module InlineResources
|
340
353
|
|
341
|
-
#
|
342
|
-
#
|
343
|
-
|
344
|
-
|
354
|
+
# Create a child run_context, compile the block, and converge it.
|
355
|
+
#
|
356
|
+
# @api private
|
357
|
+
def compile_and_converge_action(&block)
|
358
|
+
old_run_context = run_context
|
359
|
+
@run_context = run_context.create_child
|
360
|
+
return_value = instance_eval(&block)
|
361
|
+
Chef::Runner.new(run_context).converge
|
362
|
+
return_value
|
363
|
+
ensure
|
364
|
+
if run_context.resource_collection.any? { |r| r.updated? }
|
365
|
+
new_resource.updated_by_last_action(true)
|
366
|
+
end
|
367
|
+
@run_context = old_run_context
|
345
368
|
end
|
346
369
|
|
347
370
|
# Class methods for InlineResources. Overrides the `action` DSL method
|
@@ -353,36 +376,18 @@ class Chef
|
|
353
376
|
# compile the resources, converging them, and then checking if any
|
354
377
|
# were updated (and updating new-resource if so)
|
355
378
|
def action(name, &block)
|
356
|
-
# We
|
357
|
-
#
|
358
|
-
#
|
379
|
+
# We need the block directly in a method so that `super` works
|
380
|
+
define_method("compile_action_#{name}", &block)
|
381
|
+
# We try hard to use `def` because define_method doesn't show the method name in the stack.
|
359
382
|
begin
|
360
|
-
class_eval <<-EOM
|
383
|
+
class_eval <<-EOM
|
361
384
|
def action_#{name}
|
362
|
-
|
363
|
-
Chef::Runner.new(run_context).converge
|
364
|
-
return_value
|
365
|
-
ensure
|
366
|
-
if run_context.resource_collection.any? {|r| r.updated? }
|
367
|
-
new_resource.updated_by_last_action(true)
|
368
|
-
end
|
385
|
+
compile_and_converge_action { compile_action_#{name} }
|
369
386
|
end
|
370
387
|
EOM
|
371
388
|
rescue SyntaxError
|
372
|
-
define_method("action_#{name}")
|
373
|
-
begin
|
374
|
-
return_value = send("compile_action_#{name}")
|
375
|
-
Chef::Runner.new(run_context).converge
|
376
|
-
return_value
|
377
|
-
ensure
|
378
|
-
if run_context.resource_collection.any? {|r| r.updated? }
|
379
|
-
new_resource.updated_by_last_action(true)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
end
|
389
|
+
define_method("action_#{name}") { send("compile_action_#{name}") }
|
383
390
|
end
|
384
|
-
# We put the action in its own method so that super() works.
|
385
|
-
define_method("compile_action_#{name}", &block)
|
386
391
|
end
|
387
392
|
end
|
388
393
|
|