Issue 28815: test_socket fails if /proc/modules is existent but not readable (original) (raw)

Created on 2016-11-27 16:16 by patrila, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_socket_isTipcAvailable_proc_modules.patch patrila,2016-11-27 16:16 Patch for test_socket.isTipcAvailable() [obsolete] review
test_socket_isTipcAvailable_proc_modules.patch patrila,2016-12-10 12:59 Patch for test_socket.isTipcAvailable() review
Messages (8)
msg281828 - (view) Author: (patrila) Date: 2016-11-27 16:16
Dear Python developers The test_socket test fails if /proc/modules is existent but not readable by the user (this is for example the case with the grsecurity patchset of the kernel). The method reading /proc/modules is isTipcAvailable(), which is not a test but a guard for other tests. It seems reasonable to return False in the case that /proc/modules is not readable (but existent). The method isTipcAvailable() already returns False if /proc/modules is non existent (but fails to return False if it's not readable). Attached a proposed test. Feel free to remove the EISDIR in case you feel uncomfortable and want a it be a "real" error. The patch should be applied to both Python-2.7 and Python-3.x. Kind regards Here is the inline version of the patch; it's also attached. diff -r 876bee0bd0ba Lib/test/test_socket.py --- a/Lib/test/test_socket.py Sat Nov 26 14:04:40 2016 -0800 +++ b/Lib/test/test_socket.py Sun Nov 27 17:00:55 2016 +0100 @@ -4779,12 +4779,21 @@ """ if not hasattr(socket, "AF_TIPC"): return False - if not os.path.isfile("/proc/modules"): - return False - with open("/proc/modules") as f: - for line in f: - if line.startswith("tipc "): - return True + try: + f = open("/proc/modules") + except IOError as e: + # It's ok if the file does not exist, is a directory or if we + # have not the permission to read it. In any other case it's a + # real error, so raise it again. + if e.errno in (ENOENT, EISDIR, EACCES): + return False + else: + raise + else: + with f: + for line in f: + if line.startswith("tipc "): + return True return False @unittest.skipUnless(isTipcAvailable(),
msg282126 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-01 02:12
This seems reasonable in general. Did you test this exact patch Patrila? It looks to me like you need to change ENOENT → errno.ENOENT, etc.
msg282849 - (view) Author: (patrila) Date: 2016-12-10 12:59
Oops, sorry that was the draft version of the patch. Attached the correct version. It was tested against "default" branch (but not against 2.7).
msg283943 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-12-24 11:38
New changeset 7889d7a771c7 by Martin Panter in branch '3.5': Issue #28815: Skip TIPC tests if /proc/modules is not readable https://hg.python.org/cpython/rev/7889d7a771c7 New changeset 48b9d9cdfe3b by Martin Panter in branch '3.6': Issue #28815: Merge test_socket fix from 3.5 https://hg.python.org/cpython/rev/48b9d9cdfe3b New changeset 7ceacac48cd2 by Martin Panter in branch 'default': Issue #28815: Merge test_socket fix from 3.6 https://hg.python.org/cpython/rev/7ceacac48cd2 New changeset 41a99a2a7198 by Martin Panter in branch '2.7': Issue #28815: Skip TIPC tests if /proc/modules is not readable https://hg.python.org/cpython/rev/41a99a2a7198
msg283946 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-24 12:23
Wouldn't be more pythonic to catch (FileNotFoundError, IsADirectoryError, PermissionError) instead of checking errno?
msg283951 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-12-24 13:40
That would be possible in Python 3, not Python 2 though.
msg284379 - (view) Author: (patrila) Date: 2016-12-31 08:32
@Martin Panter: Thanks for your support and merging.
msg284953 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-08 02:35
New changeset 5a417e160b34 by Martin Panter in branch '3.5': Issue #28815: Use new exception subclasses https://hg.python.org/cpython/rev/5a417e160b34 New changeset 401e70317976 by Martin Panter in branch '3.6': Issue #28815: Merge test tweak from 3.5 https://hg.python.org/cpython/rev/401e70317976 New changeset 82fb37281954 by Martin Panter in branch 'default': Issue #28815: Merge test tweak from 3.6 https://hg.python.org/cpython/rev/82fb37281954
History
Date User Action Args
2022-04-11 14:58:40 admin set github: 73001
2017-01-08 05:24:27 martin.panter set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-01-08 02:35:10 python-dev set messages: +
2016-12-31 08:32:59 patrila set messages: +
2016-12-24 13:40:56 martin.panter set messages: +
2016-12-24 12:23:40 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2016-12-24 11:38:41 python-dev set nosy: + python-devmessages: +
2016-12-10 12:59:13 patrila set files: + test_socket_isTipcAvailable_proc_modules.patchmessages: +
2016-12-01 02:12:44 martin.panter set type: behaviorcomponents: + Testsversions: - Python 3.3, Python 3.4nosy: + martin.pantermessages: + stage: patch review
2016-11-27 16:16:18 patrila create