Skip to content

Commit 2bd9f9b

Browse files
miss-islingtonvstinnergpshead
authored
[3.10] gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-129171) (#129440)
* [3.11] gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-129171) 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) Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit e94dbe4) (cherry picked from commit c750061) (cherry picked from commit cbfe302) * gh-119461: Restore the testSocket VSOCK skipUnless removed by PR #119465 (#129561) Restore the skipUnless removed by #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. --------- Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
1 parent 10a2a9b commit 2bd9f9b

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
@@ -41,6 +41,7 @@
4141
# test unicode string and carriage return
4242
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4343

44+
VMADDR_CID_LOCAL = 1
4445
VSOCKPORT = 1234
4546
AIX = platform.system() == "AIX"
4647

@@ -124,8 +125,8 @@ def _have_socket_qipcrtr():
124125

125126
def _have_socket_vsock():
126127
"""Check whether AF_VSOCK sockets are supported on this host."""
127-
ret = get_cid() is not None
128-
return ret
128+
cid = get_cid()
129+
return (cid is not None)
129130

130131

131132
def _have_socket_bluetooth():
@@ -487,8 +488,8 @@ def clientTearDown(self):
487488
@unittest.skipIf(fcntl is None, "need fcntl")
488489
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
489490
'VSOCK sockets required for this test.')
490-
@unittest.skipUnless(get_cid() != 2,
491-
"This test can only be run on a virtual guest.")
491+
@unittest.skipUnless(get_cid() != 2, # VMADDR_CID_HOST
492+
"This test can only be run on a virtual guest.")
492493
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
493494

494495
def __init__(self, methodName='runTest'):
@@ -509,10 +510,16 @@ def clientSetUp(self):
509510
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
510511
self.addCleanup(self.cli.close)
511512
cid = get_cid()
513+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
514+
# gh-119461: Use the local communication address (loopback)
515+
cid = VMADDR_CID_LOCAL
512516
self.cli.connect((cid, VSOCKPORT))
513517

514518
def testStream(self):
515-
msg = self.conn.recv(1024)
519+
try:
520+
msg = self.conn.recv(1024)
521+
except PermissionError as exc:
522+
self.skipTest(repr(exc))
516523
self.assertEqual(msg, MSG)
517524

518525
def _testStream(self):

0 commit comments

Comments
 (0)