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

bpo-32199: uuid.getnode() now returns the MAC address on Android #4696

Merged
merged 3 commits into from
Dec 7, 2017
Merged

bpo-32199: uuid.getnode() now returns the MAC address on Android #4696

merged 3 commits into from
Dec 7, 2017

Conversation

xdegaye
Copy link
Contributor

@xdegaye xdegaye commented Dec 4, 2017

@xdegaye xdegaye added the type-bug An unexpected behavior, bug, or error label Dec 4, 2017
Lib/uuid.py Outdated
@@ -401,7 +401,8 @@ def _ifconfig_getnode():
def _ip_getnode():
"""Get the hardware address on Unix by running ip."""
# This works on Linux with iproute2.
mac = _find_mac('ip', 'link list', [b'link/ether'], lambda i: i+1)
arg = 'link' if hasattr(sys, 'getandroidapilevel') else 'link list'
Copy link
Member

Choose a reason for hiding this comment

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

Can you please leave a comment explaining why link must be used instead of link list on Android? Even a URL would help avoid having to search for the underlying difference.

Also, I guess the new sys.getandroidapilevel attribute in 3.7 is the most reliable way to check for the Android platform? E.g. why is sys.platform not good enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ip link help command on linux and the ip man page on linux as well do not mention any list parameter for this command, so the question should be reversed, why list is being used here ? Probably some other platform using another version of iproute.

sys.platform does not list Android.

Copy link
Member

Choose a reason for hiding this comment

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

On my Debian machine, I get the same output for both ip link and ip link list. If it's there to support an older CLI API for the ip link command, then why not just use that unconditionally? We'd have to watch the buildbots to see if any supported platform breaks. Simpler and less inscrutable code is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_ip_getnode was added in issue 22902.

The ip command is part of the ìproute2 collection of network tools whose documentation states that the syntax is:

    ip [ OPTIONS ] OBJECT [ COMMAND [ ARGUMENTS ]]

and that If no command is given a default command is assumed. The default command is usually show (list) but if the objects of the class cannot be listed then the default is to print out the command syntax help.

So it seems you are right and I will change the code to use only ip link in all cases.

Copy link
Member

@serhiy-storchaka serhiy-storchaka Dec 4, 2017

Choose a reason for hiding this comment

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

If this works on OS X, it LGTM.

Copy link
Member

Choose a reason for hiding this comment

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

This looks as unneeded complication to me. All modern Linux distributions have either ifconfig, ip or arp (or all of them). If there was a version of ip that didn't support ip link, I suppose it was many years ago (you can check the sources of iproute2 to be sure: https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git).

Copy link
Member

Choose a reason for hiding this comment

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

I still think it's a mildly bad idea to just swallow the getter errors with no notification. @xdegaye maybe you can propose an optional API to turn on debugging here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@serhiy-storchaka packages such as iproute2 may be patched by a linux distribution and if they did not and we could just check for the source of iproute2, then there would not be any issue in the first place as Android (a linux distribution in this context) would have a functional ip link list then.

One may say, as it has been done before for the same kind of problem let us just use 'ip link' for now, because it is such an obvious change, and see if any one complain. But strictly speaking we cannot, as here the behavioral change that could trigger a complaint is a change in a single bit in the value returned by getnode().

@warsaw I agree it would be better to try to improve this with some kind of notification, maybe in another issue and we can leave this one pending meanwhile ?

Copy link
Member

@warsaw warsaw Dec 5, 2017

Choose a reason for hiding this comment

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

@xdegaye I'd personally prefer addressing the notification issue first so that we can get a sense of what's actually happening on user's machines, then come back and see if we can just use ip link for everything. OTOH, I think it's probably safe for the platforms we care about, and won't cause any behavior change in practice. But your change in this PR is admittedly the more conservative approach. I just don't like special casing Android here.

Here's another thought: what if you just added another getter that calls ip link list and placed that after one that calls ip link. Wouldn't that accomplish both goals? Then if ip link fails, we fall back to the old behavior, so nothing changes. It's uglier, but it doesn't special case for the Android platform, and eventually we can decide to remove ip link list altogether.

Copy link
Member

Choose a reason for hiding this comment

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

Let discuss the design on the tracker.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@@ -0,0 +1 @@
The getnode() ip getter now uses 'ip link'.
Copy link
Member

Choose a reason for hiding this comment

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

"instead of 'ip link list'"

@xdegaye
Copy link
Contributor Author

xdegaye commented Dec 7, 2017

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@warsaw: please review the changes made to this pull request.

@xdegaye xdegaye merged commit 961dbe0 into python:master Dec 7, 2017
@miss-islington
Copy link
Contributor

Thanks @xdegaye for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@xdegaye xdegaye deleted the bpo-32199 branch December 7, 2017 11:59
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 7, 2017
@bedevere-bot
Copy link

GH-4747 is a backport of this pull request to the 3.6 branch.

xdegaye pushed a commit that referenced this pull request Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants