chef 12.4.0-universal-mingw32 → 12.4.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/api_client.rb +31 -129
  3. data/lib/chef/api_client_v1.rb +325 -0
  4. data/lib/chef/chef_class.rb +15 -7
  5. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +2 -2
  6. data/lib/chef/dsl/resources.rb +6 -4
  7. data/lib/chef/exceptions.rb +2 -2
  8. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +2 -1
  9. data/lib/chef/knife/bootstrap/templates/chef-full.erb +4 -4
  10. data/lib/chef/knife/client_bulk_delete.rb +2 -2
  11. data/lib/chef/knife/client_create.rb +4 -4
  12. data/lib/chef/knife/client_delete.rb +3 -3
  13. data/lib/chef/knife/client_edit.rb +10 -2
  14. data/lib/chef/knife/client_list.rb +2 -2
  15. data/lib/chef/knife/client_reregister.rb +2 -2
  16. data/lib/chef/knife/client_show.rb +2 -2
  17. data/lib/chef/knife/osc_user_create.rb +3 -3
  18. data/lib/chef/knife/osc_user_delete.rb +2 -2
  19. data/lib/chef/knife/osc_user_edit.rb +3 -3
  20. data/lib/chef/knife/osc_user_list.rb +2 -2
  21. data/lib/chef/knife/osc_user_reregister.rb +2 -2
  22. data/lib/chef/knife/osc_user_show.rb +2 -2
  23. data/lib/chef/knife/user_create.rb +3 -3
  24. data/lib/chef/knife/user_delete.rb +4 -4
  25. data/lib/chef/knife/user_edit.rb +3 -3
  26. data/lib/chef/knife/user_list.rb +2 -2
  27. data/lib/chef/knife/user_reregister.rb +2 -2
  28. data/lib/chef/knife/user_show.rb +2 -2
  29. data/lib/chef/node_map.rb +14 -18
  30. data/lib/chef/platform/handler_map.rb +45 -0
  31. data/lib/chef/platform/priority_map.rb +19 -32
  32. data/lib/chef/platform/provider_handler_map.rb +29 -0
  33. data/lib/chef/platform/provider_mapping.rb +3 -2
  34. data/lib/chef/platform/resource_handler_map.rb +29 -0
  35. data/lib/chef/platform/resource_priority_map.rb +0 -6
  36. data/lib/chef/provider.rb +1 -1
  37. data/lib/chef/provider/dsc_resource.rb +2 -2
  38. data/lib/chef/provider/dsc_script.rb +1 -1
  39. data/lib/chef/provider/mount/aix.rb +1 -1
  40. data/lib/chef/provider/package.rb +0 -31
  41. data/lib/chef/provider/package/aix.rb +1 -0
  42. data/lib/chef/provider/package/apt.rb +1 -0
  43. data/lib/chef/provider/package/homebrew.rb +1 -0
  44. data/lib/chef/provider/package/ips.rb +1 -0
  45. data/lib/chef/provider/package/macports.rb +1 -0
  46. data/lib/chef/provider/package/openbsd.rb +1 -0
  47. data/lib/chef/provider/package/pacman.rb +1 -0
  48. data/lib/chef/provider/package/paludis.rb +1 -0
  49. data/lib/chef/provider/package/portage.rb +2 -0
  50. data/lib/chef/provider/package/smartos.rb +1 -0
  51. data/lib/chef/provider/package/solaris.rb +2 -0
  52. data/lib/chef/provider/package/yum.rb +1 -0
  53. data/lib/chef/provider/package/zypper.rb +1 -0
  54. data/lib/chef/provider/service.rb +4 -22
  55. data/lib/chef/provider/service/debian.rb +2 -0
  56. data/lib/chef/provider/service/insserv.rb +2 -0
  57. data/lib/chef/provider/service/invokercd.rb +2 -0
  58. data/lib/chef/provider/service/openbsd.rb +1 -1
  59. data/lib/chef/provider/service/redhat.rb +2 -0
  60. data/lib/chef/provider/service/upstart.rb +3 -0
  61. data/lib/chef/provider_resolver.rb +59 -53
  62. data/lib/chef/resource.rb +22 -73
  63. data/lib/chef/resource/dsc_script.rb +1 -1
  64. data/lib/chef/resource/ips_package.rb +1 -0
  65. data/lib/chef/resource/mount.rb +8 -0
  66. data/lib/chef/resource/openbsd_package.rb +0 -11
  67. data/lib/chef/resource/solaris_package.rb +1 -4
  68. data/lib/chef/resource_resolver.rb +54 -26
  69. data/lib/chef/run_list/versioned_recipe_list.rb +6 -5
  70. data/lib/chef/user.rb +52 -188
  71. data/lib/chef/user_v1.rb +335 -0
  72. data/lib/chef/version.rb +1 -1
  73. data/spec/data/trusted_certs/opscode.pem +53 -56
  74. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +1 -1
  75. data/spec/functional/resource/package_spec.rb +0 -2
  76. data/spec/integration/recipes/recipe_dsl_spec.rb +661 -126
  77. data/spec/spec_helper.rb +19 -13
  78. data/spec/support/shared/unit/api_versioning.rb +2 -2
  79. data/spec/unit/api_client_spec.rb +22 -201
  80. data/spec/unit/api_client_v1_spec.rb +457 -0
  81. data/spec/unit/knife/client_bulk_delete_spec.rb +4 -4
  82. data/spec/unit/knife/client_create_spec.rb +1 -1
  83. data/spec/unit/knife/client_delete_spec.rb +3 -3
  84. data/spec/unit/knife/client_edit_spec.rb +14 -1
  85. data/spec/unit/knife/client_list_spec.rb +1 -1
  86. data/spec/unit/knife/client_reregister_spec.rb +2 -2
  87. data/spec/unit/knife/client_show_spec.rb +2 -2
  88. data/spec/unit/knife/osc_user_create_spec.rb +5 -5
  89. data/spec/unit/knife/osc_user_delete_spec.rb +1 -1
  90. data/spec/unit/knife/osc_user_edit_spec.rb +1 -1
  91. data/spec/unit/knife/osc_user_list_spec.rb +1 -1
  92. data/spec/unit/knife/osc_user_reregister_spec.rb +1 -1
  93. data/spec/unit/knife/osc_user_show_spec.rb +1 -1
  94. data/spec/unit/knife/user_create_spec.rb +1 -1
  95. data/spec/unit/knife/user_delete_spec.rb +2 -2
  96. data/spec/unit/knife/user_edit_spec.rb +2 -2
  97. data/spec/unit/knife/user_list_spec.rb +1 -1
  98. data/spec/unit/knife/user_reregister_spec.rb +1 -1
  99. data/spec/unit/knife/user_show_spec.rb +2 -2
  100. data/spec/unit/lwrp_spec.rb +146 -134
  101. data/spec/unit/node_map_spec.rb +12 -0
  102. data/spec/unit/platform_spec.rb +1 -1
  103. data/spec/unit/provider/deploy_spec.rb +1 -1
  104. data/spec/unit/provider/dsc_resource_spec.rb +3 -3
  105. data/spec/unit/provider/dsc_script_spec.rb +2 -2
  106. data/spec/unit/provider_resolver_spec.rb +170 -135
  107. data/spec/unit/recipe_spec.rb +3 -3
  108. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  109. data/spec/unit/resource/cron_spec.rb +1 -1
  110. data/spec/unit/resource/directory_spec.rb +1 -1
  111. data/spec/unit/resource/dsc_resource_spec.rb +1 -1
  112. data/spec/unit/resource/dsc_script_spec.rb +2 -2
  113. data/spec/unit/resource/env_spec.rb +1 -1
  114. data/spec/unit/resource/erl_call_spec.rb +1 -1
  115. data/spec/unit/resource/file_spec.rb +1 -1
  116. data/spec/unit/resource/group_spec.rb +1 -1
  117. data/spec/unit/resource/link_spec.rb +1 -1
  118. data/spec/unit/resource/mdadm_spec.rb +1 -1
  119. data/spec/unit/resource/mount_spec.rb +1 -1
  120. data/spec/unit/resource/ohai_spec.rb +1 -1
  121. data/spec/unit/resource/registry_key_spec.rb +1 -1
  122. data/spec/unit/resource/route_spec.rb +1 -1
  123. data/spec/unit/resource/ruby_block_spec.rb +3 -3
  124. data/spec/unit/resource/user_spec.rb +1 -1
  125. data/spec/unit/resource/windows_service_spec.rb +1 -1
  126. data/spec/unit/resource_resolver_spec.rb +8 -4
  127. data/spec/unit/resource_spec.rb +89 -3
  128. data/spec/unit/run_list/versioned_recipe_list_spec.rb +115 -48
  129. data/spec/unit/user_spec.rb +97 -405
  130. data/spec/unit/user_v1_spec.rb +584 -0
  131. metadata +11 -6
  132. data/lib/chef/osc_user.rb +0 -194
  133. data/spec/unit/osc_user_spec.rb +0 -276
