Skip to content

Commit 9ae8920

Browse files
committed
Fix ifconfig flags tests, run in Python 3 CI
- Python 2 CI image has an old net-tools (hence ifconfig) version with a non-easily-parsable flags format, making tests fail. - Python 3 musllinux CI image has a busybox-provided ifconfig with the same format as old net-tools. - Python 3 manylinux CI image does not have net-tools (hence ifconfig) pre-installed, so tests using it were skippied altogether. Signed-off-by: Ben Raz <[email protected]>
1 parent 5c55456 commit 9ae8920

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ jobs:
3333
include:
3434
- {name: Linux, python: '3.9', os: ubuntu-latest}
3535
env:
36-
CIBW_BEFORE_ALL_LINUX: command -v apk && apk --no-cache add coreutils procps || true
36+
CIBW_BEFORE_ALL_LINUX: command -v apk && apk --no-cache add coreutils procps ||
37+
(yum install -y net-tools && yum clean all)
3738
CIBW_TEST_COMMAND:
3839
PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 python {project}/psutil/tests/runner.py &&
3940
PYTHONWARNINGS=always PYTHONUNBUFFERED=1 PSUTIL_DEBUG=1 python {project}/psutil/tests/test_memleaks.py

psutil/tests/test_linux.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ def get_free_version_info():
204204
return tuple(map(int, out.split()[-1].split('.')))
205205

206206

207+
def ifconfig_has_flags():
208+
"""
209+
Parse 'ifconfig' command output and determine whether
210+
it exposes easily-parsable flags for interfaces or not.
211+
"""
212+
if not which('ifconfig'):
213+
return False
214+
215+
out = sh(['ifconfig']).strip()
216+
return 'flags=' in out
217+
218+
207219
@contextlib.contextmanager
208220
def mock_open_content(for_path, content):
209221
"""Mock open() builtin and forces it to return a certain `content`
@@ -993,7 +1005,10 @@ def test_mtu(self):
9931005
with open("/sys/class/net/%s/mtu" % name, "rt") as f:
9941006
self.assertEqual(stats.mtu, int(f.read().strip()))
9951007

996-
@unittest.skipIf(not which("ifconfig"), "ifconfig utility not available")
1008+
@unittest.skipIf(not which("ifconfig"),
1009+
"ifconfig utility not available")
1010+
@unittest.skipIf(not ifconfig_has_flags(),
1011+
"ifconfig utility doesn't expose flags in a known format")
9971012
def test_flags(self):
9981013
# first line looks like this:
9991014
# "eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500"
@@ -1023,7 +1038,7 @@ class TestSystemNetIOCounters(PsutilTestCase):
10231038
def test_against_ifconfig(self):
10241039
def ifconfig(nic):
10251040
ret = {}
1026-
out = sh("ifconfig %s" % name)
1041+
out = sh("ifconfig %s" % nic)
10271042
ret['packets_recv'] = int(
10281043
re.findall(r'RX packets[: ](\d+)', out)[0])
10291044
ret['packets_sent'] = int(

0 commit comments

Comments
 (0)