-
Notifications
You must be signed in to change notification settings - Fork 33
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
Rewrite ohai_plugin.rb to reflect new ohai cookbook version #23
Conversation
ping @zuazo |
Hi @ledgr, Thanks for the PR 😄 Please, could you fix the RuboCop offenses and the Unit tests?
Also, please avoid updating the cookbook version in the metadata. If you fix these details, I'm going to merge it and make a release. Thanks again! And sorry for the delay in my review. |
@@ -34,9 +34,6 @@ | |||
package "(#{type}) #{pkg}" do | |||
package_name pkg | |||
only_if { Dovecot::Conf.require?(type, node['dovecot']) } | |||
if type == 'core' || node['dovecot']['ohai_plugin']['build-options'] | |||
notifies :reload, 'ohai[reload_dovecot]', :immediately | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohai cookbook does this now using ohai_plugin resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't need to notify ohai_plugin[dovecot]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is done by ohai_plugin
here: https://github.com/chef-cookbooks/ohai/blob/master/resources/plugin.rb#L83
here: https://github.com/chef-cookbooks/ohai/blob/master/resources/plugin.rb#L90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong but I think that this notification you are referring to only replaces the notification of the old ohai template resource. But not the notification here.
Keep in mind that this change is breaking the integration tests:
$ kitchen test default-debian-7
[...]
Recipe: dovecot_test::default
* ruby_block[ohai plugin tests] action run
================================================================================
Error executing action `run` on resource 'ruby_block[ohai plugin tests]'
================================================================================
RuntimeError
------------
Ohai plugin cannot get dovecot version.
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/dovecot_test/recipes/default.rb:27:in `block (2 levels) in from_file'
/tmp/kitchen/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:41:in `run_action'
Resource Declaration:
---------------------
# In /tmp/kitchen/cache/cookbooks/dovecot_test/recipes/default.rb
24: ruby_block 'ohai plugin tests' do
25: block do
26: unless node['dovecot']['version'].is_a?(String)
27: raise 'Ohai plugin cannot get dovecot version.'
28: end
29: unless node['dovecot']['build-options'].is_a?(Hash) &&
30: !node['dovecot']['build-options'].empty?
31: raise 'Ohai plugin cannot get dovecot build options.'
32: end
33: end
34: end
35:
Compiled Resource:
------------------
# Declared in /tmp/kitchen/cache/cookbooks/dovecot_test/recipes/default.rb:24:in `from_file'
ruby_block("ohai plugin tests") do
action [:run]
retries 0
retry_delay 2
default_guard_interpreter :default
block_name "ohai plugin tests"
declared_type :ruby_block
cookbook_name "dovecot_test"
recipe_name "default"
block #<Proc:0x000000034410d0@/tmp/kitchen/cache/cookbooks/dovecot_test/recipes/default.rb:25>
end
So, we still need to notify the ohai plugin to reload here.
The problem maybe is that we cannot notify the internal ohai[dovecot]
resource and the ohai_plugin
resource has no :reload
action defined. A possible solution would be to add a dummy ohai[dovecot]
resource:
# recipes/ohai_plugin.rb
# dummy resource to be able to notify reload action to the ohai plugin
ohai 'dovecot' do
action :nothing
end
# recipes/from_package.rb
package "(#{type}) #{pkg}" do
package_name pkg
only_if { Dovecot::Conf.require?(type, node['dovecot']) }
if type == 'core' || node['dovecot']['ohai_plugin']['build-options']
notifies :reload, 'ohai[dovecot]', :immediately
end
end # package
Some integration tests also need to be updated:
-----> Verifying <default-debian-7>...
Preparing files for transfer
Suite path directory /tmp/verifier/suites does not exist, skipping.
Transferring files to <default-debian-7>
-----> Running bats test suite
✗ ohai gets dovecot version
(in test file /tmp/verifier/suites/bats/ohai.bats, line 5)
`ohai -d /etc/chef/ohai_plugins | tr -d $'\n' | grep -q '"dovecot":\s*{\s*"version"'' failed
[2016-07-20T08:22:29+00:00] WARN: The plugin path /etc/chef/ohai_plugins does not exist. Skipping...
✗ ohai prints nothing to stderr
(in test file /tmp/verifier/suites/bats/ohai.bats, line 10)
`[ -z "`ohai -d /etc/chef/ohai_plugins 2>&1 > /dev/null`" ]' failed
5 tests, 2 failures
!!!!!! Command [/tmp/verifier/vendor/bats/bin/bats /tmp/verifier/suites/bats] exit code was 1
You can see the full output in travis. Also, see TESTING if you need help with the tests.
Updated. I have dropped few tests, hope not too much. @zuazo |
it 'dovecot plugin installation notifies ohai reload' do | ||
resource = chef_run.template('/etc/chef/ohai_plugins/dovecot.rb') | ||
expect(resource).to notify('ohai[reload_dovecot]').to(:reload).immediately | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all these tests should be replaced by a create_ohai_plugin
matcher. Something like the following:
expect(chef_run).to create_ohai_plugin('dovecot')
OK, thanks @ledgr. I have reviewed your code. Please, read my comments. |
Also there are two unit test errors:
|
@zuazo: Should be good to go. I have replaced all tests with your proposed |
@ledgr first of all, thanks for your patience with this issue and excuse my "impertinence" but I think we still have to polish this a bit before merging it. Let me know if you need help with the tests. |
Thanks, @zuazo! |
Released in |
Ohai plugins should be installed ohai_plugin resource: https://github.com/chef-cookbooks/ohai/blob/master/resources/plugin.rb