-
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
Add hardware plugin for ohai on darwin #839
Conversation
Hi. I am an automated pull request bot named Curry. There are commits in this pull request whose authors are not yet authorized to contribute to Chef Software, Inc. projects or are using a non-GitHub verified email address. To become authorized to contribute, you will need to sign the Contributor License Agreement (CLA) as an individual or on behalf of your company. You can read more on Chef's blog. GitHub Users Who Are Not Authorized To ContributeThe following GitHub users do not appear to have signed a CLA: |
Revisions planned..... |
next | ||
end | ||
|
||
hardware Mash.new |
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.
We shouldn't create this if hardware already exists. We check first around ohai so we don't globber other plugins that use the same namespace.
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.
Would it be better to make it a different namespace? I plan on adding similar data for Windows and Linux as well (to be used mainly for client machines).
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.
hardware is a good high level namespace. The subkeys seem to be pretty clean here. If someone later on wanted to add something like HP iLO on the Linux side there'd be room and it wouldn't be horribly cluttered.
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've looked in the code base and poked the Ohai object. What is the best way to look for an existing namespace? I assume I can return at the beginning of the collect_data function before anything happens.
Works btw. Also I'm going to need a new battery soon "hardware": {
"SMC_version_system": "2.19f12",
"boot_rom_version": "MBP112.0138.B17",
"cpu_type": "Intel Core i7",
"current_processor_speed": "2.8 GHz",
"l2_cache_core": "256 KB",
"l3_cache": "6 MB",
"machine_model": "MacBookPro11,3",
"machine_name": "MacBook Pro",
"number_processors": 4,
"packages": 1,
"physical_memory": "16 GB",
"platform_UUID": "08CD3042-4DB0-550F-A936-0BB809D15B7E",
"serial_number": "C02N63D0G3QP",
"operating_system": "Mac OS X",
"operating_system_version": "10.11.5",
"build_version": "15F34",
"architecture": "x86_64",
"storage": [
{
"name": "Macintosh HD",
"bsd_name": "disk1",
"capacity": 499046809600,
"drive_type": "ssd",
"smart_status": "Verified",
"partitions": 1
}
],
"battery": {
"current_capacity": 6872,
"max_capacity": 7728,
"fully_charged": false,
"is_charging": true,
"charge_cycle_count": 474,
"health": "Good",
"serial": "D864315Y5LRF9CPAD",
"remaining": 88
}
}, |
I'm not seeing any other Ohai plugins that check the namespace before using it (unless I am missing the few that do). What is the best way to do this? |
This sort of thing ohai/lib/ohai/plugins/freebsd/network.rb Line 24 in 80c91e7
|
Aha! I didn't realize all the Ohai data wasn't scoped in any way. I kept trying ohai['cpu'], node['cpu'], etc. I knew CPU existed, but wasn't sure where on the namespace. I'll do this check for hardware now that I know how its scoped. Thanks! |
Ready for feedback now. Is this sufficient? Should I get started on the specs? I'm not sure why the CI is failing....it looked like a bundle install error. I'll check it out again after this run. |
I'll take a look at what's there now. CI is failing due to rack 2.0.1 getting released. We're waiting on a new chef gem to fix that. |
if sp_std.exitstatus == 0 | ||
sp_hash = Plist.parse_xml(sp_std.stdout) | ||
else | ||
Ohai::Log.debug("system_profiler failed to run") |
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.
As a note, the shell_out method has some debugging which may duplicate this message: https://github.com/chef/ohai/blob/master/lib/ohai/mixin/command.rb#L39. It's your decision.
Rebased and changed a few things based on feedback. |
It looks like you have some ChefStyle* offenses. You can fix most of these automatically by running *Original message cited RuboCop. It's actually ChefStyle we're adhering to. |
If this looks good now, I can start on the rspec. Let me know! |
Go forth and write tests (though there's really no need to wait ;) ). |
reminder, this must be merged by @jaymzh . I'll get on the rspecs. |
There is a fail on the build, but it is a chefstyle error that I am uncertain on how to fix. when I add the 2 space indent, it causes the output blocks to get messed up ;( |
@natewalck You don't have to indent the entire string block, just the lines beginning with module HardwareSystemProfilerOutput
Hardware = <<hardware_output
<?xml version="1.0" encoding="UTF-8"?>
# ...
hardware_output
# ...
end If you don't like the way that looks, which is a fine choice, you may want to explore copying the command outputs to |
) | ||
end | ||
|
||
it "should parse hardware data correctly" do |
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.
(Minor style comment) In alignment with BetterSpecs we prefer to not use "should" in test descriptions.
I guess I don't understand why this is failing. It runs great on my own machine(OS X), but since it is failing on *nix, it seems like the shell_out mocks are not working quite as I expect them to. I threw some pry binds in and I confirmed plugin contains the expected (mocked) data. Any idea where this could be breaking down? I basically copied the allow commands from system_profiler_spec, which isn't failing. |
Ohai only runs the default and operating system-specific plugins. The tests pass on your machine because Ohai detects OS X ( You can trick Ohai into running this plugin during testing by adding this line to your allow(plugin).to receive(:collect_os).and_return(:darwin) |
That did it! Let me know if there are any other changes. If not, I'll squash and tag Phild. |
This looks great. Squash and summon Phil. |
@jaymzh, I choose you! (please don't kill me...) |
@mcquin Thanks a ton for working through this diff with me! It was my first PR for ohai, which was a little different to test than providers, etc. Should be more complete for the initial PR next time. |
👍 |
Sorry for the delay. Was in TX. :) |
This adds information about OS X that is basically unusable in the current system_profiler ohai plugin. I made it in such a way that more information could always be parsed out and used.
Apple's formatting for the system_profiler info is really terrible, so even with XML output, it required quite a bit of massaging.
I'm with Facebook and this must be merged by @jaymzh
P.S. I plan on doing rspec tests, but I wanted to make sure I was on the right track before writing them.