summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-06-25 09:30:31 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-06-25 09:30:31 -0700
commitcb0a6ce775bd9039cc2b892f55cf146ea554c56f (patch)
treeec1bf09018721db603f9ec6226bb0b4fb6c5c72b
parentab34e3cd83d545b5da19113d723eeebcab1e77e2 (diff)
parentdbb2e0c36d2585dc10eafd3c73f0af09ff0ff52a (diff)
downloadchef-cb0a6ce775bd9039cc2b892f55cf146ea554c56f.tar.gz
Merge pull request #3586 from chef/jdm/lwrp-fix
Fix to allow LW resources to be used with HW providers
-rw-r--r--lib/chef/platform/provider_mapping.rb3
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb25
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index af17d8e1b4..4278b8d24f 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -197,7 +197,8 @@ class Chef
def resource_matching_provider(platform, version, resource_type)
if resource_type.kind_of?(Chef::Resource)
- class_name = resource_type.class.to_s.split('::').last
+ class_name = resource_type.class.name ? resource_type.class.name.split('::').last :
+ convert_to_class_name(resource_type.resource_name.to_s)
begin
result = Chef::Provider.const_get(class_name)
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 6bbb9a5c4c..5426dce080 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -969,4 +969,29 @@ describe "Recipe DSL methods" do
end
end
end
+
+ context "with a dynamically defined resource and regular provider" do
+ before(:context) do
+ Class.new(Chef::Resource) do
+ resource_name :lw_resource_with_hw_provider_test_case
+ default_action :create
+ attr_accessor :created_provider
+ end
+ class Chef::Provider::LwResourceWithHwProviderTestCase < Chef::Provider
+ def load_current_resource
+ end
+ def action_create
+ new_resource.created_provider = self.class
+ end
+ end
+ end
+
+ it "looks up the provider in Chef::Provider converting the resource name from snake case to camel case" do
+ resource = nil
+ recipe = converge {
+ resource = lw_resource_with_hw_provider_test_case 'blah' do; end
+ }
+ expect(resource.created_provider).to eq(Chef::Provider::LwResourceWithHwProviderTestCase)
+ end
+ end
end