Hi Nick,
Thanks for getting back to me.
Unfortunately, this doesn't seem to be working for me.
I tried:
require 'rubygems'
require 'puppet'
require 'spec'
require 'spec/mocks'
env = Puppet::Node::Environment.new('nodename')
Puppet::Parser::Functions::function(:mangle_ip_address)
s = Puppet::Parser::Scope.new
s.stub(:e).and_return env
# Mask the ipaddress variable
s.setvar('ipaddress','11.22.33.44')
s.function_mangle_ip_address([])
But unfortunately ended with the same result.
I do figure that :e is not the correct procedure to stub, but I'm not
sure which one is.
Trevor
On Tue, Mar 6, 2012 at 1:17 PM, Nick Lewis <[email protected]> wrote:
> On Tuesday, March 6, 2012 at 10:03 AM, Trevor Vaughan wrote:
>
> Sorry about the re-post, but I'm not getting much traction in the User's
> list.
>
> So, many moons ago, the following used to work:
>
> require 'puppet'
>
> Puppet::Parser::Functions::function(:mangle_ip_address)
> s = Puppet::Parser::Scope.new
> # Mask the ipaddress variable
> s.setvar('ipaddress','11.22.33.44')
> s.mangle_ip_address
>
> However, now that we have to call 'lookupvar' in our functions, this
> doesn't work and gives the error:
>
> NoMethodError: undefined method `known_resource_types' for nil:NilClass
> from
> /usr/lib/ruby/site_ruby/1.8/puppet/resource/type_collection_helper.rb:5:in
> `known_resource_types'
>
> Does anyone have any ideas on how to get this working again?
>
> It looks like it's trying to look up a class to check if a variable is in
> there, so it needs a TypeCollection (known_resource_types) which comes from
> an environment. It should work to just create an environment and stub it on
> the scope (unfortunately, it normally comes from compiler, so you can't just
> set it, but there's no reason to actually make a compiler).
>
> env = Puppet::Node::Environment.new('nodename')
> s = Puppet::Parser::Scope.new
> s.stubs(:e).returns env
>
> Thanks,
>
> Trevor
>
> --
> Trevor Vaughan
> Vice President, Onyx Point, Inc
> (410) 541-6699
> [email protected]
>
> -- This account not approved for unencrypted proprietary information --
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en.
--
Trevor Vaughan
Vice President, Onyx Point, Inc
(410) 541-6699
[email protected]
-- This account not approved for unencrypted proprietary information --
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.