@@ -26,6 +26,7 @@ class Chef
26
26
  class Package
27
27
  class Aix < Chef::Provider::Package
28
28
 
29
+ provides :package, os: "aix"
29
30
  provides :bff_package, os: "aix"
30
31
 
31
32
  include Chef::Mixin::GetSourceFromPackage
@@ -25,6 +25,7 @@ class Chef
25
25
  class Package
26
26
  class Apt < Chef::Provider::Package
27
27
 
28
+ provides :package, platform_family: "debian"
28
29
  provides :apt_package, os: "linux"
29
30
 
30
31
  # return [Hash] mapping of package name to Boolean value
@@ -26,6 +26,7 @@ class Chef
26
26
  class Package
27
27
  class Homebrew < Chef::Provider::Package
28
28
 
29
+ provides :package, os: "darwin", override: true
29
30
  provides :homebrew_package
30
31
 
31
32
  include Chef::Mixin::HomebrewUser
@@ -27,6 +27,7 @@ class Chef
27
27
  class Package
28
28
  class Ips < Chef::Provider::Package
29
29
 
30
+ provides :package, platform: %w(openindiana opensolaris omnios solaris2)
30
31
  provides :ips_package, os: "solaris2"
31
32
 
32
33
  attr_accessor :virtual
@@ -3,6 +3,7 @@ class Chef
3
3
  class Package
