Skip to content

Commit d80cbdd

Browse files
miss-islingtonvstinnergpsheadencukou
authored
[3.9] gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-129171) (GH-129440) (#130075)
Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host address or the "any" address, use the local communication address (loopback): VMADDR_CID_LOCAL. On Linux 6.9, apparently, the /dev/vsock device is now available but get_cid() returns VMADDR_CID_ANY (-1). (cherry picked from commit 45db419) (cherry picked from commit e94dbe4) (cherry picked from commit c750061) (cherry picked from commit cbfe302) --- Restore the skipUnless removed by GH-119465. This test can only pass on virtual machines, not actual machines. Actual machines see: ``` self.cli.connect((cid, VSOCKPORT)) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ OSError: [Errno 19] No such device ``` Reproduced on (Linux) Ubuntu 24.04.1 running 6.8.0-52-generic. (cherry picked from commit 2bd9f9b) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 8a417ed commit d80cbdd

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Lib/test/test_socket.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# test unicode string and carriage return
4040
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4141

42+
VMADDR_CID_LOCAL = 1
4243
VSOCKPORT = 1234
4344
AIX = platform.system() == "AIX"
4445

@@ -122,8 +123,8 @@ def _have_socket_qipcrtr():
122123

123124
def _have_socket_vsock():
124125
"""Check whether AF_VSOCK sockets are supported on this host."""
125-
ret = get_cid() is not None
126-
return ret
126+
cid = get_cid()
127+
return (cid is not None)
127128

128129

129130
def _have_socket_bluetooth():
@@ -485,8 +486,8 @@ def clientTearDown(self):
485486
@unittest.skipIf(fcntl is None, "need fcntl")
486487
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
487488
'VSOCK sockets required for this test.')
488-
@unittest.skipUnless(get_cid() != 2,
489-
"This test can only be run on a virtual guest.")
489+
@unittest.skipUnless(get_cid() != 2, # VMADDR_CID_HOST
490+
"This test can only be run on a virtual guest.")
490491
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
491492

492493
def __init__(self, methodName='runTest'):
@@ -507,10 +508,16 @@ def clientSetUp(self):
507508
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
508509
self.addCleanup(self.cli.close)
509510
cid = get_cid()
511+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
512+
# gh-119461: Use the local communication address (loopback)
513+
cid = VMADDR_CID_LOCAL
510514
self.cli.connect((cid, VSOCKPORT))
511515

512516
def testStream(self):
513-
msg = self.conn.recv(1024)
517+
try:
518+
msg = self.conn.recv(1024)
519+
except PermissionError as exc:
520+
self.skipTest(repr(exc))
514521
self.assertEqual(msg, MSG)
515522

516523
def _testStream(self):

0 commit comments

Comments
 (0)