Ignore resource in provider if not defined?

53 views
Skip to first unread message

Gavin Williams

unread,
May 6, 2014, 12:40:09 PM5/6/14
to puppet...@googlegroups.com
Afternoon all,

I'm trying to update my Glassfish module [1] to support some additional functionality, such as clustering.

I've done most of the code changes, and they all seem to work fine from a usage POV. However several of my tests [2] are failing with the following error:
  1) Puppet::Type::Application::ProviderAsadmin when asking exists? should return true if resource is present
     Failure/Error: application.provider.should be_exists
     Puppet::Error:
       Invalid parameter dashost(:dashost)
     # ./lib/puppet/provider/asadmin.rb:6:in `asadmin_exec'
     # ./lib/puppet/provider/application/asadmin.rb:22:in `exists?'
     # ./spec/unit/puppet/provider/application/asadmin_spec.rb:34:in `block (3 levels) in <top (required)>'

I suspect this is related to some changes I made to Puppet::Provider::Asadmin [3] in order to support running asadmin commands against a host other than localhost.
Effectively, I'm just trying to only use the 'dashost' resource value if it's defined and not null.
This works fine for actual usage, but seems to fail horribly for RSpec testing :(

Cheers in advance for any replies.

Regards
Gavin

[1] https://github.com/fatmcgav/puppet-glassfish/tree/develop
[2] https://travis-ci.org/fatmcgav/puppet-glassfish/jobs/24549377#L505-L511
[3] https://github.com/fatmcgav/puppet-glassfish/blob/develop/lib/puppet/provider/asadmin.rb#L6-L8

Gavin Williams

unread,
May 7, 2014, 9:47:48 AM5/7/14
to puppet...@googlegroups.com
Further to the below, it looks like I appear to be getting differing behaviour in various environments :(

TravisCI passes on Ruby 1.8.7 [1] but fails on Ruby 1.9.3 [2].
Running the tests on a local CentOS 6 box with RVM, I get failures with both versions of Ruby... So not sure why TravisCI can pass 1.8.7, but locally I cant :'(

Adding in some additional debug logging, I can see that 'defined?(@resource[:dashost]' returns true with a 'method' response.
However whenever I try and evaluate the value of 'resource[:dashost]', I get the 'Invalid parameter dashost(:dashost)' error.

Any ideas if it's possible to have 'optional' params that aren't defined on all types that use a provider?

Cheers
Gavin

[1] https://travis-ci.org/fatmcgav/puppet-glassfish/jobs/24564901
[2] https://travis-ci.org/fatmcgav/puppet-glassfish/jobs/24564908

Gavin Williams

unread,
May 7, 2014, 12:30:16 PM5/7/14
to puppet...@googlegroups.com
Right, after dropping into #Puppet-dev and hashing the issue out with Andy (zaphod42), have managed to find a fix...

The failures I was seeing on 1.9.3 were due to a difference in how asadmin.rb:6 was being interpreted between Ruby 1.8.7 and 1.9.3, as Andy outlined:
17:11 <+zaphod42> fatmcgav: figured it out
17:12 <+zaphod42> 1.8.7 and 1.9.3 deal with that line differently
17:12 <+zaphod42> on 1.8.7 defined?@resource[:dashost] && !@resource[:dashost].nil? turns into nil
17:12 <+zaphod42> on 1.9.3 defined?@resource[:dashost] && !@resource[:dashost].nil? turns into "expression"

He also suggested a more elegant way of handling this scenario, by using '@resource.parameters.include?' [1] to check if the param is present.
So a quick tweak, and it appears to be working as expected : D

So again, a massive thanks to Andy for persisting.

Regards
Gavin

[1] https://github.com/fatmcgav/puppet-glassfish/commit/ea702df4ec111c81b55a4b927191673faddbe270
Reply all
Reply to author
Forward
0 new messages