4
4
  class Macports < Chef::Provider::Package
5
5
 
6
+ provides :package, os: "darwin"
6
7
  provides :macports_package
7
8
 
8
9
  def load_current_resource
@@ -31,6 +31,7 @@ class Chef
31
31
  class Openbsd < Chef::Provider::Package
32
32
 
33
33
  provides :package, os: "openbsd"
34
+ provides :openbsd_package
34
35
 
35
36
  include Chef::Mixin::ShellOut
36
37
  include Chef::Mixin::GetSourceFromPackage
@@ -25,6 +25,7 @@ class Chef
25
25
  class Package
26
26
  class Pacman < Chef::Provider::Package
27
27
 
28
+ provides :package, platform: "arch"
28
29
  provides :pacman_package, os: "linux"
29
30
 
30
31
  def load_current_resource
@@ -24,6 +24,7 @@ class Chef
24
24
  class Package
25
25
  class Paludis < Chef::Provider::Package
26
26
 
27
+ provides :package, platform: "exherbo"
27
28
  provides :paludis_package, os: "linux"
28
29
 
29
30
  def load_current_resource
@@ -25,6 +25,8 @@ class Chef
25
25
  class Provider
26
26
  class Package
27
27
  class Portage < Chef::Provider::Package
28
+
29
+ provides :package, platform: "gentoo"
28
30
  provides :portage_package
29
31
 
30
32
  PACKAGE_NAME_PATTERN = %r{(?:([^/]+)/)?([^/]+)}
