summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Page <adrian@pagenet.plus.com>2017-10-28 18:37:07 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-10-28 19:37:07 +0200
commit3cec63006e0f3f3498862310268d2ca6e21af39d (patch)
treed53566f7b4151c8b9fca577313ddaef09e89cb1d
parentbe8abbdf9cbab6ea82a1b16ad144a55783c5f45b (diff)
downloadpsutil-3cec63006e0f3f3498862310268d2ca6e21af39d.tar.gz
Fix network tests for newer ifconfig versions. (#1160)
Arch Linux and Ubuntu 17.10 use a newer ifconfig version than other distributions and that changes the statistics output text formatting, causing the following tests to fail: psutil.tests.test_linux.TestSystemNetwork.test_net_if_stats psutil.tests.test_linux.TestSystemNetwork.test_net_io_counters MTU becomes lower case, colons are replaced with spaces, and packets and bytes are on the same line. Example ifconfig output: enp2s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether a8:20:66:04:4c:45 txqueuelen 1000 (Ethernet) RX packets 1396351 bytes 1928499072 (1.7 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 750492 bytes 185338978 (176.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 16
-rwxr-xr-xpsutil/tests/test_linux.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 468b3c66..7bb37a8d 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -762,21 +762,25 @@ class TestSystemNetwork(unittest.TestCase):
# Not always reliable.
# self.assertEqual(stats.isup, 'RUNNING' in out, msg=out)
self.assertEqual(stats.mtu,
- int(re.findall(r'MTU:(\d+)', out)[0]))
+ int(re.findall(r'(?i)MTU[: ](\d+)', out)[0]))
@retry_before_failing()
def test_net_io_counters(self):
def ifconfig(nic):
ret = {}
out = sh("ifconfig %s" % name)
- ret['packets_recv'] = int(re.findall(r'RX packets:(\d+)', out)[0])
- ret['packets_sent'] = int(re.findall(r'TX packets:(\d+)', out)[0])
- ret['errin'] = int(re.findall(r'errors:(\d+)', out)[0])
- ret['errout'] = int(re.findall(r'errors:(\d+)', out)[1])
- ret['dropin'] = int(re.findall(r'dropped:(\d+)', out)[0])
- ret['dropout'] = int(re.findall(r'dropped:(\d+)', out)[1])
- ret['bytes_recv'] = int(re.findall(r'RX bytes:(\d+)', out)[0])
- ret['bytes_sent'] = int(re.findall(r'TX bytes:(\d+)', out)[0])
+ ret['packets_recv'] = int(
+ re.findall(r'RX packets[: ](\d+)', out)[0])
+ ret['packets_sent'] = int(
+ re.findall(r'TX packets[: ](\d+)', out)[0])
+ ret['errin'] = int(re.findall(r'errors[: ](\d+)', out)[0])
+ ret['errout'] = int(re.findall(r'errors[: ](\d+)', out)[1])
+ ret['dropin'] = int(re.findall(r'dropped[: ](\d+)', out)[0])
+ ret['dropout'] = int(re.findall(r'dropped[: ](\d+)', out)[1])
+ ret['bytes_recv'] = int(
+ re.findall(r'RX (?:packets \d+ +)?bytes[: ](\d+)', out)[0])
+ ret['bytes_sent'] = int(
+ re.findall(r'TX (?:packets \d+ +)?bytes[: ](\d+)', out)[0])
return ret
nio = psutil.net_io_counters(pernic=True, nowrap=False)