summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-02-09 21:29:35 +0100
committerGitHub <noreply@github.com>2020-02-09 21:29:35 +0100
commit796b2dda2e0d8751eee0a4d16ab8c027839f8908 (patch)
tree04c466dc50a84ca880b5c344634c6b8eef750541
parent13cf7d7ab356233c3bb8dc34f1143e7bb0c2c088 (diff)
downloadpsutil-796b2dda2e0d8751eee0a4d16ab8c027839f8908.tar.gz
[Linux] disk_io_counters() ValueError when parsing /sys/block (#1684)
Fixes: ``` ====================================================================== ERROR: psutil.tests.test_linux.TestSystemDiskIoCounters.test_emulate_use_sysfs ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/giampaolo/svn/psutil/psutil/tests/test_linux.py", line 1195, in test_emulate_use_sysfs wsysfs = psutil.disk_io_counters(perdisk=True) File "/home/giampaolo/svn/psutil/psutil/__init__.py", line 2065, in disk_io_counters rawdict = _psplatform.disk_io_counters(**kwargs) File "/home/giampaolo/svn/psutil/psutil/_pslinux.py", line 1124, in disk_io_counters for entry in gen: File "/home/giampaolo/svn/psutil/psutil/_pslinux.py", line 1110, in read_sysfs wbytes, wtime, _, busy_time, _) = map(int, fields) ValueError: too many values to unpack (expected 11) ```
-rw-r--r--HISTORY.rst2
-rw-r--r--psutil/_pslinux.py2
-rwxr-xr-xpsutil/tests/test_linux.py23
3 files changed, 5 insertions, 22 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 0277db58..2a9c046b 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -34,6 +34,8 @@ XXXX-XX-XX
- 1673_: [OpenBSD] Process connections(), num_fds() and threads() returned
improper exception if process is gone.
- 1674_: [SunOS] disk_partitions() may raise OSError.
+- 1684_: [Linux] disk_io_counters() may raise ValueError on systems not
+ having /proc/diskstats.
5.6.7
=====
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 7348b3dc..ba65aea9 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1106,7 +1106,7 @@ def disk_io_counters(perdisk=False):
fields = f.read().strip().split()
name = os.path.basename(root)
(reads, reads_merged, rbytes, rtime, writes, writes_merged,
- wbytes, wtime, _, busy_time, _) = map(int, fields)
+ wbytes, wtime, _, busy_time) = map(int, fields[:10])
yield (name, reads, writes, rbytes, wbytes, rtime,
wtime, reads_merged, writes_merged, busy_time)
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 80bbd113..97946a0b 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -316,7 +316,7 @@ class TestSystemVirtualMemory(unittest.TestCase):
@retry_on_failure()
def test_avail_old_percent(self):
# Make sure that our calculation of avail mem for old kernels
- # is off by max 10%.
+ # is off by max 15%.
from psutil._pslinux import calculate_avail_vmem
from psutil._pslinux import open_binary
@@ -330,7 +330,7 @@ class TestSystemVirtualMemory(unittest.TestCase):
if b'MemAvailable:' in mems:
b = mems[b'MemAvailable:']
diff_percent = abs(a - b) / a * 100
- self.assertLess(diff_percent, 10)
+ self.assertLess(diff_percent, 15)
def test_avail_old_comes_from_kernel(self):
# Make sure "MemAvailable:" coluimn is used instead of relying
@@ -1548,25 +1548,6 @@ class TestSensorsBattery(unittest.TestCase):
@unittest.skipIf(not LINUX, "LINUX only")
class TestSensorsTemperatures(unittest.TestCase):
- @unittest.skipIf(TRAVIS, "unreliable on TRAVIS")
- @unittest.skipIf(LINUX and EMPTY_TEMPERATURES, "no temperatures")
- def test_emulate_eio_error(self):
- def open_mock(name, *args, **kwargs):
- if name.endswith("_input"):
- raise OSError(errno.EIO, "")
- elif name.endswith("temp"):
- raise OSError(errno.EIO, "")
- else:
- return orig_open(name, *args, **kwargs)
-
- orig_open = open
- patch_point = 'builtins.open' if PY3 else '__builtin__.open'
- with mock.patch(patch_point, side_effect=open_mock) as m:
- with warnings.catch_warnings(record=True) as ws:
- self.assertEqual(psutil.sensors_temperatures(), {})
- assert m.called
- self.assertIn("ignoring", str(ws[0].message))
-
def test_emulate_class_hwmon(self):
def open_mock(name, *args, **kwargs):
if name.endswith('/name'):