From 5cf18078d81741f1783100ec62e85fab6ba55e91 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 6 Sep 2022 19:48:27 +0200 Subject: [PATCH] add ifconfig test case for NIC flags re. to #2037 --- Makefile | 2 +- psutil/tests/test_linux.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 05ca56550..caf4c9e9d 100644 --- a/Makefile +++ b/Makefile @@ -248,7 +248,7 @@ print-wheels: ## Print downloaded wheels # =================================================================== git-tag-release: ## Git-tag a new release. - git tag -a release-`python -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD` + git tag -a release-`python3 -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD` git push --follow-tags sdist: ## Create tar.gz source distribution. diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index 41645e3bc..feec0a59f 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -993,6 +993,27 @@ def test_mtu(self): with open("/sys/class/net/%s/mtu" % name, "rt") as f: self.assertEqual(stats.mtu, int(f.read().strip())) + @unittest.skipIf(not which("ifconfig"), "ifconfig utility not available") + def test_flags(self): + # first line looks like this: + # "eth0: flags=4163 mtu 1500" + matches_found = 0 + for name, stats in psutil.net_if_stats().items(): + try: + out = sh("ifconfig %s" % name) + except RuntimeError: + pass + else: + match = re.search(r"flags=(\d+)?<(.*?)>", out) + if match and len(match.groups()) >= 2: + matches_found += 1 + ifconfig_flags = set(match.group(2).lower().split(",")) + psutil_flags = set(stats.flags.split(",")) + self.assertEqual(ifconfig_flags, psutil_flags) + + if not matches_found: + raise self.fail("no matches were found") + @unittest.skipIf(not LINUX, "LINUX only") class TestSystemNetIOCounters(PsutilTestCase):