diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-10-09 11:55:56 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-10-09 11:55:56 -0700 |
commit | 5a30432e811ca53e5b94bafb0145d5cadb4f4573 (patch) | |
tree | a9cf6268e4507f77e0057f38cdba3319748e3fcd | |
parent | e544bcbbe323d090a2e3d0c506aa966421370f55 (diff) | |
parent | 911cad381009a7a7dbe2723af37ddc5f96c2408b (diff) | |
download | chef-5a30432e811ca53e5b94bafb0145d5cadb4f4573.tar.gz |
Merge pull request #2193 from opscode/sersut/no-lwrp-class-reload
Don't override LWRP resources or providers anymore in Chef 12.
-rw-r--r-- | lib/chef/provider/lwrp_base.rb | 20 | ||||
-rw-r--r-- | lib/chef/resource/lwrp_base.rb | 26 | ||||
-rw-r--r-- | spec/data/lwrp/providers/buck_passer.rb | 11 | ||||
-rw-r--r-- | spec/data/lwrp/resources/foo.rb | 5 | ||||
-rw-r--r-- | spec/data/lwrp_override/providers/buck_passer.rb | 15 | ||||
-rw-r--r-- | spec/data/lwrp_override/resources/foo.rb | 7 | ||||
-rw-r--r-- | spec/unit/lwrp_spec.rb | 16 |
7 files changed, 52 insertions, 48 deletions
diff --git a/lib/chef/provider/lwrp_base.rb b/lib/chef/provider/lwrp_base.rb index 90ce70ae61..135a3f6b7c 100644 --- a/lib/chef/provider/lwrp_base.rb +++ b/lib/chef/provider/lwrp_base.rb @@ -81,22 +81,24 @@ class Chef include Chef::DSL::DataQuery def self.build_from_file(cookbook_name, filename, run_context) + provider_class = nil provider_name = filename_to_qualified_string(cookbook_name, filename) - # Add log entry if we override an existing light-weight provider. class_name = convert_to_class_name(provider_name) if Chef::Provider.const_defined?(class_name) - Chef::Log.info("#{class_name} light-weight provider already initialized -- overriding!") + Chef::Log.info("#{class_name} light-weight provider is already initialized -- Skipping loading #{filename}!") + Chef::Log.debug("Overriding already defined LWRPs is not supported anymore starting with Chef 12.") + provider_class = Chef::Provider.const_get(class_name) + else + provider_class = Class.new(self) + provider_class.class_from_file(filename) + + class_name = convert_to_class_name(provider_name) + Chef::Provider.const_set(class_name, provider_class) + Chef::Log.debug("Loaded contents of #{filename} into a provider named #{provider_name} defined in Chef::Provider::#{class_name}") end - provider_class = Class.new(self) - provider_class.class_from_file(filename) - - class_name = convert_to_class_name(provider_name) - Chef::Provider.const_set(class_name, provider_class) - Chef::Log.debug("Loaded contents of #{filename} into a provider named #{provider_name} defined in Chef::Provider::#{class_name}") - provider_class end diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index 5b67941a8b..19c1aa4269 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -35,26 +35,24 @@ class Chef # Evaluates the LWRP resource file and instantiates a new Resource class. def self.build_from_file(cookbook_name, filename, run_context) + resource_class = nil rname = filename_to_qualified_string(cookbook_name, filename) - # Add log entry if we override an existing lightweight resource. class_name = convert_to_class_name(rname) if Resource.strict_const_defined?(class_name) - old_class = Resource.send(:remove_const, class_name) - # CHEF-3432 -- Chef::Resource keeps a list of subclasses; need to - # remove old ones from the list when replacing. - resource_classes.delete(old_class) - Chef::Log.info("#{class_name} lightweight resource already initialized -- overriding!") - end - - resource_class = Class.new(self) + Chef::Log.info("#{class_name} light-weight resource is already initialized -- Skipping loading #{filename}!") + Chef::Log.debug("Overriding already defined LWRPs is not supported anymore starting with Chef 12.") + resource_class = Resource.const_get(class_name) + else + resource_class = Class.new(self) - resource_class.resource_name = rname - resource_class.run_context = run_context - resource_class.class_from_file(filename) + resource_class.resource_name = rname + resource_class.run_context = run_context + resource_class.class_from_file(filename) - Chef::Resource.const_set(class_name, resource_class) - Chef::Log.debug("Loaded contents of #{filename} into a resource named #{rname} defined in Chef::Resource::#{class_name}") + Chef::Resource.const_set(class_name, resource_class) + Chef::Log.debug("Loaded contents of #{filename} into a resource named #{rname} defined in Chef::Resource::#{class_name}") + end resource_class end diff --git a/spec/data/lwrp/providers/buck_passer.rb b/spec/data/lwrp/providers/buck_passer.rb index 1f83e5098b..8d5156af81 100644 --- a/spec/data/lwrp/providers/buck_passer.rb +++ b/spec/data/lwrp/providers/buck_passer.rb @@ -1,3 +1,10 @@ -action :buck_stops_here do - log "This should be overwritten by ../lwrp_override/buck_passer.rb" +action :pass_buck do + lwrp_foo :prepared_thumbs do + action :prepare_thumbs + provider :lwrp_thumb_twiddler + end + lwrp_foo :twiddled_thumbs do + action :twiddle_thumbs + provider :lwrp_thumb_twiddler + end end diff --git a/spec/data/lwrp/resources/foo.rb b/spec/data/lwrp/resources/foo.rb index c881c80530..0ee83f0cd0 100644 --- a/spec/data/lwrp/resources/foo.rb +++ b/spec/data/lwrp/resources/foo.rb @@ -1,3 +1,4 @@ -actions :never_execute +actions :prepare_thumbs, :twiddle_thumbs +default_action :pass_buck -attribute :ever, :kind_of => String +attribute :monkey, :kind_of => String diff --git a/spec/data/lwrp_override/providers/buck_passer.rb b/spec/data/lwrp_override/providers/buck_passer.rb index 75917a58c9..2061b391dc 100644 --- a/spec/data/lwrp_override/providers/buck_passer.rb +++ b/spec/data/lwrp_override/providers/buck_passer.rb @@ -1,10 +1,5 @@ -action :pass_buck do - lwrp_foo :prepared_thumbs do - action :prepare_thumbs - provider :lwrp_thumb_twiddler - end - lwrp_foo :twiddled_thumbs do - action :twiddle_thumbs - provider :lwrp_thumb_twiddler - end -end
\ No newline at end of file +# Starting with Chef 12 reloading an LWRP shouldn't reload the file anymore + +action :buck_stops_here do + log "This should be overwritten by ../lwrp_override/buck_passer.rb" +end diff --git a/spec/data/lwrp_override/resources/foo.rb b/spec/data/lwrp_override/resources/foo.rb index 0ee83f0cd0..14decb9634 100644 --- a/spec/data/lwrp_override/resources/foo.rb +++ b/spec/data/lwrp_override/resources/foo.rb @@ -1,4 +1,5 @@ -actions :prepare_thumbs, :twiddle_thumbs -default_action :pass_buck +# Starting with Chef 12 reloading an LWRP shouldn't reload the file anymore -attribute :monkey, :kind_of => String +actions :never_execute + +attribute :ever, :kind_of => String diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index 960aff3c36..28d32d71ba 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -42,7 +42,8 @@ describe "LWRP" do end Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file| - Chef::Log.should_receive(:info).with(/overriding/) + Chef::Log.should_receive(:info).with(/Skipping/) + Chef::Log.should_receive(:debug).with(/anymore/) Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) end end @@ -53,16 +54,15 @@ describe "LWRP" do end Dir[File.expand_path( "lwrp/providers/*", CHEF_SPEC_DATA)].each do |file| - Chef::Log.should_receive(:info).with(/overriding/) + Chef::Log.should_receive(:info).with(/Skipping/) + Chef::Log.should_receive(:debug).with(/anymore/) Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil) end end - it "removes the old LRWP resource class from the list of resource subclasses [CHEF-3432]" do - # CHEF-3432 regression test: - # Chef::Resource keeps a list of all subclasses to assist class inflation - # for json parsing (see Chef::JSONCompat). When replacing LWRP resources, - # we need to ensure the old resource class is remove from that list. + it "keeps the old LRWP resource class in the list of resource subclasses" do + # This was originally CHEF-3432 regression test. But with Chef 12 we are + # not replacing the original classes anymore. Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file| Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) end @@ -71,7 +71,7 @@ describe "LWRP" do Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file| Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) end - Chef::Resource.resource_classes.should_not include(first_lwr_foo_class) + Chef::Resource.resource_classes.should include(first_lwr_foo_class) end it "does not attempt to remove classes from higher up namespaces [CHEF-4117]" do |