@@ -29,6 +29,7 @@ class Chef
29
29
  class SmartOS < Chef::Provider::Package
30
30
  attr_accessor :is_virtual_package
31
31
 
32
+ provides :package, platform: "smartos"
32
33
  provides :smartos_package, os: "solaris2", platform_family: "smartos"
33
34
 
34
35
  def load_current_resource
@@ -27,6 +27,8 @@ class Chef
27
27
 
28
28
  include Chef::Mixin::GetSourceFromPackage
29
29
 
30
+ provides :package, platform: "nexentacore"
31
+ provides :package, platform: "solaris2", platform_version: '< 5.11'
30
32
  provides :solaris_package, os: "solaris2"
31
33
 
32
34
  # def initialize(*args)
@@ -28,6 +28,7 @@ class Chef
28
28
  class Package
29
29
  class Yum < Chef::Provider::Package
30
30
 
31
+ provides :package, platform_family: %w(rhel fedora)
31
32
  provides :yum_package, os: "linux"
32
33
 
33
34
  class RPMUtils
@@ -29,6 +29,7 @@ class Chef
29
29
  class Package
30
30
  class Zypper < Chef::Provider::Package
31
31
 
32
+ provides :package, platform_family: "suse"
32
33
  provides :zypper_package, os: "linux"
33
34
 
34
35
  def load_current_resource
@@ -188,29 +188,11 @@ class Chef
188
188
  require 'chef/provider/service/upstart'
189
189
  require 'chef/provider/service/debian'
190
190
  require 'chef/provider/service/invokercd'
191
- require 'chef/provider/service/freebsd'
192
- require 'chef/provider/service/openbsd'
193
- require 'chef/provider/service/solaris'
194
- require 'chef/provider/service/macosx'
195
-
196
- def self.os(os, *providers)
197
- Chef.set_provider_priority_array(:service, providers, os: os)
198
- end
199
- def self.platform_family(platform_family, *providers)
200
- Chef.set_provider_priority_array(:service, providers, platform_family: platform_family)
201
- end
202
-
203
- os %w(freebsd netbsd), Freebsd
204
- os %w(openbsd), Openbsd
205
- os %w(solaris2), Solaris
206
- os %w(darwin), Macosx
207
- os %w(linux), Systemd, Insserv, Redhat
208
-
209
- platform_family %w(arch), Systemd, Arch
210
- platform_family %w(gentoo), Systemd, Gentoo
211
- platform_family %w(debian), Systemd, Upstart, Insserv, Debian, Invokercd
212
- platform_family %w(rhel fedora suse), Systemd, Insserv, Redhat
213
191
 
192
+ Chef.set_provider_priority_array :service, [ Systemd, Arch ], platform_family: 'arch'
193
+ Chef.set_provider_priority_array :service, [ Systemd, Gentoo ], platform_family: 'gentoo'
194
+ Chef.set_provider_priority_array :service, [ Systemd, Upstart, Insserv, Debian, Invokercd ], platform_family: 'debian'
195
+ Chef.set_provider_priority_array :service, [ Systemd, Insserv, Redhat ], platform_family: %w(rhel fedora suse)
214
196
  end
215
197
  end
216
198
  end
@@ -22,6 +22,8 @@ class Chef
22
22
  class Provider
23
23
  class Service
24
24
  class Debian < Chef::Provider::Service::Init
25
+ provides :service, platform_family: 'debian'
26
+
25
27
  UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i
26
28
  UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i
27
29
 
@@ -24,6 +24,8 @@ class Chef
24
24
  class Service
25
25
  class Insserv < Chef::Provider::Service::Init
26
26
 
27
+ provides :service, platform_family: %w(debian rhel fedora suse)
28
+
27
29
  def self.provides?(node, resource)
28
30
  super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv)
29
31
  end
@@ -23,6 +23,8 @@ class Chef
23
23
  class Service
24
24
  class Invokercd < Chef::Provider::Service::Init
25
25
 
