Skip to content

Commit

Permalink
[Linux] disk_io_counters() ValueError when parsing /sys/block (#1684)
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
giampaolo authored Feb 9, 2020
1 parent 13cf7d7 commit 796b2dd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand Down
2 changes: 1 addition & 1 deletion psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def read_sysfs():
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)

Expand Down
23 changes: 2 additions & 21 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def test_warnings_on_misses(self):
@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

Expand All @@ -330,7 +330,7 @@ def test_avail_old_percent(self):
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
Expand Down Expand Up @@ -1548,25 +1548,6 @@ def test_emulate_no_power(self):
@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'):
Expand Down

0 comments on commit 796b2dd

Please sign in to comment.