Fix a regression in uuid added in bpo-32107. (#4677)
uuid.get_node() always must return a stable result. Also added a test for non-reproducibility of _random_getnode(). Original patch by Xavier de Gaye.
This commit is contained in:
parent
85d5c18c9d
commit
e69fbb6a56
|
@ -565,6 +565,9 @@ eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
|
||||||
self.assertTrue(node & (1 << 40), '%012x' % node)
|
self.assertTrue(node & (1 << 40), '%012x' % node)
|
||||||
self.check_node(node)
|
self.check_node(node)
|
||||||
|
|
||||||
|
node2 = self.uuid._random_getnode()
|
||||||
|
self.assertNotEqual(node2, node, '%012x' % node)
|
||||||
|
|
||||||
@unittest.skipUnless(os.name == 'posix', 'requires Posix')
|
@unittest.skipUnless(os.name == 'posix', 'requires Posix')
|
||||||
def test_unix_getnode(self):
|
def test_unix_getnode(self):
|
||||||
if not importable('_uuid') and not importable('ctypes'):
|
if not importable('_uuid') and not importable('ctypes'):
|
||||||
|
|
|
@ -674,14 +674,14 @@ def getnode():
|
||||||
getters = [_unix_getnode, _ifconfig_getnode, _ip_getnode,
|
getters = [_unix_getnode, _ifconfig_getnode, _ip_getnode,
|
||||||
_arp_getnode, _lanscan_getnode, _netstat_getnode]
|
_arp_getnode, _lanscan_getnode, _netstat_getnode]
|
||||||
|
|
||||||
for getter in getters:
|
for getter in getters + [_random_getnode]:
|
||||||
try:
|
try:
|
||||||
_node = getter()
|
_node = getter()
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
if _node is not None:
|
if _node is not None:
|
||||||
return _node
|
return _node
|
||||||
return _random_getnode()
|
assert False, '_random_getnode() returned None'
|
||||||
|
|
||||||
|
|
||||||
_last_timestamp = None
|
_last_timestamp = None
|
||||||
|
|
Loading…
Reference in New Issue