26
+ provides :service, platform_family: 'debian', override: true
27
+
26
28
  def self.provides?(node, resource)
27
29
  super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokercd)
28
30
  end
@@ -26,7 +26,7 @@ class Chef
26
26
  class Service
27
27
  class Openbsd < Chef::Provider::Service::Init
28
28
 
29
- provides :service, os: [ "openbsd" ]
29
+ provides :service, os: "openbsd"
30
30
 
31
31
  include Chef::Mixin::ShellOut
32
32
 
@@ -23,6 +23,8 @@ class Chef
23
23
  class Service
24
24
  class Redhat < Chef::Provider::Service::Init
25
25
 
26
+ provides :service, platform_family: %w(rhel fedora suse)
27
+
26
28
  CHKCONFIG_ON = /\d:on/
27
29
  CHKCONFIG_MISSING = /No such/
28
30
 
@@ -25,6 +25,9 @@ class Chef
25
25
  class Provider
26
26
  class Service
27
27
  class Upstart < Chef::Provider::Service::Simple
28
+
29
+ provides :service, platform_family: 'debian', override: true
30
+
28
31
  UPSTART_STATE_FORMAT = /\w+ \(?(\w+)\)?[\/ ](\w+)/
29
32
 
30
33
  def self.provides?(node, resource)
@@ -17,7 +17,7 @@
17
17
  #
18
18
 
19
19
  require 'chef/exceptions'
20
- require 'chef/platform/provider_priority_map'
20
+ require 'chef/platform/priority_map'
21
21
 
22
22
  class Chef
23
23
  #
@@ -62,12 +62,47 @@ class Chef
62
62
  maybe_chef_platform_lookup(resource)
63
63
  end
64
64
 
65
+ # Does NOT call provides? on the resource (it is assumed this is being
66
+ # called *from* provides?).
65
67
  def provided_by?(provider_class)
66
- prioritized_handlers.include?(provider_class)
68
+ potential_handlers.include?(provider_class)
69
+ end
70
+
71
+ def enabled_handlers
72
+ @enabled_handlers ||= potential_handlers.select { |handler| !overrode_provides?(handler) || handler.provides?(node, resource) }
73
+ end
74
+
75
+ # TODO deprecate this and allow actions to be passed as a filter to
76
+ # `provides` so we don't have to have two separate things.
77
+ # @api private
78
+ def supported_handlers
79
+ enabled_handlers.select { |handler| handler.supports?(resource, action) }
67
80
  end
68
81
 
69
82
  private
70
83
 
84
+ def potential_handlers
85
+ handler_map.list(node, resource.resource_name).uniq
86
+ end
87
+
88
+ # The list of handlers, with any in the priority_map moved to the front
89
+ def prioritized_handlers
90
+ @prioritized_handlers ||= begin
91
+ supported_handlers = self.supported_handlers
92
+ if supported_handlers.empty?
93
+ # if none of the providers specifically support the resource, we still need to pick one of the providers that are
94
+ # enabled on the node to handle the why-run use case. FIXME we should only do this in why-run mode then.
95
+ Chef::Log.debug "No providers responded true to `supports?` for action #{action} on resource #{resource}, falling back to enabled handlers so we can return something anyway."
96
+ supported_handlers = enabled_handlers
97
+ end
98
+
99
+ prioritized = priority_map.list(node, resource.resource_name).flatten(1)
100
+ prioritized &= supported_handlers # Filter the priority map by the actual enabled handlers
101
+ prioritized |= supported_handlers # Bring back any handlers that aren't in the priority map, at the *end* (ordered set)
102
+ prioritized
103
+ end
104
+ end
105
+
71
106
  # if resource.provider is set, just return one of those objects
72
107
  def maybe_explicit_provider(resource)
73
108
  return nil unless resource.provider
@@ -78,27 +113,7 @@ class Chef
78
113
  def maybe_dynamic_provider_resolution(resource, action)
79
114
  Chef::Log.debug "Providers for generic #{resource.resource_name} resource enabled on node include: #{enabled_handlers}"
