Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean properties and misc #346

Merged
merged 7 commits into from
Apr 24, 2015
Merged

Conversation

cataphract
Copy link
Contributor

As mentioned in 05999a6#commitcomment-10864529 , implement the boolean properties through a superclass.

Unfortunately, Puppet::Parameter::Boolean was only introduced in 3.3, so we must implement our own superclass. In the process, fixed some other issues.

puppetlabs_spec_helper-0.10.2 not compatible with puppet 4.0
Not passing the arguments to the super constructors has nasty side
effects, including the default values specified for the parameters being
ignored.
The :boolean option is ignored for newproperty. It only has an effect
with newparam, where is creates a method called <parameter name>? in the
type class.
@@ -30,7 +30,7 @@ end
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
gem 'puppet', '< 4.0.0', :require => false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puppetlabs_spec_helper-0.10.2 seems to be incompatible with puppet 4.0. I get this error:

/usr/bin/ruby1.9.1 -S rspec spec/classes/sensu_api_spec.rb spec/classes/sensu_client_spec.rb spec/classes/sensu_init_spec.rb spec/classes/sensu_package_spec.rb spec/classes/sensu_rabbitmq_spec.rb spec/classes/sensu_redis_spec.rb spec/classes/sensu_server_spec.rb spec/defines/sensu_check_spec.rb spec/defines/sensu_extension_spec.rb spec/defines/sensu_filter_spec.rb spec/defines/sensu_handler_spec.rb spec/defines/sensu_plugin_spec.rb spec/defines/sensu_subscription_spec.rb spec/unit/puppet_x_sensu_totype_spec.rb spec/unit/sensu_config_spec.rb --color
/home/glopes/.gems/gems/puppetlabs_spec_helper-0.10.2/lib/puppetlabs_spec_helper/module_spec_helper.rb:23:in `block in <top (required)>': undefined method `environmentpath=' for #<RSpec::Core::Configuration:0x000000012d2ae8> (NoMethodError)
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core.rb:154:in `configure'
    from /home/glopes/.gems/gems/puppetlabs_spec_helper-0.10.2/lib/puppetlabs_spec_helper/module_spec_helper.rb:22:in `<top (required)>'
    from /home/glopes/repos/sensu-puppet/spec/spec_helper.rb:2:in `require'
    from /home/glopes/repos/sensu-puppet/spec/spec_helper.rb:2:in `<top (required)>'
    from /home/glopes/repos/sensu-puppet/spec/classes/sensu_api_spec.rb:1:in `require'
    from /home/glopes/repos/sensu-puppet/spec/classes/sensu_api_spec.rb:1:in `<top (required)>'
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load'
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `block in load_spec_files'
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `each'
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in `load_spec_files'
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in `run'
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run'
    from /var/lib/gems/1.9.1/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the odd thing is that that line is c.environmentpath = spec_path if Puppet.version.to_f >= 4.0, so it's there specifically for puppet 4.

@jlambert121
Copy link
Contributor

I've been re-evaluating what versions of puppet I support with my modules and was thinking about this module as well. The release of 4.0 makes me think we should drop all 2.7 support, and I believe dropping everything pre-3.3 still keeps one version of PE older than current support. Not to muddy the waters on this, but I'm wondering if it makes sense to just use Puppet::Parameter::Boolean and make this module depend on >= 3.3.

@jamtur01
Copy link
Contributor

I guess I am not adverse to that - we'll go a major release to go with it?

@jlambert121
Copy link
Contributor

That would probably make sense if we remove older supported versions. If there's other things we want to change with that we should probably have that discussion outside this PR.

@jamtur01
Copy link
Contributor

Yeah I don't have anything else - unless you do - there's probably a few types/providers folks would like to replace but I don't have any bandwidth.

@cataphract
Copy link
Contributor Author

So would you prefer a pull request using Puppet::Property::Boolean for puppet >= 3.3.0?

@jamtur01
Copy link
Contributor

Yes please!

@cataphract
Copy link
Contributor Author

Done. I also added another commit for using the full GPG fingerprint for the apt repository, as this generates a warning in the latest puppetlabs-apt (I can submit a separate PR if you prefer).

As to the default, my choice was to only give defaults where create on
the provider did not should whether the should value was null.
Missing caller the port= setter on sensu_client_config's provider's
create method. When the resource is first created (more precisely, when
the ensure property is out of sync) the only synched property is ensure,
which delegates to create on the provider. Because writing to the json
object of the provider that serves as the data for the json object is
only done in the provider setters, we must call them explicitly from
create.
This avoids a warning with recent versions of puppetlabs-apt, which warn
you that using a shortened fingerprint is insecure.
jamtur01 added a commit that referenced this pull request Apr 24, 2015
@jamtur01 jamtur01 merged commit ecc23b4 into sensu:master Apr 24, 2015
@jamtur01
Copy link
Contributor

Thanks so much for this - excellent refactor!

@cataphract
Copy link
Contributor Author

Unfortunately, there is a problem. Once a property is true, you cannot change it back to false. This is because on ResourceHarness::sync_if_needed() the property value is not even checked to be in sync of if the should value is false:

if param.should && !param.safe_insync?(current_value)

Arguable this should test nil? (property unmanaged) but things are what they are. I'll prepare a fix later this week (probably it will have no normalize to :true/:false), but in the meantime you may want to revert ec9fa40.

jamtur01 added a commit that referenced this pull request May 10, 2015
Fix problem introduced in #346 and simplification of create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants