class MountpointStats(StatsParser):
    """Stats for filesystems

    Uses systematic.MountPoints to parse filesystem stats
    """
    parser_name = 'filesystems'

    def __init__(self):
        super(MountpointStats, self).__init__()
        self.mountpoints = MountPoints()
        self.update_timestamp()

    def update(self):
        """Update filesystems

        """
        self.mountpoints.update()
        return self.update_timestamp()

    def to_json(self, verbose=True):
        """Return JSON data

        """
        if self.__updated__ is None:
            self.update()
        return json.dumps(
            {
                'timestamp':
                self.__updated__,
                'filesystems':
                [mp.as_dict(verbose=verbose) for mp in self.mountpoints],
            },
            indent=2,
        )
 def test1_list_mountpoints(self):
     """
     Test listing mount points on this platform
     """
     try:
         mp = MountPoints()
         self.assertIsInstance(mp.keys(), list)
     except FileSystemError, emsg:
         print emsg
         return
Beispiel #3
0
    def test1_list_mountpoints(self):

        """
        Test listing mount points on this platform
        """
        try:
            mp = MountPoints()
            self.assertIsInstance(mp.keys(), list)
        except FileSystemError as e:
            print('Error listing mountpoints: {0}'.format(e))
            return
    def test1_list_mountpoints(self):

        """
        Test listing mount points on this platform
        """
        try:
            mp = MountPoints()
            self.assertIsInstance(mp.keys(), list)
        except FileSystemError, emsg:
            print emsg
            return
def test_mountpoint_sorting(platform_mock_binaries):
    """Test sorting of mountpoints

    """
    from systematic.filesystems import MountPoints
    mounts = MountPoints()

    values = sorted(mp for mp in mounts)
    assert len(values) == len(mounts)

    mounts.sort()
    for i, mp in enumerate(mounts):
        assert mp == values[i]
Beispiel #6
0
def test_mountpoint_sorting(platform_mock_binaries):
    """Test sorting of mountpoints

    """
    from systematic.filesystems import MountPoints
    mounts = MountPoints()

    values = sorted(mp for mp in mounts)
    assert len(values) == len(mounts)

    mounts.sort()
    for i, mp in enumerate(mounts):
        assert mp == values[i]
 def test2_check_mounpoint_type(self):
     """
     Check object type of returned filesystems
     """
     try:
         mp = MountPoints()
     except FileSystemError, emsg:
         print emsg
         return
def test_mountpoint_attributes(platform_mock_binaries):
    """Test mountpoint attributes

    """

    from systematic.filesystems import MountPoints
    from systematic.classes import MountPoint

    mounts = MountPoints()
    assert len(mounts) > 0

    for mp in mounts:
        assert isinstance(mp, MountPoint)

        assert isinstance(mp.path, str)
        assert isinstance(mp.name, str)

        assert isinstance(mp.usage, dict)
        assert isinstance(mp.flags, dict)

        assert isinstance(mp.size, int)
        assert isinstance(mp.used, int)
        assert isinstance(mp.available, int)
        assert isinstance(mp.free, int)
        assert isinstance(mp.percent, int)

        assert isinstance(mp.as_dict(), dict)
        json.dumps(mp.as_dict())

        # Only available with MacOS (darwin) ps output
        if hasattr(mp, 'blocksize'):
            assert isinstance(mp.blocksize, int)
        for attr in ('internal', 'writable', 'bootable', 'ejectable',
                     'removable'):
            if hasattr(mp, attr):
                assert isinstance(getattr(mp, attr), bool)
 def __init__(self):
     super(MountpointStats, self).__init__()
     self.mountpoints = MountPoints()
     self.update_timestamp()