80
115
 
81
- # Get all the handlers in the priority bucket
82
- handlers = prioritized_handlers
83
-
84
- # Narrow it down to handlers that return `true` to `provides?`
85
- # TODO deprecate this and don't bother calling--the fact that they said
86
- # `provides` should be enough. But we need to do it right now because
87
- # some classes implement additional handling.
88
- enabled_handlers = prioritized_handlers.select { |handler| handler.provides?(node, resource) }
89
-
90
- # Narrow it down to handlers that return `true` to `supports?`
91
- # TODO deprecate this and allow actions to be passed as a filter to
92
- # `provides` so we don't have to have two separate things.
93
- supported_handlers = enabled_handlers.select { |handler| handler.supports?(resource, action) }
94
- if supported_handlers.empty?
95
- # if none of the providers specifically support the resource, we still need to pick one of the providers that are
96
- # enabled on the node to handle the why-run use case. FIXME we should only do this in why-run mode then.
97
- Chef::Log.debug "No providers responded true to `supports?` for action #{action} on resource #{resource}, falling back to enabled handlers so we can return something anyway."
98
- handler = enabled_handlers.first
99
- else
100
- handler = supported_handlers.first
101
- end
116
+ handler = prioritized_handlers.first
102
117
 
103
118
  if handler
104
119
  Chef::Log.debug "Provider for action #{action} on resource #{resource} is #{handler}"
@@ -114,13 +129,16 @@ class Chef
114
129
  Chef::Platform.find_provider_for_node(node, resource)
115
130
  end
116
131
 
117
- def provider_priority_map
118
- Chef::Platform::ProviderPriorityMap.instance
132
+ def priority_map
133
+ Chef.provider_priority_map
119
134
  end
120
135
 
121
- def prioritized_handlers
122
- @prioritized_handlers ||=
123
- provider_priority_map.list_handlers(node, resource.resource_name).flatten(1).uniq
136
+ def handler_map
137
+ Chef.provider_handler_map
138
+ end
139
+
140
+ def overrode_provides?(handler)
141
+ handler.method(:provides?).owner != Chef::Provider.method(:provides?).owner
124
142
  end
125
143
 
126
144
  module Deprecated
@@ -129,33 +147,21 @@ class Chef
129
147
  @providers ||= Chef::Provider.descendants
130
148
  end
131
149
 
132
- # this cut looks at if the provider can handle the resource type on the node
133
150
  def enabled_handlers
134
- @enabled_handlers ||=
135
- providers.select do |klass|
136
- # NB: this is different from resource_resolver which must pass a resource_name
137
- # FIXME: deprecate this and normalize on passing resource_name here
138
- klass.provides?(node, resource)
139
- end.sort {|a,b| a.to_s <=> b.to_s }
140
- end
141
-
142
- # this cut looks at if the provider can handle the specific resource and action
143
- def supported_handlers
144
- @supported_handlers ||=
145
- enabled_handlers.select do |klass|
146
- klass.supports?(resource, action)
147
- end
148
- end
149
-
150
- # If there are no providers for a DSL, we search through the
151
- def prioritized_handlers
152
- @prioritized_handlers ||= super || begin
153
- result = providers.select { |handler| handler.provides?(node, resource) }.sort_by(:name)
154
- if !result.empty?
155
- Chef::Log.deprecation("#{resource.resource_name.to_sym} is marked as providing DSL #{method_symbol}, but provides #{resource.resource_name.to_sym.inspect} was never called!")
156
- Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.")
151
+ @enabled_handlers ||= begin
152
+ handlers = super
153
+ if handlers.empty?
154
+ # Look through all providers, and find ones that return true to provides.
155
+ # Don't bother with ones that don't override provides?, since they
156
+ # would have been in enabled_handlers already if that were so. (It's a
157
+ # perf concern otherwise.)
158
+ handlers = providers.select { |handler| overrode_provides?(handler) && handler.provides?(node, resource) }
159
+ handlers.each do |handler|
160
+ Chef::Log.deprecation("#{handler}.provides? returned true when asked if it provides DSL #{resource.resource_name}, but provides #{resource.resource_name.inspect} was never called!")
161
+ Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.")
162
+ end
157
163
  end
