示例#1
0
 def test_symlink_home(self):
     symlink_path = self.makeFile()
     os.symlink("/foo/bar", symlink_path)
     self.addCleanup(os.remove, symlink_path)
     self.set_mount_points(["/", "/foo"])
     info = get_filesystem_for_path(symlink_path, self.mount_file,
                                    self.statvfs)
     self.assertEqual(info["mount-point"], "/foo")
示例#2
0
 def test_ignore_unreadable_mount_point(self):
     """
     We should ignore mountpoints which are unreadable by the user who
     is logging in.
     """
     self.set_mount_points(["/secret"], read_access=False)
     info = get_filesystem_for_path("/secret", self.mount_file,
                                    self.statvfs)
     self.assertIs(info, None)
示例#3
0
    def run(self):
        main_info = get_filesystem_for_path("/home", self._mounts_file,
                                            self._statvfs)
        if main_info is not None:
            total = main_info["total-space"]
            if total <= 0:
                root_main_info = get_filesystem_for_path(
                    "/", self._mounts_file, self._statvfs)
                if root_main_info is not None:
                    total = root_main_info["total-space"]
                    main_info = root_main_info
            if total <= 0:
                main_usage = "unknown"
            else:
                main_usage = usage(main_info)
            self._sysinfo.add_header("Usage of " + main_info["mount-point"],
                                     main_usage)
        else:
            self._sysinfo.add_header("Usage of /home", "unknown")

        seen_mounts = set()
        seen_devices = set()
        infos = list(get_mount_info(self._mounts_file, self._statvfs))
        infos.sort(key=lambda i: len(i["mount-point"]))
        for info in infos:
            total = info["total-space"]
            mount_seen = info["mount-point"] in seen_mounts
            device_seen = info["device"] in seen_devices
            seen_mounts.add(info["mount-point"])
            seen_devices.add(info["device"])
            if mount_seen or device_seen:
                continue

            if total <= 0:
                # Some "virtual" filesystems have 0 total space. ignore them.
                continue

            used = ((total - info["free-space"]) / total) * 100
            if used >= 85:
                self._sysinfo.add_note("%s is using %s" %
                                       (info["mount-point"], usage(info)))
        return succeed(None)
示例#4
0
 def test_get_filesystem_weird_fs(self):
     self.set_mount_points(["/"], fs='simfs')
     info = get_filesystem_for_path("/home", self.mount_file, self.statvfs)
     self.assertEqual(info["mount-point"], "/")
示例#5
0
 def test_get_filesystem_subpath_not_stupid(self):
     self.set_mount_points(["/", "/ho"])
     info = get_filesystem_for_path("/home", self.mount_file, self.statvfs)
     self.assertEqual(info["mount-point"], "/")
示例#6
0
 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"], "/")
示例#7
0
 def test_get_filesystem_for_path(self):
     self.set_mount_points(["/"])
     info = get_filesystem_for_path("/", self.mount_file, self.statvfs)
     self.assertEqual(info["mount-point"], "/")