Ask Your Question
0

validate_array with one element in array

asked 2016-01-11 09:05:24 -0500

tp gravatar image

updated 2016-01-11 09:09:53 -0500

Hey,

short: I have a problem with validate_array()from puppetlabs-stdlib (v4.10.0) (https://github.com/puppetlabs/puppetl...) An array with only one element returns an error like ... is not an Array. It looks to be a String ...

I try follow:

  @@icinga2::object::apply_dependency { "dep_service2-${::fqdn}":
    object_type => 'Service',
    parent_host_name => $::fqdn,
    states => [ 'Up',],
    disable_notifications => true,
    assign_where => "\"host.name=='${::fqdn}\"",
    tag=> 'neu6',
  }

And then I collect this:

Icinga2::Object::Apply_dependency <<| tag=='neu6' |>> { }

I get follow error message:

Error 400 on SERVER: "Up" is not an Array.  It looks to be a String at /etc/puppet/environments/production/modules/icinga2/manifests/object/apply_dependency.pp:45 ....

Now I change it to:

  @@icinga2::object::apply_dependency { "dep_service2-${::fqdn}":
    object_type => 'Service',
    parent_host_name => $::fqdn,
    states => [ 'Up','Up'],
    disable_notifications => true,
    assign_where => "\"host.name=='${::fqdn}\"",
    tag=> 'neu7',
  }

and collect it again with:

Icinga2::Object::Apply_dependency <<| tag=='neu7' |>> { }

Now puppet agent -t runs fine.

line 45 of /etc/puppet/environments/production/modules/icinga2/manifests/object/apply_dependency.pp is

validate_array($states)

(https://github.com/Icinga/puppet-icin... )

Is for function validate_array() from std_lib an array with only one element not an array?

Best regards, thomas polnik.

edit retag flag offensive close merge delete

Comments

Can you update so that we can see the code that is failing? Thanks.

Alex Harvey gravatar imageAlex Harvey ( 2016-01-11 21:08:44 -0500 )edit

Oh, sorry, I see the code's there. Yes, sounds like a bug. I'll see if I can reproduce it.

Alex Harvey gravatar imageAlex Harvey ( 2016-01-11 21:11:32 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-02-07 19:23:12 -0500

Henrik Lindberg gravatar image

The problem is the irritating behavior that resource attributes when assigned an array with a single element will unwrap the value. There is a bug report about this: https://tickets.puppetlabs.com/browse... The problem with fixing this is that the behavior has been around for a very long time and is thus a breaking change.

If your case is different than PUP-4911 you should log a ticket.

edit flag offensive delete link more
0

answered 2016-01-12 20:49:36 -0500

updated 2016-01-12 20:51:19 -0500

I am fairly sure this is a bug.

I tried the following code that works fine for me:

# cat /tmp/foo.pp 
define my_type(
  $arr = [],
) {
  validate_array($arr)
  $f = $arr[0]
  notify { "first element of your array is $f": }
}

my_type { 'type':
  arr => [ 'a' ],
}

# puppet apply /tmp/foo.pp
Notice: Compiled catalog for centos-66-x64.macquarie.local in environment production in 0.06 seconds
Notice: first element of your array is a
Notice: /Stage[main]//My_type[type]/Notify[first element of your array is a]/message: defined 'message' as 'first element of your array is a'
Notice: Finished catalog run in 0.04 seconds

You should probably try doing something simple yourself on your own system as I've done to limit the scope and see if you can find which component has the bug, then raise a bug against the appropriate project.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-01-11 09:05:24 -0500

Seen: 178 times

Last updated: Jan 12 '16