diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2022-09-06 19:48:27 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2022-09-06 19:48:27 +0200 |
commit | 5cf18078d81741f1783100ec62e85fab6ba55e91 (patch) | |
tree | 9a9e207da1a4e7ae7064975ca2f442b8d754f02d | |
parent | 70eecaf44d61f2cabcd22ffb407b904242a122c9 (diff) | |
download | psutil-5cf18078d81741f1783100ec62e85fab6ba55e91.tar.gz |
add ifconfig test case for NIC flags re. to #2037
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | psutil/tests/test_linux.py | 21 |
2 files changed, 22 insertions, 1 deletions
@@ -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 41645e3b..feec0a59 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -993,6 +993,27 @@ class TestSystemNetIfStats(PsutilTestCase): 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<UP,BROADCAST,RUNNING,MULTICAST> 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): |