158
- result
164
+ handlers
159
165
  end
160
166
  end
161
167
  end
data/lib/chef/resource.rb CHANGED
@@ -171,27 +171,25 @@ class Chef
171
171
  # @param arg [Array[Symbol], Symbol] A list of actions (e.g. `:create`)
172
172
  # @return [Array[Symbol]] the list of actions.
173
173
  #
174
- attr_accessor :action
175
174
  def action(arg=nil)
176
175
  if arg
177
- if arg.is_a?(Array)
178
- arg = arg.map { |a| a.to_sym }
179
- else
180
- arg = arg.to_sym
181
- end
182
- Array(arg).each do |action|
176
+ arg = Array(arg).map(&:to_sym)
177
+ arg.each do |action|
183
178
  validate(
184
179
  { action: action },
185
180
  { action: { kind_of: Symbol, equal_to: allowed_actions } }
186
181
  )
187
182
  end
188
- self.action = arg
183
+ @action = arg
189
184
  else
190
185
  # Pull the action from the class if it's not set
191
186
  @action || self.class.default_action
192
187
  end
193
188
  end
194
189
 
190
+ # Alias for normal assigment syntax.
191
+ alias_method :action=, :action
192
+
195
193
  #
196
194
  # Sets up a notification that will run a particular action on another resource
197
195
  # if and when *this* resource is updated by an action.
@@ -917,7 +915,7 @@ class Chef
917
915
  if name
918
916
  name = name.to_sym
919
917
  # If our class is not already providing this name, provide it.
920
- if !Chef::ResourceResolver.list(name).include?(self)
918
+ if !Chef::ResourceResolver.includes_handler?(name, self)
921
919
  provides name, canonical: true
922
920
  end
923
921
  @resource_name = name
@@ -981,22 +979,17 @@ class Chef
981
979
  # Setting default_action will automatially add the action to
982
980
  # allowed_actions, if it isn't already there.
983
981
  #
984
- # Defaults to :nothing.
982
+ # Defaults to [:nothing].
985
983
  #
986
984
  # @param action_name [Symbol,Array<Symbol>] The default action (or series
987
985
  # of actions) to use.
988
986
  #
989
- # @return [Symbol,Array<Symbol>] The default actions for the resource.
987
+ # @return [Array<Symbol>] The default actions for the resource.
990
988
  #
991
989
  def self.default_action(action_name=NULL_ARG)
992
990
  unless action_name.equal?(NULL_ARG)
993
- if action_name.is_a?(Array)
994
- @default_action = action_name.map { |arg| arg.to_sym }
995
- else
996
- @default_action = action_name.to_sym
997
- end
998
-
999
- self.allowed_actions |= Array(@default_action)
991
+ @default_action = Array(action_name).map(&:to_sym)
992
+ self.allowed_actions |= @default_action
1000
993
  end
1001
994
 
1002
995
  if @default_action
@@ -1004,13 +997,14 @@ class Chef
1004
997
  elsif superclass.respond_to?(:default_action)
1005
998
  superclass.default_action
1006
999
  else
1007
- :nothing
1000
+ [:nothing]
1008
1001
  end
1009
1002
  end
1010
1003
  def self.default_action=(action_name)
1011
1004
  default_action(action_name)
1012
1005
  end
1013
1006
 
1007
+
1014
1008
  #
1015
1009
  # Internal Resource Interface (for Chef)
1016
1010
  #
@@ -1105,7 +1099,7 @@ class Chef
1105
1099
  end
1106
1100
  def self.inherited(child)
1107
1101
  super
1108
- @sorted_descendants = nil
1102
+ @@sorted_descendants = nil
1109
1103
  # set resource_name automatically if it's not set
1110
1104
  if child.name && !child.resource_name
