Lwrp's and libraries broken kung-foo


#1

We recently updated to open chef 10.6 (from 9.8) and my lwrp broke a
little.
The goal of the LWRP is to auto discover the presence of utilities on the
system, and use the appropriate one.
The way it was rigged as:

  • A library file contains a general purpose class which is to be extended
    by the utility specific classes
  • The general class implements self.inherited(subclass), and records in a
    class variable all the extending classes (an array)
  • The provider in its load_current_resource iterates over the collection
    of available libraries, until one reports it can operate on this system.

This worked nicely in .9.8, but broke in .10.6. Poking at chef code a bit,
it seems that the reason for that is the switch in run_context.rb
load_libraries to using Kernel.load() rather than require. (I think). This
seems to prevent any common context between the different libraries and
providers (??)

To put it it code:

in libraries/d_base.rb:

class BASE:
@@controller_styles = []

def self.inherited(subclass)
  @@controller_styles  << subclass
end

def self.controller_styles
  @@controller_styles
end

end

in libraries/d_a.rb:

class ASTYLE < BASE
def working()
return test
end
end

in providers/a.rb:

def load_current_resource
BASE.controller_styles.each { |c|
break if c.working()
}
end

A few questions:

) what triggered the switch from ‘require’ to Kernel.load()? Is it around
better isolation of libraries within the same provider, or across providers?
) anyone else hit something similar?
) is there a way of achieving this in 0.10.6 and beyond?

thanks for any pointers.