Skip to content

Commit

Permalink
Merge pull request #44 from jaingaurav/diskspace
Browse files Browse the repository at this point in the history
Follow symbolic links fore device paths
  • Loading branch information
mattrobenolt committed Dec 30, 2014
2 parents 9616c8b + 35cc3f5 commit 76f934a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/collectors/diskspace/diskspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_file_systems(self):
continue

result[(major, minor)] = {
'device': device,
'device': os.path.realpath(device),
'mount_point': mount_point,
'fs_type': fs_type
}
Expand All @@ -182,7 +182,7 @@ def get_file_systems(self):
partitions = psutil.disk_partitions(False)
for partition in partitions:
result[(0, len(result))] = {
'device': partition.device,
'device': os.path.realpath(partition.device),
'mount_point': partition.mountpoint,
'fs_type': partition.fstype
}
Expand Down
9 changes: 8 additions & 1 deletion src/collectors/diskspace/test/testdiskspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_get_file_systems(self):
os_stat_mock = patch('os.stat')
os_major_mock = patch('os.major')
os_minor_mock = patch('os.minor')
os_realpath_mock = patch('os.path.realpath')
open_mock = patch('__builtin__.open',
Mock(return_value=self.getFixture('proc_mounts')))

Expand All @@ -62,22 +63,28 @@ def test_get_file_systems(self):
minor_mock = os_minor_mock.start()
minor_mock.return_value = 0

realpath_mock = os_realpath_mock.start()
realpath_mock.return_value = '/dev/sda1'

omock = open_mock.start()

result = self.collector.get_file_systems()
os_stat_mock.stop()
os_major_mock.stop()
os_minor_mock.stop()
os_realpath_mock.stop()
open_mock.stop()

stat_mock.assert_called_once_with('/')
major_mock.assert_called_once_with(42)
minor_mock.assert_called_once_with(42)
realpath_mock.assert_called_once_with(
'/dev/disk/by-uuid/81969733-a724-4651-9cf5-64970f86daba')

self.assertEqual(result, {
(9, 0): {
'device':
'/dev/disk/by-uuid/81969733-a724-4651-9cf5-64970f86daba',
'/dev/sda1',
'fs_type': 'ext3',
'mount_point': '/'}
})
Expand Down

0 comments on commit 76f934a

Please sign in to comment.