Beispiel #1
0
    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)
Beispiel #2
0
    def _get_mount_info(self):
        """Generator yields local mount points worth recording data for."""
        bound_mount_points = self._get_bound_mount_points()

        for info in get_mount_info(self._mounts_file, self._statvfs):
            device = info["device"]
            mount_point = info["mount-point"]
            if (device.startswith("/dev/") and
                not mount_point.startswith("/dev/") and
                not self.is_device_removable(device) and
                not mount_point in bound_mount_points):
                yield info
Beispiel #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)