From d866ce187d45897acb9b099e7a4d77a2aadced8d Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Fri, 10 Jun 2011 10:32:30 -0700 Subject: Cleanup indentation, comment, and unused code The Great Reindentation of '10 left certain structures indented incorrectly; this addresses some of these instances. The comment about loading all providers incorrectly stated that we're trying to figure out the type, when we're actually trying to figure out the provider. There was an unused variable initialization that was introduced in 2b14f627, which was reverting c19835c, 9290cc8, and ffb4c2d. Paired-with: Jacob Helwig --- lib/puppet/metatype/manager.rb | 26 ++++++-------------------- lib/puppet/type.rb | 18 ++++++++---------- 2 files changed, 14 insertions(+), 30 deletions(-) (limited to 'lib') diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb index 12cbf645c..3a2f77b6f 100644 --- a/lib/puppet/metatype/manager.rb +++ b/lib/puppet/metatype/manager.rb @@ -61,10 +61,9 @@ module Manager # Then create the class. - klass = genclass( - name, + klass = genclass( + name, :parent => (parent || Puppet::Type), - :overwrite => true, :hash => @types, :attributes => options, @@ -87,13 +86,9 @@ module Manager # Now set up autoload any providers that might exist for this type. - klass.providerloader = Puppet::Util::Autoload.new( - klass, - - "puppet/provider/#{klass.name.to_s}" - ) + klass.providerloader = Puppet::Util::Autoload.new(klass, "puppet/provider/#{klass.name.to_s}") - # We have to load everything so that we can figure out the default type. + # We have to load everything so that we can figure out the default provider. klass.providerloader.loadall klass @@ -103,11 +98,7 @@ module Manager def rmtype(name) # Then create the class. - klass = rmclass( - name, - - :hash => @types - ) + klass = rmclass(name, :hash => @types) singleton_class.send(:remove_method, "new#{name}") if respond_to?("new#{name}") end @@ -132,12 +123,7 @@ module Manager # Create a loader for Puppet types. def typeloader unless defined?(@typeloader) - - @typeloader = Puppet::Util::Autoload.new( - self, - - "puppet/type", :wrap => false - ) + @typeloader = Puppet::Util::Autoload.new(self, "puppet/type", :wrap => false) end @typeloader diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index d24cc8554..58673462a 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1442,15 +1442,14 @@ class Type self.providify - provider = genclass( - name, - :parent => parent, - :hash => provider_hash, - :prefix => "Provider", - :block => block, - :include => feature_module, - :extend => feature_module, - + provider = genclass( + name, + :parent => parent, + :hash => provider_hash, + :prefix => "Provider", + :block => block, + :include => feature_module, + :extend => feature_module, :attributes => options ) @@ -1581,7 +1580,6 @@ class Type # Collect the current prereqs list.each { |dep| - obj = nil # Support them passing objects directly, to save some effort. unless dep.is_a? Puppet::Type # Skip autorequires that we aren't managing -- cgit From 413b136671232a8a0a9e27c18c1b6547241276e7 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Fri, 10 Jun 2011 10:48:36 -0700 Subject: (#4416) Always remove old provider before recreating it In the case where provider class evaluation failed midway, the provider class would be created but not registered. Thus, when checking whether it should be removed, it wasn't found, and wasn't removed. This caused it to then fail to be recreated, because it collided with the existing class. Now we don't bother checking whether the provider is registered before we remove it, since rmclass has the appropriate checks to do the unregistration, and class removal safely. Removing a provider class that has been created but not registered should not be a problem since the only time this can happen is when the class is unusable because of parsing or other fatal errors in the provider itself. Paired-with: Jacob Helwig --- lib/puppet/type.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 58673462a..1933097da 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1416,9 +1416,8 @@ class Type def self.provide(name, options = {}, &block) name = Puppet::Util.symbolize(name) - if obj = provider_hash[name] + if unprovide(name) Puppet.debug "Reloading #{name} #{self.name} provider" - unprovide(name) end parent = if pname = options[:parent] @@ -1441,7 +1440,6 @@ class Type self.providify - provider = genclass( name, :parent => parent, @@ -1509,18 +1507,11 @@ class Type end def self.unprovide(name) - if provider_hash.has_key? name - - rmclass( - name, - :hash => provider_hash, - - :prefix => "Provider" - ) - if @defaultprovider and @defaultprovider.name == name - @defaultprovider = nil - end + if @defaultprovider and @defaultprovider.name == name + @defaultprovider = nil end + + rmclass(name, :hash => provider_hash, :prefix => "Provider") end # Return an array of all of the suitable providers. -- cgit From caca469976cc8b5ff6c7f68d7324eecd35399176 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Fri, 10 Jun 2011 10:58:19 -0700 Subject: (#4416) Ensure types are providified after reloading Previously, the 'provider' parameter for a type was only added when creating a provider for that type. This would cause a type to forget about its 'provider' parameter when only the type was reloaded. This was manifesting itself in pluginsync, when a provider plugin would be loaded before its type, causing the type to be autoloaded. The type plugin would then be loaded again by the plugin handler. Because the type => provider information is stored separately from the type, the providers don't need to be reloaded, and thus don't recreate the type's 'provider' parameter. Now we always "providify" the type (add its 'provider' parameter) upon creation, after trying to load its providers, if any providers are present. Paired-with: Jacob Helwig --- lib/puppet/metatype/manager.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb index 3a2f77b6f..597a89f31 100644 --- a/lib/puppet/metatype/manager.rb +++ b/lib/puppet/metatype/manager.rb @@ -90,6 +90,7 @@ module Manager # We have to load everything so that we can figure out the default provider. klass.providerloader.loadall + klass.providify unless klass.providers.empty? klass end -- cgit