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

uuid.getnode() MAC address on AIX #61495

Closed
aivarsk mannequin opened this issue Feb 25, 2013 · 27 comments
Closed

uuid.getnode() MAC address on AIX #61495

aivarsk mannequin opened this issue Feb 25, 2013 · 27 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@aivarsk
Copy link
Mannequin

aivarsk mannequin commented Feb 25, 2013

BPO 17293
Nosy @vstinner, @serhiy-storchaka, @koobs, @xnox
Files
  • aix_mac.patch
  • uuid_netstat_getnode.patch
  • uuid_netstat_getnode-3.5.patch
  • uuid_netstat_getnode-3.5_2.patch
  • uuid_netstat_getnode-3.4.patch
  • koobs-freebsd10-python27-build758.log
  • uuid_arp_getnode_freebsd.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-11-27.22:52:52.862>
    created_at = <Date 2013-02-25.07:29:08.128>
    labels = ['type-bug', 'library']
    title = 'uuid.getnode() MAC address on AIX'
    updated_at = <Date 2015-01-05.17:55:00.193>
    user = 'https://bugs.python.org/aivarsk'

    bugs.python.org fields:

    activity = <Date 2015-01-05.17:55:00.193>
    actor = 'xnox'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-11-27.22:52:52.862>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2013-02-25.07:29:08.128>
    creator = 'aivarsk'
    dependencies = []
    files = ['29229', '36768', '36993', '36998', '36999', '37193', '37196']
    hgrepos = []
    issue_num = 17293
    keywords = ['patch']
    message_count = 27.0
    messages = ['182925', '223390', '223693', '223705', '223724', '223738', '228108', '229151', '229153', '229154', '229160', '229162', '229163', '229172', '229831', '229832', '229833', '229866', '230784', '230817', '231148', '231176', '231225', '231242', '231264', '231494', '233473']
    nosy_count = 9.0
    nosy_names = ['vstinner', 'neologix', 'BreamoreBoy', 'python-dev', 'serhiy.storchaka', 'koobs', 'aivarsk', 'xnox', 'David.Edelsohn']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17293'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @aivarsk
    Copy link
    Mannequin Author

    aivarsk mannequin commented Feb 25, 2013

    uuid.getnode() on AIX returned random integer. This patch finds MAC in output of netstat -ia.
    Tested on AIX 5.2

    @aivarsk aivarsk mannequin added the stdlib Python modules in the Lib dir label Feb 25, 2013
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 17, 2014

    @aivars sorry about the delay in getting back to you.

    @BreamoreBoy BreamoreBoy mannequin added the type-bug An unexpected behavior, bug, or error label Jul 17, 2014
    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Jul 22, 2014

    Thanks for the patch, but I'm not even sure AIX is an officially supported platform, so I'm not sure what to do with this patch.

    @DavidEdelsohn
    Copy link
    Mannequin

    DavidEdelsohn mannequin commented Jul 22, 2014

    Huh? What does officially supported platform mean? CPython builds and runs on AIX.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Jul 23, 2014

    Huh? What does officially supported platform mean? CPython builds and runs on AIX.

    It means a platform for which we have regular contributors committed
    to support the port, and ideallly with a stable buildbot.

    We apparently have an unstable buildbot with mainy tests failing (and
    last time I checked it didn't even build IIRC))
    http://buildbot.python.org/all/builders/PPC64%20AIX%203.x/

    So it would be nice to have the full regtest pass (with skips if applicable).

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 23, 2014

    David is listed against AIX on the experts list https://docs.python.org/devguide/experts.html. That alone suggests to me that AIX is an officially supported platform.

    @serhiy-storchaka
    Copy link
    Member

    Thank you Aivars for your patch. I have verified and confirm that this method works on AIX and True64 UNIX (it should also work on IRIX, but I can't login in Snakebite's i6).

    Here is modified patch. MAC address is now searched only in column with the "Address" header. Added try/except around converting to int for the case if candidate word contains non-heximal digits. Synchronized _netstat_getnode() with current code of _find_mac and extracted common code in separate function. Split _ifconfig_getnode() into separate functions which use different commands: ifconfig, arp and lanscan.

    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 1, 2014
    @serhiy-storchaka
    Copy link
    Member

    If there are no objections, I'll commit the patch soon.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Oct 12, 2014

    My only comment would be to use subprocess instead of os.popen().

    @serhiy-storchaka
    Copy link
    Member

    This is different issue and can be applied only to 3.5.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Oct 12, 2014

    Why is that a different issue?
    The code you *add in this patch* uses os.popen, why not use subprocess instead?

    Furthermore, the code catches OSError when calling popen(), but
    popen() doesn't raise an exception.

    @vstinner
    Copy link
    Member

    FYI os.popen() now calls subprocess... So it's safe to call directly subprocess.

    @vstinner
    Copy link
    Member

    + cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, '-ia')

    It's safer to use the subprocess module instead of using a shell (see the recent Shellshock story) to change the environment variables and to redirect stderr. subprocess now has a convinient subprocess.DEVNULL. So it's something like:

    env = os.environ.copy()
    env['LC_ALL'] = 'C'
    process = subprocess.Popen([executable, '-ia'], stderr=subprocess.DEVNULL)
    ...

    @serhiy-storchaka
    Copy link
    Member

    The code you *add in this patch* uses os.popen, why not use subprocess instead?

    Added code is just modified copy of existing code.

    Furthermore, the code catches OSError when calling popen(), but
    popen() doesn't raise an exception.

    It can raise an exception in rare cases. The manual of pipe mentions this. The code of posix_popen() contains error handling.

    FYI os.popen() now calls subprocess...

    Not in 2.7.

    It's safer to use the subprocess module instead of using a shell (see the recent Shellshock story) to change the environment variables and to redirect stderr.

    May be, but this is different issue, which is not related to this issue. If os.popen should be replaced with subprocess, it should be done even without applying the patch of this issue. Please open new issue.

    However the recent Shellshock story affects only users of platforms which use bash or zsh as system shell (are there any?).

    subprocess now has a convinient subprocess.DEVNULL.

    Not in 2.7.

    @serhiy-storchaka
    Copy link
    Member

    Here is a patch for 3.5 which uses subprocess.Popen() (subprocess.Popen() used in _find_mac() since bpo-22637).

    @vstinner
    Copy link
    Member

    Here is a patch for 3.5 which uses subprocess.Popen() (subprocess.Popen() used in _find_mac() since bpo-22637).

    You probably forgot to attach the patch...

    @serhiy-storchaka
    Copy link
    Member

    You probably forgot to attach the patch...

    Indeed. :-(

    @serhiy-storchaka
    Copy link
    Member

    Here are updated patches for 3.5 (using subprocess) and 3.4 (using os.popen)
    which addresses Victor's comments.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 7, 2014

    New changeset e80cb046e764 by Serhiy Storchaka in branch '2.7':
    Issue bpo-17293: uuid.getnode() now determines MAC address on AIX using netstat.
    https://hg.python.org/cpython/rev/e80cb046e764

    New changeset ba4b31ed2952 by Serhiy Storchaka in branch '3.4':
    Issue bpo-17293: uuid.getnode() now determines MAC address on AIX using netstat.
    https://hg.python.org/cpython/rev/ba4b31ed2952

    New changeset 3e4f3cc4f1f9 by Serhiy Storchaka in branch 'default':
    Issue bpo-17293: uuid.getnode() now determines MAC address on AIX using netstat.
    https://hg.python.org/cpython/rev/3e4f3cc4f1f9

    @serhiy-storchaka
    Copy link
    Member

    Looks as this hasn't broke buildbots.

    Thank you Aivars for your patch. Thank you Natali and Victor for your suggestions and reviews.

    @koobs
    Copy link

    koobs commented Nov 14, 2014

    koobs-freebsd10 buildbot broken on all branches since:

    2.7: e80cb046e7641fb8a71dda8254d2e619cdd64480
    3.4: ba4b31ed2952b65ca447f57fbd6d540ebc4b749c
    3.x: 3e4f3cc4f1f9dbee8e0ed5df47f77baae2ad310c

    Full (2.7) log attached.

    ======================================================================
    ERROR: test_arp_getnode (test.test_uuid.TestUUID)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/usr/home/buildbot/python/2.7.koobs-freebsd10/build/Lib/test/test_uuid.py", line 312, in test_arp_getnode
        node = uuid._arp_getnode()
      File "/usr/home/buildbot/python/2.7.koobs-freebsd10/build/Lib/uuid.py", line 348, in _arp_getnode
        ip_addr = socket.gethostbyname(socket.gethostname())
    gaierror: [Errno 8] hostname nor servname provided, or not known

    @koobs koobs reopened this Nov 14, 2014
    @serhiy-storchaka
    Copy link
    Member

    This issue had added new tests. Here is a patch against 2.7 (3.4+ should use OSError instead of socket.gaierror) which fixes _arp_getnode().

    @koobs
    Copy link

    koobs commented Nov 15, 2014

    I only attached the 2.7 build log because the failures from 3.4 and 3.x are identical, copying them here for completeness:

    From 3.4:

    ======================================================================
    ERROR: test_arp_getnode (test.test_uuid.TestUUID)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/usr/home/buildbot/python/3.4.koobs-freebsd10/build/Lib/test/test_uuid.py", line 324, in test_arp_getnode
        node = uuid._arp_getnode()
      File "/usr/home/buildbot/python/3.4.koobs-freebsd10/build/Lib/uuid.py", line 364, in _arp_getnode
        ip_addr = socket.gethostbyname(socket.gethostname())
    socket.gaierror: [Errno 8] hostname nor servname provided, or not known

    Ran 18 tests in 0.209s

    From 3.x:

    ======================================================================
    ERROR: test_arp_getnode (test.test_uuid.TestUUID)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/usr/home/buildbot/python/3.x.koobs-freebsd10/build/Lib/test/test_uuid.py", line 325, in test_arp_getnode
        node = uuid._arp_getnode()
      File "/usr/home/buildbot/python/3.x.koobs-freebsd10/build/Lib/uuid.py", line 362, in _arp_getnode
        ip_addr = socket.gethostbyname(socket.gethostname())
    socket.gaierror: [Errno 8] hostname nor servname provided, or not known

    @serhiy-storchaka
    Copy link
    Member

    Oh, socket.gaierror was not made an alias of OSError, only subclass of it. Well, we can apply the same patch to all releases. Does it fix tests?

    @koobs
    Copy link

    koobs commented Nov 17, 2014

    I don't have the environment to test here. Can you run a custom build on the buildbots?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 21, 2014

    New changeset 301d62ef5c0b by Serhiy Storchaka in branch '2.7':
    Issue bpo-17293: socket.gethostbyname() can raise an exception of FreeBSD.
    https://hg.python.org/cpython/rev/301d62ef5c0b

    New changeset 97ceab0bd6f8 by Serhiy Storchaka in branch '3.4':
    Issue bpo-17293: socket.gethostbyname() can raise an exception of FreeBSD.
    https://hg.python.org/cpython/rev/97ceab0bd6f8

    @xnox
    Copy link
    Mannequin

    xnox mannequin commented Jan 5, 2015

    I'm getting socket.gaierror from test_ifconfig_getnode / uuid._ifconfig_getnode() on python 3.4.2 on Linux, in a no network environment. Thus i'd like to see these try:/excepts: to be ported back to 3.4 branch, if they haven't been already.

    I filed http://bugs.python.org/issue23170 to track my issue.

    Feel free to close that one as a (related) dupe of this one.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants