-
Notifications
You must be signed in to change notification settings - Fork 452
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
Ohai merges duplicate plugins in very dangerous ways #1212
Comments
@jaymzh what's the ideal/expected behavior for you? One plugin always wins? An exception is raised for duplicate plugins? |
@btm I'd expect the behavior to be the same as the Currently that means first one wins (with a warning on subsequent ones), but I don't really care if it's first one wins or last one wins, I can order my plugin list accordingly. It seems like last one should win since core plugins come first, but that would be a very significant change and not a bugfix, so we probably don't want to do that without an RFC. But making sure the whole plugin follows the same rules as |
It looks like someone tried to make multiple collect_data statements for the same platform fail with an exception: https:/chef/ohai/blob/master/lib/ohai/dsl/plugin/versionvii.rb#L111-L115 Its possible that gets raised only if it is declared in the same file, and not across two different files? Whatever the fix, probably need to be careful about explicitly allowing different implementations for e.g. linux and solaris in different files to still work. |
That error is raised - and like any other error in Ohai - is caught, printed, and then it carry's on. So we have several of those. ;) But it shouldn't have eval'd it in the same namespace to determine that, IMO. However, It does because that collect_data block could be for a different platform. |
ah, so that's the problem. we're monkeypatching the class, so last-writer-wins for methods, but the last-writer throws an exception there instead of wiring up its collect_data method. the intent seems to be that it should throw and fail, but that's difficult with ohai's never-fail "philosophy" |
@jaymzh how are you specifying multiple ohai plugin directories in your repro case? |
I put those two dirs in |
If we happen to load a plugin with the same name twice, we refuse to run #collect_data but we still load the rest of the plugin, which means you get #collect_data from the first plugin and rest of the plugin from the last plugin. This makes it so you get #collect_data from the last plugin as well. I don't know how to use the logger from the class method so I fell back to `Ohai::Log`. Happy to fix that if someone knows the magic. Fixes chef#1212 Signed-off-by: Bryan McLellan <[email protected]>
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
It turns out that Ohai
eval
s every plugin in every directory... and so all methods inside ofOhai.plugin
blocks are evaluated... however thecollect_data
blocks are not - if a second one is hit on the same platform, it will not evaluate it, it runs on the first one it hits. This means the methods from the last plugin seen win, but the collector code from the first plugin seen wins.This means that you can into a problem where if you have two versions of the same module in different plugin paths, the first path will be run but call the methods from the second plugin.
So if you have
/root/ohai_repro/test.rb
with:So if you have
/root/ohai_repro2/test.rb
with:Your output will be the very unexpected:
Woah!! That's pretty weird.
Ohai Version
13.8.0
works on 12 too.
Platform Version
CentOS 7.5
The text was updated successfully, but these errors were encountered: