You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "rohityadavcloud (via GitHub)" <gi...@apache.org> on 2024/04/26 09:47:34 UTC
[PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
rohityadavcloud opened a new pull request, #8988:
URL: https://github.com/apache/cloudstack/pull/8988
Cleanup old mac address handling code to use JDK11 lib instead of hacks. Also really strange to see some basic string parsing code was written by hand, replaced with Long.parseValue(str, 16) to convert hex string to long.
Fixes #8174
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [x] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] build/CI
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [x] Major
- [ ] Minor
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [x] Major
- [ ] Minor
- [ ] Trivial
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud merged PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2079038407
@rohityadavcloud a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1581384065
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
+ StringBuilder macAddressBuilder = new StringBuilder();
+ for (byte b : mac) {
+ macAddressBuilder.append(String.format("%02X", b));
+ }
+ macAddress = macAddressBuilder.toString();
Review Comment:
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580918983
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
Review Comment:
One concern though, cc @weizhouapache if you know - do people run CloudStack in containers, then what nice are seen within; for such users could this cause issues (if we ignore virtual nics?)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2081157002
<b>[SF] Trillian test result (tid-10064)</b>
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 47052 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr8988-t10064-kvm-centos7.zip
Smoke tests completed. 128 look OK, 2 have errors, 0 did not run
Only failed and skipped tests results shown below:
Test | Result | Time (s) | Test File
--- | --- | --- | ---
test_01_events_resource | `Error` | 405.75 | test_events_resource.py
test_01_redundant_vpc_site2site_vpn | `Failure` | 406.81 | test_vpc_vpn.py
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2080369490
Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 9451
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2079121905
## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/8988?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `54.54545%` with `10 lines` in your changes are missing coverage. Please review.
> Project coverage is 15.66%. Comparing base [(`e409c6d`)](https://app.codecov.io/gh/apache/cloudstack/commit/e409c6d870a49762fb4e730ad118a3a836715cc5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`e68f7ee`)](https://app.codecov.io/gh/apache/cloudstack/pull/8988?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
| [Files](https://app.codecov.io/gh/apache/cloudstack/pull/8988?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [.../src/main/java/com/cloud/utils/net/MacAddress.java](https://app.codecov.io/gh/apache/cloudstack/pull/8988?src=pr&el=tree&filepath=utils%2Fsrc%2Fmain%2Fjava%2Fcom%2Fcloud%2Futils%2Fnet%2FMacAddress.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dXRpbHMvc3JjL21haW4vamF2YS9jb20vY2xvdWQvdXRpbHMvbmV0L01hY0FkZHJlc3MuamF2YQ==) | 54.54% | [6 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/cloudstack/pull/8988?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 4.19 #8988 +/- ##
============================================
+ Coverage 14.96% 15.66% +0.69%
+ Complexity 10995 10982 -13
============================================
Files 5373 5010 -363
Lines 468989 439725 -29264
Branches 61009 53693 -7316
============================================
- Hits 70191 68880 -1311
+ Misses 391019 363222 -27797
+ Partials 7779 7623 -156
```
| [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/8988/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/8988/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/8988/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `15.66% <54.54%> (-0.01%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/cloudstack/pull/8988?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "DaanHoogland (via GitHub)" <gi...@apache.org>.
DaanHoogland commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580831321
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
Review Comment:
sh-/could this test be a method for reuse and readability?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2079035096
@blueorangutan package
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2079187443
Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 9441
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2079236483
@blueorangutan test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1581727099
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
Review Comment:
Found this to be a non-issue. Interfaces inside containers were found to have non-virtual Nic names.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2080375134
@blueorangutan test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580998790
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
+ StringBuilder macAddressBuilder = new StringBuilder();
+ for (byte b : mac) {
+ macAddressBuilder.append(String.format("%02X", b));
+ }
+ macAddress = macAddressBuilder.toString();
+ }
+ }
+ } catch (SocketException ignore) {
Review Comment:
want to log exception here, in case any issues while fetching network information?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580982750
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
Review Comment:
```suggestion
final byte[] mac = network.getHardwareAddress();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1581725346
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
+ StringBuilder macAddressBuilder = new StringBuilder();
+ for (byte b : mac) {
+ macAddressBuilder.append(String.format("%02X", b));
+ }
+ macAddress = macAddressBuilder.toString();
+ }
+ }
+ } catch (SocketException ignore) {
Review Comment:
Logging wouldn't be necessary here, we ignore it anyway.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2080352750
@rohityadavcloud a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2080375440
@rohityadavcloud a [SL] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580917355
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
Review Comment:
I'm not sure that's really necessary; unless if you know there's a utility to scan and find if string starts with on an array of provided substrings?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580918983
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
Review Comment:
One concern though, cc @weizhouapache if you know - do people run CloudStack in containers - if so, could this cause issues (if we ignore virtual nics?)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2082119686
code lgtm
deployed it on an existing environment, there is no new management server added to `mshost` table
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2079032577
@blueorangutan package
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "rohityadavcloud (via GitHub)" <gi...@apache.org>.
rohityadavcloud commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2080352554
Thanks @weizhouapache @sureshanaparti I've addressed the review comments.
@blueorangutan package
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#issuecomment-2079265875
@rohityadavcloud
I copied the code and run it locally
- on mgmt server (with only 1 interface), the `macAddressInLong` value is same as previous legacy code. that is good
```
macAddressInLong = 32989023043991
mysql> select msid from mshost where state='Up';
+----------------+
| msid |
+----------------+
| 32989023043991 |
+----------------+
1 row in set (0.00 sec)
```
- run it on kvm host
```
network.getName() = vnet125
network.getName() = vnet150
network.getName() = vnet110
network.getName() = vnet127
network.getName() = vnet111
network.getName() = vnet124
network.getName() = vnet148
network.getName() = vnet78
network.getName() = vnet145
network.getName() = vnet118
network.getName() = vnet122
network.getName() = vnet116
network.getName() = vnet147
network.getName() = vnet117
network.getName() = vnet123
network.getName() = vnet80
network.getName() = vnet79
network.getName() = vnet146
network.getName() = vnet149
network.getName() = vnet112
network.getName() = vnet126
network.getName() = vnet131
network.getName() = cloud0
network.getName() = cloudbr1
network.getName() = cloudbr0
network.getName() = lo
```
my suggestion is
- reverse the elements in the return of `NetworkInterface.getNetworkInterfaces`
- ignore `lo` interface, so the code will get the mac address of the first non-loopback nic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] utils: cleanup MacAddress and MacAddressTest [cloudstack]
Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580995715
##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
static {
String macAddress = null;
- Process p = null;
- BufferedReader in = null;
-
try {
- String osname = System.getProperty("os.name");
-
- if (osname.startsWith("Windows")) {
- p = Runtime.getRuntime().exec(new String[] {"ipconfig", "/all"}, null);
- } else if (osname.startsWith("Solaris") || osname.startsWith("SunOS")) {
- // Solaris code must appear before the generic code
- String hostName = MacAddress.getFirstLineOfCommand(new String[] {"uname", "-n"});
- if (hostName != null) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/arp", hostName}, null);
- }
- } else if (new File("/usr/sbin/lanscan").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/usr/sbin/lanscan"}, null);
- } else if (new File("/sbin/ifconfig").exists()) {
- p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", "-a"}, null);
- }
-
- if (p != null) {
- in = new BufferedReader(new InputStreamReader(p.getInputStream()), 128);
- String l = null;
- while ((l = in.readLine()) != null) {
- macAddress = MacAddress.parse(l);
- if (macAddress != null) {
- short parsedShortMacAddress = MacAddress.parseShort(macAddress);
- if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
- break;
- }
- macAddress = null;
- }
- }
-
- } catch (SecurityException ex) {
- s_logger.info("[ignored] security exception in static initializer of MacAddress", ex);
- } catch (IOException ex) {
- s_logger.info("[ignored] io exception in static initializer of MacAddress");
- } finally {
- if (p != null) {
- closeAutoCloseable(in, "closing init process input stream");
- closeAutoCloseable(p.getErrorStream(), "closing init process error output stream");
- closeAutoCloseable(p.getOutputStream(), "closing init process std output stream");
- p.destroy();
- }
+ Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+ while (networkInterfaces.hasMoreElements()) {
+ NetworkInterface network = networkInterfaces.nextElement();
+ final byte [] mac = network.getHardwareAddress();
+ if (mac != null && !network.isVirtual() &&
+ !network.getName().startsWith("br-") &&
+ !network.getName().startsWith("veth") &&
+ !network.getName().startsWith("vnet")) {
+ StringBuilder macAddressBuilder = new StringBuilder();
+ for (byte b : mac) {
+ macAddressBuilder.append(String.format("%02X", b));
+ }
+ macAddress = macAddressBuilder.toString();
Review Comment:
break loop here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org