def testStatFS(self): f_bsize = 4096 # Simulate pre-2.6 kernel f_frsize = 0 f_blocks = 9743394 f_bfree = 5690052 f_bavail = 5201809 f_files = 2441216 f_ffree = 2074221 f_favail = 2074221 f_flag = 4096 f_namemax = 255 def MockStatFS(unused_path): return posix.statvfs_result( (f_bsize, f_frsize, f_blocks, f_bfree, f_bavail, f_files, f_ffree, f_favail, f_flag, f_namemax)) def MockIsMount(path): """Only return True for the root path.""" return path == "/" with utils.MultiStubber((os, "statvfs", MockStatFS), (os.path, "ismount", MockIsMount)): # This test assumes "/" is the mount point for /usr/bin results = self.RunAction( standard.StatFS, rdf_client.StatFSRequest(path_list=["/usr/bin", "/"])) self.assertEqual(len(results), 2) # Both results should have mount_point as "/" self.assertEqual(results[0].unixvolume.mount_point, results[1].unixvolume.mount_point) result = results[0] self.assertEqual(result.bytes_per_sector, f_bsize) self.assertEqual(result.sectors_per_allocation_unit, 1) self.assertEqual(result.total_allocation_units, f_blocks) self.assertEqual(result.actual_available_allocation_units, f_bavail) self.assertAlmostEqual(result.FreeSpacePercent(), 53.388, delta=0.001) self.assertEqual(result.unixvolume.mount_point, "/") self.assertEqual(result.Name(), "/") # Test we get a result even if one path is bad results = self.RunAction( standard.StatFS, rdf_client.StatFSRequest(path_list=["/does/not/exist", "/"])) self.assertEqual(len(results), 1) self.assertEqual(result.Name(), "/")
def CollectVolumeInfo(self, unused_responses): if self.state.system == "Windows": # No dependencies for WMI deps = artifact_utils.ArtifactCollectorFlowArgs.Dependency.IGNORE_DEPS self.CallFlow( # TODO(user): dependency loop between collectors.py and # filesystem.py. # collectors.ArtifactCollectorFlow.__name__, "ArtifactCollectorFlow", artifact_list=["WMILogicalDisks"], next_state="ProcessWindowsVolumes", dependencies=deps) else: self.CallClient( server_stubs.StatFS, rdf_client.StatFSRequest( path_list=self.args.path_list, pathtype=self.args.pathtype), next_state="ProcessVolumes")