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

Check for Virtual Machine #704

Merged
merged 10 commits into from
Dec 4, 2018
Merged

Check for Virtual Machine #704

merged 10 commits into from
Dec 4, 2018

Conversation

haidong
Copy link
Contributor

@haidong haidong commented Dec 3, 2018

Followed instructions here #648 (comment) . I also made a small change to SystemInfoTest.java for a good test. I hope that's OK. If not, I can roll that change back.

In addition to the code provided, I added a check using manufacturer and model for Microsoft Hyper-V VMs. I noticed that the Mac address and model check isn't enough for a VM I use for work, but manufacture and model check took care of that.

Thanks and let me know your comments/suggestions!

Get the latest from upstream, merge, and test, before I send a pull
request
Manufacturer and model check for Microsoft. Renamed the Map so its
clearly states we are using the OUI portion.
@codecov-io
Copy link

codecov-io commented Dec 3, 2018

Codecov Report

Merging #704 into master will decrease coverage by 0.04%.
The diff coverage is 80%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #704      +/-   ##
============================================
- Coverage     82.56%   82.52%   -0.05%     
  Complexity      198      198              
============================================
  Files            28       28              
  Lines          1503     1528      +25     
  Branches        220      225       +5     
============================================
+ Hits           1241     1261      +20     
- Misses          126      128       +2     
- Partials        136      139       +3
Impacted Files Coverage Δ Complexity Δ
oshi-core/src/main/java/oshi/util/Util.java 86.27% <80%> (-6.04%) 0 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8396f6f...ec5617d. Read the comment docs.

@coveralls
Copy link

coveralls commented Dec 3, 2018

Coverage Status

Coverage decreased (-0.04%) to 90.445% when pulling ec5617d on haidong:master into 8396f6f on oshi:master.

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Looks great! A few minor points. As noted, please try to replace tabs with 4 spaces; and change the return type to simply the VM name or empty string.

Also can you just write a UtilTest separate from SystemInfoTest? Check the return string is non-null.

String mac = nif.getMacaddr().substring(0, 8).toUpperCase();
if (vmMacAddressOUI.containsKey(mac)) {
isvm = true;
return "On a VM: " + vmMacAddressOUI.get(mac);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding the words "On a VM" let's just return the VM string here.

if (manufacturer.equals("Microsoft Corporation")
&& model.equals("Virtual Machine")) {
isvm = true;
return "On a VM: Microsoft Hyper-V";
Copy link
Member

Choose a reason for hiding this comment

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

Similarly just return "Microsoft Hyper-V"

for (String vm : vmModelArray) {
if (model.contains(vm)) {
isvm = true;
return "On a VM: " + vm;
Copy link
Member

Choose a reason for hiding this comment

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

Return just vm

return "On a VM: Microsoft Hyper-V";
}
}
return "Couldn't detect VM";
Copy link
Member

Choose a reason for hiding this comment

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

Return empty string if no vm. Update javadoc comment to explain this return value.

System.out.println("virtualization: " + Util.identifyVM());
}

private static void printComputerSystem(final ComputerSystem computerSystem) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor point, you've got tabs in your editor rather than spaces. This causes unneeded whitespace changes in the diffs. Can you set your editor to use 4 spaces rather than a tab? If not, I can easily reformat and commit to your branch, but if it's an easy switch it'll make it easier.

+ String.format("%08x", processorSerialNumber.hashCode()) + delimiter
+ String.format("%08x", processorIdentifier.hashCode()) + delimiter + processors;
}
private static final Logger LOG = LoggerFactory.getLogger(Util.class);
Copy link
Member

Choose a reason for hiding this comment

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

Nearly the entire class shows as a change in the diff because of the tabs/spaces... makes it harder to review! :)

@haidong
Copy link
Contributor Author

haidong commented Dec 3, 2018

Thanks @dbwiddis for the feedback. Sorry about the tab thing, it's a good reminder.

I've made all changes you mentioned. Do I need to do a brand new PR? Or will this one here will continue automatically?

@haidong
Copy link
Contributor Author

haidong commented Dec 3, 2018

Never mind. I know the answers to my 2 questions above. Let me know if you have more feedback. Thanks!

@dbwiddis
Copy link
Member

dbwiddis commented Dec 3, 2018

You're good, pushing new changes to this branch automatically update the PR.

@dbwiddis
Copy link
Member

dbwiddis commented Dec 3, 2018

Looks good, I'll make some minor tweaks in the morning and merge it!

@haidong
Copy link
Contributor Author

haidong commented Dec 3, 2018

Wonderful, thanks @dbwiddis It has been pretty interesting and good learning experience. I appreciate your effort very much! I'd be happy to help out and do it again.

@dbwiddis dbwiddis merged commit 74dfa96 into oshi:master Dec 4, 2018
@dbwiddis
Copy link
Member

dbwiddis commented Dec 4, 2018

Thanks for your contribution to open source! Hope to see you around more!

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.

None yet

4 participants