Skip to content

(#22362) Changes in const_defined?() on ruby 1.9 break Puppet::Util::Cla...#1864

Merged
adrienthebo merged 1 commit intopuppetlabs:masterfrom
ptomulik:fix/master/rmclass_const_defined
Sep 10, 2013
Merged

(#22362) Changes in const_defined?() on ruby 1.9 break Puppet::Util::Cla...#1864
adrienthebo merged 1 commit intopuppetlabs:masterfrom
ptomulik:fix/master/rmclass_const_defined

Conversation

@ptomulik
Copy link
Contributor

I have this example (three files):

#lib/puppet/type/packagex.rb
module Puppet
  newtype(:packagex, :parent => Puppet::Type.type(:package)) do
  end
end

and

# lib/puppet/provider/packagex/ports.rb
Puppet::Type.type(:packagex).provide :ports, 
  :parent => Puppet::Type.type(:package).provider(:ports) do
end

and

# test.rb
$LOAD_PATH.unshift('lib')
require 'puppet'
Puppet::Type.type(:packagex)

Running 'ruby test.rb' fails on ruby >=1.9 with the following exception:

/usr/local/lib/ruby/site_ruby/1.9/puppet/util/autoload.rb:68:in `rescue in load_file': Could not autoload puppet/type/packagex: Could not autoload puppet/provider/packagex/ports: constant Puppet::Type::Packagex::ProviderPorts not defined (Puppet::Error)
        from /usr/local/lib/ruby/site_ruby/1.9/puppet/util/autoload.rb:59:in `load_file'
        from /usr/local/lib/ruby/site_ruby/1.9/puppet/util/autoload.rb:201:in `load'
        from /usr/local/lib/ruby/site_ruby/1.9/puppet/metatype/manager.rb:159:in `type'
        from /tmp/test.rb:4:in `<main>'

The problem appears, when using newtype with :parent argument. I've tracked down the problem and found that the exception is raised from Puppet::Util::Classgen.rmclass(). The method uses const_defined?() whose behavior changed in ruby 1.9.

@ptomulik
Copy link
Contributor Author

The example may be actually simplified:

# lib/puppet/provider/packagex/ports.rb
Puppet::Type.type(:packagex).provide :ports do
end

@puppetcla
Copy link

Waiting for CLA signature by @ptomulik

@ptomulik - We require a Contributor License Agreement (CLA) for people who contribute to Puppet, but we have an easy click-through license with instructions, which is available at https://cla.puppetlabs.com/

Note: if your contribution is trivial and you think it may be exempt from the CLA, please post a short reply to this comment with details. http://docs.puppetlabs.com/community/trivial_patch_exemption.html

@ptomulik
Copy link
Contributor Author

Signed CLA. Also: the contribution is trivial

@puppetcla
Copy link

CLA signed by all contributors.

@Sharpie
Copy link
Contributor

Sharpie commented Sep 10, 2013

Cross-reference: This is Redmine #22362

@adrienthebo
Copy link
Contributor

Thank you very much for this contribution!

For clarification, the type declaration:

module Puppet
  newtype() do
    # etc
  end
end

is a less common way of invoking newtype, and the comments indicate that this was deprecated in 2008, albeit silently. Could you test this syntax:

Puppet::Type.newtype(:packagex) do
  # etc
end

And see if this has any impact on the issue raised?

@ptomulik
Copy link
Contributor Author

No, this has no influence. The exception is still raised. It disappears once the patch is applied.

@adrienthebo
Copy link
Contributor

Fair enough, and your change is a good one. (That being said, you might want to prefer the latter type declaration). It doesn't look like there are any existing unit tests for Classgen, so I think this is ready for merging.

adrienthebo added a commit that referenced this pull request Sep 10, 2013
(#22362) Changes in const_defined?() on ruby 1.9 break Puppet::Util::Cla...
@adrienthebo adrienthebo merged commit 7f4b593 into puppetlabs:master Sep 10, 2013
@adrienthebo
Copy link
Contributor

summary: merged into master in 7f4b593; this should be released in 3.4.0. Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants