diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-04 14:48:15 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-08 11:26:07 -0800 |
commit | 4aba8b23a6248e34aca75436ad142836fe2d4c82 (patch) | |
tree | 0985fdd976c03cf9f1e644d918b3c96f32c1c9f4 /lib/chef | |
parent | 74889fe64a8a71c48fb1d0ffa124f3d28fb9695c (diff) | |
download | chef-4aba8b23a6248e34aca75436ad142836fe2d4c82.tar.gz |
polishing provider_resolver
* makes provides? more correct for linux services
* makes supports? more targetted for linux services
* remove provider_resolver from the run_context
* fix timestamped deploy spec
* add more specs
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/service/aixinit.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/service/arch.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/service/debian.rb | 6 | ||||
-rw-r--r-- | lib/chef/provider/service/init.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/service/insserv.rb | 6 | ||||
-rw-r--r-- | lib/chef/provider/service/invokercd.rb | 6 | ||||
-rw-r--r-- | lib/chef/provider/service/redhat.rb | 6 | ||||
-rw-r--r-- | lib/chef/provider/service/systemd.rb | 6 | ||||
-rw-r--r-- | lib/chef/provider/service/upstart.rb | 7 | ||||
-rw-r--r-- | lib/chef/provider_resolver.rb | 37 | ||||
-rw-r--r-- | lib/chef/resource.rb | 3 | ||||
-rw-r--r-- | lib/chef/run_context.rb | 5 |
12 files changed, 61 insertions, 29 deletions
diff --git a/lib/chef/provider/service/aixinit.rb b/lib/chef/provider/service/aixinit.rb index ab4b8e5406..19beac79f0 100644 --- a/lib/chef/provider/service/aixinit.rb +++ b/lib/chef/provider/service/aixinit.rb @@ -114,4 +114,4 @@ class Chef end end end -end
\ No newline at end of file +end diff --git a/lib/chef/provider/service/arch.rb b/lib/chef/provider/service/arch.rb index 888fb3fdf5..e7fbcc820c 100644 --- a/lib/chef/provider/service/arch.rb +++ b/lib/chef/provider/service/arch.rb @@ -23,7 +23,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init provides :service, platform_family: "arch" def self.supports?(resource, action) - ::File.exist?("/etc/rc.d/#{resource.service_name}") + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:etc_rcd) end def initialize(new_resource, run_context) diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index 25b1960b26..01505924cb 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -27,8 +27,12 @@ class Chef provides :service, platform_family: "debian" + def self.provides?(node, resource) + super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian) + end + def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian) + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) end def load_current_resource diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb index ab40a720f6..0a219a69e1 100644 --- a/lib/chef/provider/service/init.rb +++ b/lib/chef/provider/service/init.rb @@ -28,6 +28,10 @@ class Chef provides :service, os: "!windows" + def self.supports?(resource, action) + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) + end + def initialize(new_resource, run_context) super @init_command = "/etc/init.d/#{@new_resource.service_name}" diff --git a/lib/chef/provider/service/insserv.rb b/lib/chef/provider/service/insserv.rb index df5a162a45..37901b7802 100644 --- a/lib/chef/provider/service/insserv.rb +++ b/lib/chef/provider/service/insserv.rb @@ -26,8 +26,12 @@ class Chef provides :service, os: "linux" + def self.provides?(node, resource) + super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv) + end + def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv) + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:upstart) end def load_current_resource diff --git a/lib/chef/provider/service/invokercd.rb b/lib/chef/provider/service/invokercd.rb index c7472211bc..5ff24e0dbb 100644 --- a/lib/chef/provider/service/invokercd.rb +++ b/lib/chef/provider/service/invokercd.rb @@ -25,8 +25,12 @@ class Chef provides :service, platform_family: "debian" + def self.provides?(node, resource) + super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokercd) + end + def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokerc) + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) end def initialize(new_resource, run_context) diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb index 90744ae268..850953125e 100644 --- a/lib/chef/provider/service/redhat.rb +++ b/lib/chef/provider/service/redhat.rb @@ -28,8 +28,12 @@ class Chef provides :service, platform_family: [ "rhel", "fedora", "suse" ] + def self.provides?(node, resource) + super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) + end + def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) end def initialize(new_resource, run_context) diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb index 717ff7dc5c..9085ffde2e 100644 --- a/lib/chef/provider/service/systemd.rb +++ b/lib/chef/provider/service/systemd.rb @@ -28,8 +28,12 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple attr_accessor :status_check_success + def self.provides?(node, resource) + super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) + end + def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:systemd) end def load_current_resource diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index 41bd850d6a..3a3ddb2385 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -29,9 +29,12 @@ class Chef provides :service, os: "linux" + def self.provides?(node, resource) + super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) + end + def self.supports?(resource, action) - Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) && - Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:upstart) + Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:upstart) end # Upstart does more than start or stop a service, creating multiple 'states' [1] that a service can be in. diff --git a/lib/chef/provider_resolver.rb b/lib/chef/provider_resolver.rb index 0c3a798d3c..247102f191 100644 --- a/lib/chef/provider_resolver.rb +++ b/lib/chef/provider_resolver.rb @@ -23,22 +23,42 @@ class Chef class ProviderResolver attr_reader :node + attr_reader :resource + attr_reader :action - def initialize(node) + def initialize(node, resource, action) @node = node + @resource = resource + @action = action end # return a deterministically sorted list of Chef::Provider subclasses def providers - Chef::Provider.descendants.sort {|a,b| a.to_s <=> b.to_s } + @providers ||= Chef::Provider.descendants.sort {|a,b| a.to_s <=> b.to_s } end - def resolve(resource, action) + def resolve maybe_explicit_provider(resource) || maybe_dynamic_provider_resolution(resource, action) || maybe_chef_platform_lookup(resource) end + # this cut looks at if the provider can handle the resource type on the node + def enabled_handlers + @enabled_handlers ||= + providers.select do |klass| + klass.provides?(node, resource) + end + end + + # this cut looks at if the provider can handle the specific resource and action + def supported_handlers + @supported_handlers ||= + enabled_handlers.select do |klass| + klass.supports?(resource, action) + end + end + private # if resource.provider is set, just return one of those objects @@ -49,20 +69,9 @@ class Chef # try dynamically finding a provider based on querying the providers to see what they support def maybe_dynamic_provider_resolution(resource, action) - # this cut only depends on the node value and is going to be static for all nodes - # will contain all providers that could possibly support a resource on a node - enabled_handlers = providers.select do |klass| - klass.provides?(node, resource) - end - # log this so we know what providers will work for the generic resource on the node (early cut) Chef::Log.debug "providers for generic #{resource.resource_name} resource enabled on node include: #{enabled_handlers}" - # ask all the enabled providers if they can actually support the resource - supported_handlers = enabled_handlers.select do |klass| - klass.supports?(resource, action) - end - # what providers were excluded by machine state (late cut) Chef::Log.debug "providers that refused resource #{resource} were: #{enabled_handlers - supported_handlers}" Chef::Log.debug "providers that support resource #{resource} include: #{supported_handlers}" diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index c38f36aa72..8d964da66d 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -29,6 +29,7 @@ require 'chef/resource/conditional_action_not_nothing' require 'chef/resource_collection' require 'chef/node_map' require 'chef/node' +require 'chef/provider_resolver' require 'chef/platform' require 'chef/mixin/deprecation' @@ -679,7 +680,7 @@ F end def provider_for_action(action) - provider = run_context.provider_resolver.resolve(self, action).new(self, run_context) + provider = Chef::ProviderResolver.new(node, self, action).resolve.new(self, run_context) provider.action = action provider end diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 18d353ac61..1a2d7ba3a3 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -18,7 +18,6 @@ # limitations under the License. require 'chef/resource_collection' -require 'chef/provider_resolver' require 'chef/cookbook_version' require 'chef/node' require 'chef/role' @@ -51,9 +50,6 @@ class Chef # recipes, which is triggered by #load. (See also: CookbookCompiler) attr_accessor :resource_collection - # Chef::ProviderResolver for this run - attr_accessor :provider_resolver - # A Hash containing the immediate notifications triggered by resources # during the converge phase of the chef run. attr_accessor :immediate_notification_collection @@ -87,7 +83,6 @@ class Chef @node.run_context = self @cookbook_compiler = nil - @provider_resolver = Chef::ProviderResolver.new(@node) end # Triggers the compile phase of the chef run. Implemented by |