1111
1105
  if child.name =~ /^Chef::Resource::(\w+)$/
@@ -1143,13 +1137,13 @@ class Chef
1143
1137
  remove_canonical_dsl
1144
1138
  end
1145
1139
 
1146
- result = Chef.resource_priority_map.set(name, self, options, &block)
1140
+ result = Chef.resource_handler_map.set(name, self, options, &block)
1147
1141
  Chef::DSL::Resources.add_resource_dsl(name)
1148
1142
  result
1149
1143
  end
1150
1144
 
1151
- def self.provides?(node, resource)
1152
- Chef::ResourceResolver.resolve(resource, node: node).provided_by?(self)
1145
+ def self.provides?(node, resource_name)
1146
+ Chef::ResourceResolver.new(node, resource_name).provided_by?(self)
1153
1147
  end
1154
1148
 
1155
1149
  # Helper for #notifies
@@ -1306,56 +1300,11 @@ class Chef
1306
1300
  Chef::Resource.send(:remove_const, class_name)
1307
1301
  end
1308
1302
 
1309
- # In order to generate deprecation warnings when you use Chef::Resource::MyLwrp,
1310
- # we make a special subclass (identical in nearly all respects) of the
1311
- # actual LWRP. When you say any of these, a deprecation warning will be
1312
- # generated:
1313
- #
1314
- # - Chef::Resource::MyLwrp.new(...)
1315
- # - resource.is_a?(Chef::Resource::MyLwrp)
1316
- # - resource.kind_of?(Chef::Resource::MyLwrp)
1317
- # - case resource
1318
- # when Chef::Resource::MyLwrp
1319
- # end
1320
- #
1321
- resource_subclass = Class.new(resource_class) do
1322
- resource_name nil # we do not actually provide anything
1323
- def initialize(*args, &block)
1324
- Chef::Log.deprecation("Using an LWRP by its name (#{self.class.name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
1325
- super
1326
- end
1327
- def self.resource_name(*args)
1328
- if args.empty?
1329
- @resource_name ||= superclass.resource_name
1330
- else
1331
- super
1332
- end
1333
- end
1334
- self
1335
- end
1336
- eval("Chef::Resource::#{class_name} = resource_subclass")
1337
- # Make case, is_a and kind_of work with the new subclass, for backcompat.
1338
- # Any subclass of Chef::Resource::ResourceClass is already a subclass of resource_class
1339
- # Any subclass of resource_class is considered a subclass of Chef::Resource::ResourceClass
1340
- resource_class.class_eval do
1341
- define_method(:is_a?) do |other|
1342
- other.is_a?(Module) && other === self
1343
- end
1344
- define_method(:kind_of?) do |other|
1345
- other.is_a?(Module) && other === self
1346
- end
1303
+ if !Chef::Config[:treat_deprecation_warnings_as_errors]
1304
+ Chef::Resource.const_set(class_name, resource_class)
1305
+ deprecated_constants[class_name.to_sym] = resource_class
1347
1306
  end
1348
- resource_subclass.class_eval do
1349
- define_singleton_method(:===) do |other|
1350
- Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
1351
- # resource_subclass is a superclass of all resource_class descendants.
1352
- if self == resource_subclass && other.class <= resource_class
1353
- return true
1354
- end
1355
- super(other)
1356
- end
1357
- end
1358
- deprecated_constants[class_name.to_sym] = resource_subclass
1307
+
1359
1308
  end
1360
1309
 
1361
1310
  def self.deprecated_constants
@@ -1379,7 +1328,7 @@ class Chef
1379
1328
 
1380
1329
  def self.remove_canonical_dsl
1381
1330
  if @resource_name
1382
- remaining = Chef.resource_priority_map.delete_canonical(@resource_name, self)
1331
+ remaining = Chef.resource_handler_map.delete_canonical(@resource_name, self)
1383
1332
  if !remaining
1384
1333
  Chef::DSL::Resources.remove_resource_dsl(@resource_name)
1385
1334
  end