diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-07-11 20:47:39 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-07-11 20:47:39 +0200 |
commit | 31258b5775423d340231cab7a3a6682b24b9cc65 (patch) | |
tree | 8d48917ef68b2aceb502f4e0f5c0c431a1efeab6 | |
parent | 9fb3f692a0be2526fc60fb43facc487fa55d896f (diff) | |
download | psutil-31258b5775423d340231cab7a3a6682b24b9cc65.tar.gz |
#534: (Linux) add support for ZFS filesystems
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | psutil/_pslinux.py | 12 | ||||
-rw-r--r-- | test/_linux.py | 24 |
4 files changed, 35 insertions, 4 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index bcc6ebf7..d00dd71e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -5,6 +5,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues **Enhancements** +- #534: [Linux] disk_partitions() added support for ZFS filesystems. - #646: continuous tests integration for Windows with https://ci.appveyor.com/project/giampaolo/psutil. - #647: new dev guide: @@ -46,7 +46,7 @@ setup-dev-env: flake8 \ ipaddress \ ipdb \ - mock==1.0.1 + mock==1.0.1 \ nose \ pep8 \ pyflakes \ diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 8c07b9b3..7eb25f51 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -668,11 +668,17 @@ def disk_io_counters(): def disk_partitions(all=False): """Return mounted disk partitions as a list of namedtuples""" - phydevs = set() + fstypes = set() with open("/proc/filesystems", "r") as f: for line in f: + line = line.strip() if not line.startswith("nodev"): - phydevs.add(line.strip()) + fstypes.add(line.strip()) + else: + # ignore all lines starting with "nodev" except "nodev zfs" + fstype = line.split("\t")[1] + if fstype == "zfs": + fstypes.add("zfs") retlist = [] partitions = cext.disk_partitions() @@ -681,7 +687,7 @@ def disk_partitions(all=False): if device == 'none': device = '' if not all: - if device == '' or fstype not in phydevs: + if device == '' or fstype not in fstypes: continue ntuple = _common.sdiskpart(device, mountpoint, fstype, opts) retlist.append(ntuple) diff --git a/test/_linux.py b/test/_linux.py index dd612922..c1927ea8 100644 --- a/test/_linux.py +++ b/test/_linux.py @@ -402,6 +402,30 @@ class LinuxSpecificTestCase(unittest.TestCase): self.assertEqual(psutil.users()[0].host, 'foo') assert m.called + def test_disk_partitions_mocked(self): + # Test that ZFS partitions are returned. + with open("/proc/filesystems", "r") as f: + data = f.read() + if 'zfs' in data: + for part in psutil.disk_partitions(): + if part.fstype == 'zfs': + break + else: + self.fail("couldn't find any ZFS partition") + else: + # No ZFS partitions on this system. Let's fake one. + fake_file = io.StringIO(u("nodev\tzfs\n")) + with mock.patch('psutil._pslinux.open', + return_value=fake_file, create=True) as m1: + with mock.patch( + 'psutil._pslinux.cext.disk_partitions', + return_value=[('/dev/sdb3', '/', 'zfs', 'rw')]) as m2: + ret = psutil.disk_partitions() + assert m1.called + assert m2.called + assert ret + self.assertEqual(ret[0].fstype, 'zfs') + # --- tests for specific kernel versions @unittest.skipUnless( |