Python os.statvfs_result() Examples
The following are 14
code examples of os.statvfs_result().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: test_disk.py From landscape-client with GNU General Public License v2.0 | 6 votes |
def set_mount_points(self, points, read_access=True, fs='ext4'): """ This method prepares a fake mounts file containing the mount points specified in the C{points} list of strings. This file can then be used by referencing C{self.mount_file}. If C{read_access} is set to C{False}, then all mount points will yield a permission denied error when inspected. """ self.read_access = read_access content = "\n".join("/dev/sda%d %s %s rw 0 0" % (i, point, fs) for i, point in enumerate(points)) f = open(self.mount_file, "w") f.write(content) f.close() for point in points: self.stat_results[point] = os.statvfs_result( (4096, 0, 1000, 500, 0, 0, 0, 0, 0, 0))
Example #2
Source File: test_disk.py From landscape-client with GNU General Public License v2.0 | 6 votes |
def test_ignore_unmounted_and_virtual_mountpoints(self): """ Make sure autofs and virtual mountpoints are ignored. This is to ensure non-regression on bug #1045374. """ self.read_access = True content = "\n".join(["auto_direct /opt/whatever autofs", "none /run/lock tmpfs", "proc /proc proc", "/dev/sda1 /home ext4"]) f = open(self.mount_file, "w") f.write(content) f.close() self.stat_results["/home"] = os.statvfs_result( (4096, 0, 1000, 500, 0, 0, 0, 0, 0, 0)) result = [x for x in get_mount_info(self.mount_file, self.statvfs)] expected = {"device": "/dev/sda1", "mount-point": "/home", "filesystem": "ext4", "total-space": 3, "free-space": 1} self.assertEqual([expected], result)
Example #3
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_statvfs_result_pickle(self): try: result = os.statvfs(self.fname) except OSError as e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: self.skipTest('os.statvfs() failed with ENOSYS') for proto in range(pickle.HIGHEST_PROTOCOL + 1): p = pickle.dumps(result, proto) self.assertIn(b'statvfs_result', p) if proto < 4: self.assertIn(b'cos\nstatvfs_result\n', p) unpickled = pickle.loads(p) self.assertEqual(result, unpickled)
Example #4
Source File: test_os.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_statvfs_result_pickle(self): try: result = os.statvfs(self.fname) except OSError as e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: self.skipTest('os.statvfs() failed with ENOSYS') for proto in range(pickle.HIGHEST_PROTOCOL + 1): p = pickle.dumps(result, proto) self.assertIn(b'statvfs_result', p) if proto < 4: self.assertIn(b'cos\nstatvfs_result\n', p) unpickled = pickle.loads(p) self.assertEqual(result, unpickled)
Example #5
Source File: test_disk.py From landscape-client with GNU General Public License v2.0 | 5 votes |
def add_mount(self, point, block_size=4096, capacity=1000, unused=1000, fs="ext3", device=None): if device is None: device = "/dev/" + point.replace("/", "_") self.stat_results[point] = os.statvfs_result( (block_size, 0, capacity, unused, 0, 0, 0, 0, 0, 0)) f = open(self.mount_file, "a") f.write("/dev/%s %s %s rw 0 0\n" % (device, point, fs)) f.close()
Example #6
Source File: test_mountinfo.py From landscape-client with GNU General Public License v2.0 | 5 votes |
def statvfs_result_fixture(path): """Fixture for a dummy statvfs_result.""" return os.statvfs_result((4096, 0, mb(1000), mb(100), 0, 0, 0, 0, 0, 0))
Example #7
Source File: test_mountinfo.py From landscape-client with GNU General Public License v2.0 | 5 votes |
def get_mount_info(self, *args, **kwargs): if "mounts_file" not in kwargs: kwargs["mounts_file"] = self.makeFile("/dev/hda1 / ext3 rw 0 0\n") if "mtab_file" not in kwargs: kwargs["mtab_file"] = self.makeFile("/dev/hda1 / ext3 rw 0 0\n") if "statvfs" not in kwargs: kwargs["statvfs"] = lambda path: os.statvfs_result( (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) plugin = MountInfo(*args, **kwargs) # To make sure tests are isolated from the real system by default. plugin.is_device_removable = lambda x: False return plugin
Example #8
Source File: test_mountinfo.py From landscape-client with GNU General Public License v2.0 | 5 votes |
def test_read_changing_total_space(self): """ Total space measurements are only sent when (a) none have ever been sent, or (b) the value has changed since the last time data was collected. The test sets the mount info plugin interval to the same value as the step size and advances the reactor such that the plugin will be run twice. Each time it runs it gets a different value from our sample statvfs() function which should cause it to queue new messages. """ counter = mock_counter(1) def statvfs(path, multiplier=lambda: next(counter)): return os.statvfs_result( (4096, 0, mb(multiplier() * 1000), mb(100), 0, 0, 0, 0, 0, 0)) plugin = self.get_mount_info( statvfs=statvfs, create_time=self.reactor.time, interval=self.monitor.step_size) self.monitor.add(plugin) self.reactor.advance(self.monitor.step_size * 2) message = plugin.create_mount_info_message() mount_info = message["mount-info"] self.assertEqual(len(mount_info), 2) for i, total_space in enumerate([4096000, 8192000]): self.assertEqual(mount_info[i][0], (i + 1) * self.monitor.step_size) self.assertEqual(mount_info[i][1], {"device": "/dev/hda1", "filesystem": "ext3", "mount-point": "/", "total-space": total_space})
Example #9
Source File: test_disk.py From landscape-client with GNU General Public License v2.0 | 5 votes |
def test_get_filesystem_subpath(self): self.set_mount_points(["/"]) self.stat_results["/"] = os.statvfs_result( (4096, 0, 1000, 500, 0, 0, 0, 0, 0, 0)) info = get_filesystem_for_path("/home", self.mount_file, self.statvfs) self.assertEqual(info["mount-point"], "/")
Example #10
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_statvfs_result_pickle(self): try: result = os.statvfs(self.fname) except OSError as e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: self.skipTest('os.statvfs() failed with ENOSYS') for proto in range(pickle.HIGHEST_PROTOCOL + 1): p = pickle.dumps(result, proto) self.assertIn(b'statvfs_result', p) if proto < 4: self.assertIn(b'cos\nstatvfs_result\n', p) unpickled = pickle.loads(p) self.assertEqual(result, unpickled)
Example #11
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def test_statvfs_attributes(self): try: result = os.statvfs(self.fname) except OSError as e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: self.skipTest('os.statvfs() failed with ENOSYS') # Make sure direct access works self.assertEqual(result.f_bfree, result[3]) # Make sure all the attributes are there. members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree', 'favail', 'flag', 'namemax') for value, member in enumerate(members): self.assertEqual(getattr(result, 'f_' + member), result[value]) # Make sure that assignment really fails try: result.f_bfree = 1 self.fail("No exception raised") except AttributeError: pass try: result.parrot = 1 self.fail("No exception raised") except AttributeError: pass # Use the constructor with a too-short tuple. try: result2 = os.statvfs_result((10,)) self.fail("No exception raised") except TypeError: pass # Use the constructor with a too-long tuple. try: result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) except TypeError: pass
Example #12
Source File: test_os.py From ironpython3 with Apache License 2.0 | 4 votes |
def test_statvfs_attributes(self): try: result = os.statvfs(self.fname) except OSError as e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: self.skipTest('os.statvfs() failed with ENOSYS') # Make sure direct access works self.assertEqual(result.f_bfree, result[3]) # Make sure all the attributes are there. members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree', 'favail', 'flag', 'namemax') for value, member in enumerate(members): self.assertEqual(getattr(result, 'f_' + member), result[value]) # Make sure that assignment really fails try: result.f_bfree = 1 self.fail("No exception raised") except AttributeError: pass try: result.parrot = 1 self.fail("No exception raised") except AttributeError: pass # Use the constructor with a too-short tuple. try: result2 = os.statvfs_result((10,)) self.fail("No exception raised") except TypeError: pass # Use the constructor with a too-long tuple. try: result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) except TypeError: pass
Example #13
Source File: test_mountinfo.py From landscape-client with GNU General Public License v2.0 | 4 votes |
def test_read_disjointed_changing_total_space(self): """ Total space measurements are only sent when (a) none have ever been sent, or (b) the value has changed since the last time data was collected. This test ensures that the (b) criteria is checked per-mount point. The sample statvfs() function only provides changing total space for /; therefore, new messages should only be queued for / after the first message is created. """ counter = mock_counter(1) def statvfs(path, multiplier=lambda: next(counter)): if path == "/": return os.statvfs_result( (4096, 0, mb(1000), mb(100), 0, 0, 0, 0, 0, 0)) return os.statvfs_result( (4096, 0, mb(multiplier() * 1000), mb(100), 0, 0, 0, 0, 0, 0)) filename = self.makeFile("""\ /dev/hda1 / ext3 rw 0 0 /dev/hde1 /mnt/hde1 ext3 rw 0 0 """) plugin = self.get_mount_info(mounts_file=filename, statvfs=statvfs, create_time=self.reactor.time, interval=self.monitor.step_size, mtab_file=filename) self.monitor.add(plugin) self.reactor.advance(self.monitor.step_size * 2) message = plugin.create_mount_info_message() self.assertTrue(message) mount_info = message.get("mount-info", ()) self.assertEqual(len(mount_info), 3) self.assertEqual(mount_info[0][0], self.monitor.step_size) self.assertEqual(mount_info[0][1], {"device": "/dev/hda1", "mount-point": "/", "filesystem": "ext3", "total-space": 4096000}) self.assertEqual(mount_info[1][0], self.monitor.step_size) self.assertEqual(mount_info[1][1], {"device": "/dev/hde1", "mount-point": "/mnt/hde1", "filesystem": "ext3", "total-space": 4096000}) self.assertEqual(mount_info[2][0], self.monitor.step_size * 2) self.assertEqual(mount_info[2][1], {"device": "/dev/hde1", "mount-point": "/mnt/hde1", "filesystem": "ext3", "total-space": 8192000})
Example #14
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def test_statvfs_attributes(self): try: result = os.statvfs(self.fname) except OSError as e: # On AtheOS, glibc always returns ENOSYS if e.errno == errno.ENOSYS: self.skipTest('os.statvfs() failed with ENOSYS') # Make sure direct access works self.assertEqual(result.f_bfree, result[3]) # Make sure all the attributes are there. members = ('bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree', 'favail', 'flag', 'namemax') for value, member in enumerate(members): self.assertEqual(getattr(result, 'f_' + member), result[value]) # Make sure that assignment really fails try: result.f_bfree = 1 self.fail("No exception raised") except AttributeError: pass try: result.parrot = 1 self.fail("No exception raised") except AttributeError: pass # Use the constructor with a too-short tuple. try: result2 = os.statvfs_result((10,)) self.fail("No exception raised") except TypeError: pass # Use the constructor with a too-long tuple. try: result2 = os.statvfs_result((0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)) except TypeError: pass