-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-28009: for AIX correct uuid.getnode() and add ctypes() based uuid._generate_time_safe #5183
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
Conversation
util._generate_time_safe based on lib.uuid_create (for when _uuid is not available) * use the character '.' rather than ':' to seperate the MAC ADDR values returned by 'netstat -i' command (AIX specific) * The commands arp and ifconfig do not return a local MAC address
Also, correct comments to explain changes to 'legacy' code
I wanted this in: +_NODE_GETTERS_AIX = [_unix_getnode, _netstat_getnode] @@ -722,6 +724,8 @@
but continuously creates a merge conflict. C'est la vie. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general note, AIX is a niche system and should have the absolute possible minimum of code specific to it -- if anything, because the devteam can't test and thus maintain the correctness of that code. For the same reason, it should disrupt control flow the least amount possible -- otherwise, those untestable chunks will put limitations on further changes. Whenever possible, UNIX flavors should be distinguished by functional differences rather than names.
if sys.platform.startswith("aix"): | ||
c_field = b'.' | ||
else: | ||
c_field = b':' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Comments should only provide required info that's not apparent from the code/repo metadata. In particular, issue ref is only useful if the matter isn't resolved yet. Should be like:
AIX <commands involved> use '.' as MAC delimiter
- ternary form to reduce size & duplication and a more descriptive var name (e.g.
mac_delim
)
return int(word.replace(b'.', b''), 16) | ||
else: | ||
return None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- A great deal of duplication between the two routines. Can be consolidated. Heed the general CR comment.
- Include a comment with samples of the text chunk being parsed in both cases so that the magic numbers make sense.
- Reuse the above MAC delimiter var -- maybe as a global var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the light of "functional differences better than names" -- probably detect the format instead?
@@ -573,12 +598,18 @@ def _load_system_functions(): | |||
|
|||
# The uuid_generate_* routines are provided by libuuid on at least | |||
# Linux and FreeBSD, and provided by libc on Mac OS X. | |||
# uuid_create() is used by other POSIX platforms (e.g., AIX, FreeBSD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Contradicts the existing statement just before
- fns names are formatted differently
# lib value, then look for uuid_generate() | ||
if not lib: | ||
try: | ||
lib = ctypes.CDLL(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this supposed to work? None
arg effect is undocumented. According to https://www.programcreek.com/python/example/1108/ctypes.CDLL , this is going to get the main program itself (in POSIX, at least. In Windows, it raises a TypeError
) which doesn't have the required export (and probably any). Looks redundant.
_buffer = ctypes.create_string_buffer(16)# uuid | ||
_status = ctypes.create_string_buffer(2) # c_ushort | ||
_uuid_generate_time(_buffer, _status) | ||
return bytes(_buffer.raw), bytes(_status.raw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only searches the last found lib, whatever it happens to be.
Better search uuid_create
with other exports and save in a temporary var if found. After the loop, execute this code if uuid_create
is found and others aren't.
_NODE_GETTERS_UNIX = [_unix_getnode, _ifconfig_getnode, _ip_getnode, | ||
_arp_getnode, _lanscan_getnode, _netstat_getnode] | ||
|
||
def getnode(*, getters=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't see the purpose of any changes from here and further.
About this one specifically:
- There's no discussion about an interface change or justification for it.
- In any case, the
getters
arg is unused as the code is now.
return _node | ||
assert False, '_random_getnode() returned None' | ||
assert False, '_random_getnode() returned invalid value: {}'.format(_node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getters are supposed to return valid ids or None
. Any violations that warrant rejecting the value received from the OS should be checked for by the getter itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"define uuid._generate_time_safe in uuid.py based on ctypes() lib.uuid_create (for when _uuid is not available)"
When is _uuid not available? Why not fixing _uuid instead, if it has issues?
_uuid is fixed in AIX 6.1 and later, but not in AIX 5.3 as AIX 5.3 does not have uuid_create() in libc.
…Sent from my iPhone
On 4 Jun 2018, at 03:00, Victor Stinner ***@***.***> wrote:
@vstinner commented on this pull request.
"define uuid._generate_time_safe in uuid.py based on ctypes() lib.uuid_create (for when _uuid is not available)"
When is _uuid not available? Why not fixing _uuid instead, if it has issues?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
What is available on AIX 5.3? |
Please excuse the wall of examples.
On 6/4/2018 7:37 AM, Victor Stinner wrote:
_uuid is fixed in AIX 6.1 and later, but not in AIX 5.3 as AIX 5.3
does not have uuid_create() in libc.
Currently all versions of AIX rely on netstat -i processing (Python2 and
Python3) as the _uuid fix is only in Python3.7.
What is available on AIX 5.3?
As AIX 5.3 (and all earlier versions) lack uuid support, AIX depends on
the output of netstat -i to get the mac address of the current system.
Currently, the implementation is wrong because of the search for the
colon (':') character.
DETAILS/Examples
FYI: arp -an can return the MAC address of a remote system, but not
itself - and this does use the colon. Maybe this is the origin of the
confusion.
$ arp -an
...
? (192.168.129.61) at 0:14:5e:c7:f:ca [ethernet] stored in bucket 132
...
ifconfig does not return/show the local mac addresses - only IP
addresses and netmask
$ ifconfig -a
en0:
flags=1e084863,14c0<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),LARGESEND,CHAIN>
inet 192.168.129.71 netmask 0xffffff00 broadcast 192.168.129.255
inet 192.168.90.71 netmask 0xffffff00 broadcast 192.168.90.255
tcp_sendspace 262144 tcp_recvspace 262144 tcp_nodelay 1 rfc1323 1
en1:
flags=1e084863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
lo0:
flags=e08084b,c0<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,LARGESEND,CHAIN>
inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
inet6 ::1%1/0
tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1
netstat -ia does return a value with the ':' character, but it is a
constant for all interfaces, on all systems. Not very "unique" ;)
netstat -ia
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll
en0 1500 link#2 fa.d1.8c.f7.62.4 1850055300 0 798079082
0 0
01:00:5e:00:00:01
en0 1500 192.168.129 x071 1850055300 0 798079082
0 0
224.0.0.1
en0 1500 192.168.90 x071 1850055300 0 798079082
0 0
224.0.0.1
en1 1500 link#3 fa.d1.8c.f7.62.5 35247637 0 53006985 0 0
01:00:5e:00:00:01
en1 1500 192.168.2 mail.aixtools.co 35247637 0 53006985 0 0
224.0.0.1
lo0 16896 link#1 994536 0 994536 0 0
lo0 16896 127 loopback 994536 0 994536 0 0
224.0.0.1
lo0 16896 loopback 994536 0 994536 0 0
$ dsh -a netstat -ia | egrep ":[0-9a-f]:" | sort -u
x061: ff02::1:ff00:1
x062: ff02::1:ff00:1
x063: ff02::1:ff00:1
x064: ff02::1:ff00:1
x065: ff02::1:ff00:1
x066: ff02::1:ff00:1
x067: ff02::1:ff00:1
x068: ff02::1:ff00:1
x069: ff02::1:ff00:1
x070: ff02::1:ff00:1
x071: ff02::1:ff00:1
x072: ff02::1:ff00:1
Using the '.' character both netstat -i and netstat -ia return the same
"layout".
michael@x071:[/home/michael]dsh -a netstat -ia | egrep
"link#.*[0-9a-f]+\." | sort
x061: en0 1500 link#2 0.14.5e.c7.f.ca 2956249 0
3155401 3 0
x061: en1 1500 link#3 0.14.5e.c7.f.cb 480103254 0
257084859 4 0
x062: en0 1500 link#2 0.21.5e.a3.c7.42 7764939 0
4283174 0 0
x063: en1 1500 link#2 fa.d1.86.d4.97.4 9173264 0
8472320 0 0
x064: en0 1500 link#2 0.21.5e.a3.c7.44 881980 0 411142
0 0
x065: en0 1500 link#2 fa.d1.86.33.4c.4 1741169 0
1089608 0 0
x066: en0 1500 link#2 0.21.5e.a3.c7.46 27372 0 20396
0 0
x067: en0 1500 link#2 0.21.5e.a3.c7.47 756960 0 464111
0 0
x068: en0 1500 link#2 fa.d1.84.d3.9.4 630782 0 334713
0 0
x069: en0 1500 link#2 fa.d1.80.7.9b.4 588838 0 319134
0 0
x070: en0 1500 link#2 fa.d1.86.86.1d.4 557284 0 290822
0 0
x071: en0 1500 link#2 fa.d1.8c.f7.62.4 1850118244 0
798131868 0 0
x071: en1 1500 link#3 fa.d1.8c.f7.62.5 35252897 0
5301366 0 0
x072: en0 1500 link#2 fa.d1.83.60.33.4 600408 0 325491
0 0
michael@x071:[/home/michael]dsh -a netstat -i | egrep
"link#.*[0-9a-f]+\." | sort
x061: en0 1500 link#2 0.14.5e.c7.f.ca 2956310 0
3155453 3 0
x061: en1 1500 link#3 0.14.5e.c7.f.cb 480104733 0
257085779 4 0
x062: en0 1500 link#2 0.21.5e.a3.c7.42 7764998 0
4283220 0 0
x063: en1 1500 link#2 fa.d1.86.d4.97.4 9173365 0
8472407 0 0
x064: en0 1500 link#2 0.21.5e.a3.c7.44 882009 0 411160
0 0
x065: en0 1500 link#2 fa.d1.86.33.4c.4 1741205 0
1089631 0 0
x066: en0 1500 link#2 0.21.5e.a3.c7.46 27407 0 20420
0 0
x067: en0 1500 link#2 0.21.5e.a3.c7.47 756989 0 464128
0 0
x068: en0 1500 link#2 fa.d1.84.d3.9.4 630818 0 334738
0 0
x069: en0 1500 link#2 fa.d1.80.7.9b.4 588867 0 319152
0 0
x070: en0 1500 link#2 fa.d1.86.86.1d.4 557312 0 290839
0 0
x071: en0 1500 link#2 fa.d1.8c.f7.62.4 1850119720 0
798133182 0 0
x071: en1 1500 link#3 fa.d1.8c.f7.62.5 35253076 0
53013825 0 0
x072: en0 1500 link#2 fa.d1.83.60.33.4 600436 0 325508
0 0
… —
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5183 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKWY9ZKEa02VuQ2wfcK-WNtnBrovKU4Lks5t5TgygaJpZM4Rdu0s>.
|
I don't understand why ctypes is needed. You wrote that AIX 6.1 can use _uuid, but AIX 5.3 has no usable system uuid library. If AIX doesn't benefit of ctypes, would you mind to simplify your PR to only fix the AIX specific issue (the colon character issue)? |
On 6/4/2018 9:46 AM, Victor Stinner wrote:
I don't understand why ctypes is needed. You wrote that AIX 6.1 can
use _uuid, but AIX 5.3 has no usable system uuid library. If AIX
doesn't benefit of ctypes, would you mind to simplify your PR to only
fix the AIX specific issue (the colon character issue)?
Yes, I can do that. However, I still hope you will consider backporting
this - as it has been broken everywhere for a long time.
Also note that AIX does not use libuuid - so ctypes will never be needed
- or useable - in that way. The uuid support is built-in to libc which
is active by default.
… —
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5183 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKWY9ctj4Ky_Fu2tCwPPjb1q_Ounwdf-ks5t5VZMgaJpZM4Rdu0s>.
|
"Yes, I can do that. However, I still hope you will consider backporting this - as it has been broken everywhere for a long time." I don't understand well the AIX platform. This PR is very long and so hard to review. I suggested you to write a shorter PR so it should be simpler to get a review and fix the master branch (and 3.7 which also has _uuid). Once master (and 3.7) will be fixed, we can start discussing how to fix other branches. I don't like the idea of adding code to the master branch which is written for older branches. I prefer to not "add legacy code" to the master branch. What do you think of my rationale? |
On 6/4/2018 9:46 AM, Victor Stinner wrote:
I don't understand why ctypes is needed. You wrote that AIX 6.1 can
use _uuid,
Quick update: currently, on master, _uuid is not building. Now cloned
the 3.7 branch, and checking that.
Will report when I know more - ideally have a solution.
Question: should I open a new issue, or reuse the previous one that
first addressed _uuid?
Or, include it here?
…
but AIX 5.3 has no usable system uuid library. If AIX doesn't benefit
of ctypes, would you mind to simplify your PR to only fix the AIX
specific issue (the colon character issue)?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5183 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKWY9ctj4Ky_Fu2tCwPPjb1q_Ounwdf-ks5t5VZMgaJpZM4Rdu0s>.
|
You can reuse bpo-28009 to fix _uuid in master/3.7, but please create a different PR. |
On 6/5/2018 4:55 AM, Victor Stinner wrote:
"Yes, I can do that. However, I still hope you will consider
backporting this - as it has been broken everywhere for a long time."
I don't understand well the AIX platform. This PR is very long and so
hard to review. I suggested you to write a shorter PR so it should be
simpler to get a review and fix the master branch (and 3.7 which also
has _uuid).
Once master (and 3.7) will be fixed, we can start discussing how to
fix other branches.
Great!
I don't like the idea of adding code to the master branch which is
written for older branches. I prefer to not "add legacy code" to the
master branch. What do you think of my rationale?
I believe I concur. What "happened" is that I just "cloned" master, and
started working on uuid.py. That was fairly simple. But _uuid is broken
(somewhere between Python3-3.7 rc4 and rc5). And, when I originally
submitted the PR - master was "the coming 3.7".
I don't understand git as well as I would like - so, in principle I will
only submit a PR based on the current "master".
If you prefer I work based on the 3.7 branch, then I will do that
instead. Hope to have time soon. And I shall try to think about how I
can better work at avoiding creating "walls" of text.
Searching for a hint: the current message I am getting is:
Modules/ld_so_aix xlc_r -bI:Modules/python.exp
build/temp.aix-6.1-3.7/data/prj/python/git/python3-3.7/Modules/_uuidmodule.o
-L/opt/lib -o build/lib.aix-6.1-3.7/_uuid.so
ld: 0711-317 ERROR: Undefined symbol: .uuid_enc_be
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
While the file uuidmodule.c compiles without an issue.
…
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5183 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKWY9Vdj-npN5rmtJJXPTNPMPv1Q3Rc4ks5t5mOHgaJpZM4Rdu0s>.
|
The development starts in master, once it's stabilized, it's merged into 3.7, and then to 3.6 and maybe 2.7. I'm talking about the general case. I don't know until which version we should backport these enhancements/fixes. |
On 6/6/2018 3:00 PM, Victor Stinner wrote:
The development starts in master, once it's stabilized, it's merged
into 3.7, and then to 3.6 and maybe 2.7. I'm talking about the general
case. I don't know until which version we should backport these
enhancements/fixes.
Well, this is what I found using git bisect - guess it is payback ;) -
as the _uuid for AIX did not work ideally on FreeBSD.
5734f41 is the first bad commit
commit 5734f41
Author: Miss Islington (bot)
<[email protected]>
Date: Thu May 24 16:22:59 2018 -0700
bpo-32493: Fix uuid.uuid1() on FreeBSD. (GH-7099)
Use uuid_enc_be() if available to encode UUID to bytes as big endian.
(cherry picked from commit 17d8830)
Co-authored-by: Serhiy Storchaka <[email protected]>
:040000 040000 6983052a6c16a7fda20a50595a25b8bd28b3e5d6
4c011f4015cbdc47ebfd003fa111b869227235cd M Misc
:040000 040000 9bd35582651acc82fdb7be7100d33843a39fb0b4
5c71739d2798ecf74076e172ddfaf0478f4b92de M Modules
:100755 100755 f1f01df4a80e4262d0c849aa467dfb7afec7df66
b1cd944ac562ea363eb8af040d280e1ec59c03c0 M configure
:100644 100644 2535969642042f38ad4a4a7ef485f9aef94f7b5a
59489047fc24eb1b0fe2dc2d642bd097226235c5 M configure.ac
:100644 100644 a0efff9777d27d53086971543e81abf4604a1bf6
e561a7c07cca7896f35faaa1f2dc9d07823ca42a M pyconfig.h.in
… —
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5183 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKWY9XuHZH01C-8I7vwQU7JcXGvu0703ks5t6ELngaJpZM4Rdu0s>.
|
Will start a new PR now that _uuid is working in master |
returned by 'netstat -i' command (AIX specific)
https://bugs.python.org/issue28009