FAQ
Running 2.7.14 both on the client and server.

I've created a defined type for managing network interface IPs and static
routes. The routes are passed in as an array of hashes. I used the empty()
function to see if the array is empty before attempting to call another
defined type to write out the files for managing static routes. Whenever I
try to apply this on the client, I receive the following error:

err: Could not retrieve catalog from remote server: Error 400 on SERVER:
Function 'empty' does not return a value at
/etc/puppet/modules/netif/manifests/init.pp:78 on node [REDACTED]
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run

The same error appears on the server.

Relevant code is below:

define netif::interface ( $ifaddr = "", $slaves = [] , $onboot = "yes",
$onparent = "yes" , $mtu = "" , $routes = undef)
{
# switch on interface name
case $name {
# catch alias first since it might match other stuff
/^.*:.*$/ : {
netif::alias { $name :
ifaddr => $ifaddr ,
}
}
# regular ethernet interface.
/^eth\d+$/ : {
netif::eth { $name :
ifaddr => $ifaddr ,
}
}
# vlan ethernet interface.
/^eth\d+\.\d+$/ : {
netif::eth_vlan { $name :
ifaddr => $ifaddr ,
}
}
# regular ib interface.
/^ib\d+$/ : {
netif::ib { $name :
ifaddr => $ifaddr ,
}
}
# partitioned ib interface.
/^ib\d+\.\d+$/ : {
netif::ib_pkey { $name :
ifaddr => $ifaddr ,
}
}
# bridge interface
/^br\d+$/ : {
netif::br { $name :
ifaddr => $ifaddr ,
slaves => $slaves ,
}
}
# tap interface
/^tap\d+$/ : {
netif::tap { $name :
ifaddr => $ifaddr ,
}
}

# default case do nothing
default : { notify {"netif: interface type ${name} not found.":} }
}

# make route file
if !empty($routes) {
netif::route { $name :
routes => $routes
}
}
}

--dlloyd

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Nan Liu at Jul 16, 2012 at 4:01 pm

    On Mon, Jul 16, 2012 at 7:46 AM, Dave Lloyd wrote:
    Running 2.7.14 both on the client and server.

    I've created a defined type for managing network interface IPs and static
    routes. The routes are passed in as an array of hashes. I used the empty()
    function to see if the array is empty before attempting to call another
    defined type to write out the files for managing static routes. Whenever I
    try to apply this on the client, I receive the following error:

    err: Could not retrieve catalog from remote server: Error 400 on SERVER:
    Function 'empty' does not return a value at
    /etc/puppet/modules/netif/manifests/init.pp:78 on node [REDACTED]
    warning: Not using cache on failed catalog
    err: Could not retrieve catalog; skipping run
    empty() should be an rvalue function. In this case posting the empty()
    function would be more helpful than the puppet manifests.

    Nan

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Dave Lloyd at Jul 16, 2012 at 4:49 pm

    On Mon, Jul 16, 2012 at 10:56 AM, Nan Liu wrote:

    empty() should be an rvalue function. In this case posting the empty()
    function would be more helpful than the puppet manifests.

    Nan
    It's the standard one shipped with stdlib:

    modules/stdlib/lib/puppet/parser/functions/empty.rb
    #
    # empty.rb
    #

    module Puppet::Parser::Functions
    newfunction(:empty, :type => :rvalue, :doc => <<-EOS
    Returns true if the variable is empty.
    EOS
    ) do |arguments|

    raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
    "given (#{arguments.size} for 1)") if arguments.size < 1

    value = arguments[0]
    klass = value.class

    unless [Array, Hash, String].include?(klass)
    raise(Puppet::ParseError, 'empty(): Requires either ' +
    'array, hash or string to work with')
    end

    result = value.empty?

    return result
    end
    end

    # vim: set ts=2 sw=2 et :

    --dlloyd

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Nan Liu at Jul 16, 2012 at 9:05 pm

    On Mon, Jul 16, 2012 at 9:48 AM, Dave Lloyd wrote:
    On Mon, Jul 16, 2012 at 10:56 AM, Nan Liu wrote:



    empty() should be an rvalue function. In this case posting the empty()
    function would be more helpful than the puppet manifests.

    Nan
    It's the standard one shipped with stdlib:
    Didn't realize you were using stdlib. I ran a quick test with undef
    and some common variables, and wasn't able to trigger the error msg.
    Would you be able to provide an example resource and the value for
    $routes that triggered this problem?

    Nan

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Dave Lloyd at Jul 17, 2012 at 7:53 pm
    Nan:

    I also coded up a test module using empty() and it works just fine, so it
    seems that the issue is in how my module uses the empty() function. It
    almost seems as though the empty() function is getting redefined somewhere
    else, yet I don't find any other definitions anywhere in /etc/puppet/* . Is
    there another location I should be looking in to see if there is a
    duplicate definition? Perhaps some way I could print out an include path?

    This leads me to a broader question, are there any tips/best practices for
    debugging modules using custom functions?

    --dlloyd

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Dave Lloyd at Jul 18, 2012 at 9:17 pm
    Nan:

    Since my test module worked and copying and pasting would be at best
    cumbersome, I've just created a github project with my module:
    https://github.com/ibikestl/puppet-netif

    Examples should be in the tests.

    Thanks again for your help on this,

    --dlloyd

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Dave Lloyd at Jul 20, 2012 at 8:13 pm
    Success! I've figured out what happened! It looks like not just custom
    functions disappeared, but also functions that are part of puppet
    disappeared (like split()). In fact, it looks like anything that was loaded
    into puppet via Puppet::Parser::Functions had disappeared (not knowing much
    about Puppet internals, I'm guessing that there's a table or hash that the
    functions are stored in, or they're added as methods).

    One of the modules I use is ghoneycutt's puppet-xinetd module:
    https://github.com/ghoneycutt/puppet-xinetd . This module includes spec
    test files. Once I removed the spec directory and restarted the puppet
    master, all was well.

    I expect that the real issue here is that all of Puppet's internal
    functions got whacked because of bad tests in the spec direcotry in
    puppet-xinetd. The error messge, while technically true, didn't do much to
    point me in the right direction. Is there a way that Puppet can test
    whether or not expected functions are present, refuse to start if they are
    not, and log a more informative error?

    --dlloyd


    On Wed, Jul 18, 2012 at 4:17 PM, Dave Lloyd wrote:

    Nan:

    Since my test module worked and copying and pasting would be at best
    cumbersome, I've just created a github project with my module:
    https://github.com/ibikestl/puppet-netif

    Examples should be in the tests.

    Thanks again for your help on this,

    --dlloyd

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedJul 16, '12 at 2:49p
activeJul 20, '12 at 8:13p
posts7
users2
websitepuppetlabs.com

2 users in discussion

Dave Lloyd: 5 posts Nan Liu: 2 posts

People

Translate

site design / logo © 2022 Grokbase