Use a minimum of 1 thread per core for CPU total calculation
Description
In some LXD containers running with VT-x hardware virtualization, it
appears that threads per core is 0, resulting in a total number of
CPUs of 0. Add a test case and handle some quirks with the lscpu
output.
Related Issue
Closes https://github.com/chef/ohai/issues/1755
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Chore (non-breaking change that does not add functionality or fix an issue)
Checklist:
- [x] I have read the CONTRIBUTING document.
- [x] I have run the pre-merge tests locally and they pass.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] All commits have been signed-off for the Developer Certificate of Origin.
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
1 Code Smell
No Coverage information
21.4% Duplication
LGTM
Please update the description to show why the default cpu is configurable.
Please update the description to show why the default cpu is configurable.
@johnmccrae Could you elaborate? I don't quite understand.
https://github.com/chef/ohai/pull/1761 might be an alternative solution: if we get 0, give up and use /proc/cpuinfo.
Please update the description to show why the default cpu is configurable.
@johnmccrae Could you elaborate? I don't quite understand.
@stanhu - Your change to do max[val, 1] is obviously correct. But you changed all the tests to stop checking for CPU 0 and start looking for some configurable "default_cpu" - but your PR description doesn't mention this change at all or why you are making it.
Ping @stanhu ?
@jaymzh Oh, right, thanks. It's been a while since I worked on this so I forgot that I did that. Updated. 😄
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
1 Code Smell
No Coverage information
21.4% Duplication
Thanks. Looks good, minus the lint failures. Can you run the rubocop autocorrecting rake task? @tpowell-progress is trying to find the exact command.
I manually corrected them. Running git diff --name-only main | xargs bundle exec rubocop -a corrected almost the entire file. 😄
Thanks!