Bug #2782

Changes in Ruby 1.9.x const_set and const_get prevent puppetd from properly executing

Added by Al Hoang over 2 years ago. Updated 7 months ago.

Status:Rejected Start date:11/04/2009
Priority:Low Due date:
Assignee:- % Done:

0%

Category:unknown
Target version:-
Affected Puppet version:0.25.1 Branch:https://github.com/mmrobins/puppet/tree/19_fixes
Keywords:Ruby 1.9 ruby19
Votes: 1

Description

Hello,

Attached is a patch with modifications to get puppetd to properly execute when puppetd —trace —verbose —debug is run on the command line.

Some changes are:

  • Explicitly use the top-level File object in lib/puppet/type/file.rb
  • Add some checks on RUBY_VERSION and avoid called @resource.stat(false)
  • Call a Ruby 1.8.x compatible version of const_defined? if RUBY_VERSION looks like it is 1.9.x

Here are some useful links that might help explain some of the changes to const_set and const_set in Ruby 1.9.x:

http://issues.apache.org/jira/browse/BUILDR-140 http://jira.codehaus.org/browse/JRUBY-4197 http://redmine.ruby-lang.org/issues/show/1915 http://markmail.org/message/zr5vh2333yr3k3qi

Please note that this assumes that the changes from ticket #2781 are already applied


Related issues

related to Puppet - Bug #2191: Ruby 1.9 portability Duplicate 04/23/2009
related to Puppet - Bug #2781: Case statements with colons break Ruby 1.9.x compatibility Closed 11/04/2009

History

Updated by Peter Meier over 2 years ago

can you send the patches to puppet-dev ? –> http://reductivelabs.com/trac/puppet/wiki/Development/DevelopmentLifecycle#submitting-patches thanks!

Updated by Al Hoang over 2 years ago

Sent to the mailing list. Apologies for the confusion. I’ll spend more time reading the development cycle docs.

Updated by Peter Meier over 2 years ago

Al Hoang wrote:

Sent to the mailing list. Apologies for the confusion. I’ll spend more time reading the development cycle docs.

it’s fine to open a ticket as well. oh and pushing the code to some git repository where it can be pulled from, if it have been accepted on the list.

Updated by James Turnbull over 2 years ago

  • Status changed from Unreviewed to Investigating
  • Assignee set to James Turnbull
  • Target version set to 0.25.2

Updated by James Turnbull about 2 years ago

  • Target version changed from 0.25.2 to 2.6.0

Bumping this to Rowlf.

Updated by James Turnbull almost 2 years ago

  • Status changed from Investigating to In Topic Branch Pending Review
  • Branch set to http://github.com/hoanga/puppet/tree/0.25.x_1.9.1

Updated by Markus Roberts almost 2 years ago

  • Status changed from In Topic Branch Pending Review to Code Insufficient
  • Assignee changed from James Turnbull to Markus Roberts

I’m marking this “Code Insufficient” for want of a better designation, and assigning it to me self for eventual resolution. While we need to address the issues this branch is addressing, the present branch:

  1. Contains fragments of an older version of #2781
  2. Does not merge cleanly on master
  3. Duplicates some of the changes that are being made in the code smell process
  4. Fixes things in ways that don’t make sense (e.g. guarding @resource.stat(false) with a version check when none of the stat methods took a boolean parameter even in 1.8)

My intent is to manually go through the changes after the dust settles and come up with a patch that addresses the things that need to be fixed with a new branch, perhaps based on this one.

Updated by Markus Roberts almost 2 years ago

Excluding the duplicated when-clause changes, this branch changes:

  • XMLRPC::Service::Interface.new … from one incorrect usage to another; the correct pattern is:
    @interface = XMLRPC::Service::Interface.new("status") {
      add_method("int status()")
    }

The block does not receive an argument, and the present code only works because of a bug in ruby 1.8.x; the code on the branch would work most of the time in any version, but exposes a race condition which is the reason for the block.

  • File —> ::File; we need a better fix for this.
  • Guards calls to stat with an argument, “stat(false)” whereas they are incorrect and should just be changed to stat with no arguments
  • Makes the following change, which I do not understand:
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 87f1bb1..5e51099 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -55,6 +55,16 @@ module Puppet::Rails
 
             socket          = Puppet[:dbsocket]
             args[:socket]   = socket unless socket.empty?
+          
+            connections     = Puppet[:dbconnections].to_i
+            args[:pool]     = connections if connections > 0 
+        when "oracle_enhanced"
+               args[:database] = Puppet[:dbname] unless Puppet[:dbname].empty?
+               args[:username] = Puppet[:dbuser] unless Puppet[:dbuser].empty?
+               args[:password] = Puppet[:dbpassword] unless Puppet[:dbpassword].empty?
+
+            connections     = Puppet[:dbconnections].to_i
+            args[:pool]     = connections if connections > 0
         else
             raise ArgumentError, "Invalid db adapter %s" % adapter
         end
  • Makes the following change which directly related to the title of the ticket:
diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb
index 1aa9613..c68fcef 100644
--- a/lib/puppet/util/classgen.rb
+++ b/lib/puppet/util/classgen.rb
@@ -128,11 +128,23 @@ module Puppet::Util::ClassGen
         return klass
     end
 
+    # const_defined? in Ruby 1.9 behaves differently in terms
+    # of which class hierarchy it polls for nested namespaces
+    #
+    # See http://redmine.ruby-lang.org/issues/show/1915
+    def is_constant_defined?(const)
+      if ::RUBY_VERSION =~ /1.9/
+        const_defined?(const, false)
+      else
+        const_defined?(const)
+      end
+    end
+
     # Handle the setting and/or removing of the associated constant.
     def handleclassconst(klass, name, options)
         const = genconst_string(name, options)
 
-        if const_defined? const
+        if is_constant_defined?(const)
             if options[:overwrite]
                 Puppet.info "Redefining %s in %s" % [name, self]
                 remove_const(const)

Updated by Jesse Wolfe over 1 year ago

  • Target version changed from 2.6.0 to 52

Updated by Al Hoang over 1 year ago

Hi there,

Since I originated this ticket / patch request I think I should chime in just to clarify some things.

Markus Roberts wrote:

I’m marking this “Code Insufficient”

I think this is reasonable. I started work on getting Puppet to run on Ruby 1.9 however I’ve not had a lot of time to look into this recently but have been wanting to pick it up again and complete it.

  1. Contains fragments of an older version of #2781
  2. Does not merge cleanly on master

This makes sense and I was hoping to keep up with upstream in my branch on github however it has fallen way behind.

  1. Duplicates some of the changes that are being made in the code smell process

I’m not sure I understand what this means. If you had time to explain this, that would be very helpful. Otherwise, I’ll take your word for it.

  1. Fixes things in ways that don’t make sense (e.g. guarding @resource.stat(false) with a version check when none of the stat methods took a boolean parameter even in 1.8)

Thanks for pointing this out. I’d prefer a cleaner way to get it working. I believe you suggested a cleaner methodology awhile back on the mailing list but I’ve not had time to go back and review your suggestions again. The changesets I have on github reflected my really strong desire (at the time) to have something running over a clean implementation so please take that github branch with a grain of salt.

My intent is to manually go through the changes after the dust settles and come up with a patch that addresses the things that need to be fixed with a new branch, perhaps based on this one.

This sounds reasonable to me. If you know of a way to perhaps split what needs to be done such that I can help that would be great.

Updated by Matt Robinson about 1 year ago

  • Keywords changed from Ruby 1.9 to Ruby 1.9 ruby19

Updated by James Turnbull about 1 year ago

  • Status changed from Code Insufficient to Needs Decision
  • Assignee changed from Markus Roberts to Nigel Kersten

Updated by Nigel Kersten about 1 year ago

  • Status changed from Needs Decision to Code Insufficient
  • Assignee changed from Nigel Kersten to Markus Roberts
  • Target version changed from 52 to Telly

James, this is a Markus decision. We’ve decided to support 1.9 as a design decision, but it’s a technical decision how we go about it and code insufficient appears to characterize the situation to me.

Updated by Nigel Kersten 11 months ago

  • Target version changed from Telly to 2.7.x

Updated by Matt Robinson 11 months ago

  • Status changed from Code Insufficient to In Topic Branch Pending Review
  • Branch changed from http://github.com/hoanga/puppet/tree/0.25.x_1.9.1 to https://github.com/mmrobins/puppet/tree/19_fixes

I only got so far as using Al’s solution for dealing with const_defined? problems. The branch is too old to merge in at all easily since 0.25.x was never really merged into 2.6.x or later, so it’s hard to tell about the other changes, but I haven’t run into problems to motivate making them yet.

I’m attaching a branch that gets the code to a point that the tests will run, so past all the syntax errors that prevent code from even loading. Plenty of tests still fail under Ruby 1.9, but none do under 1.8.7. The branch needs some cleanup of the commit messages, a rename of the branch, and a code review. I’ll try to get that done tomorrow so that we can start making incremental progress on fixing test failures under 1.9.

Updated by Matt Robinson 8 months ago

  • Status changed from In Topic Branch Pending Review to Rejected
  • Assignee deleted (Markus Roberts)

This work ended up being done in another ticket as part of a lot of Ruby 1.9 fixes. We are now testing Ruby 1.9 for regressions using Jenkins.

Updated by James Turnbull 7 months ago

  • Target version deleted (2.7.x)

Also available in: Atom PDF