Esempio n. 1
0
def _get_local_hdd_info_gb():
    path = pathutils.instance_dir(action=constants.PATH_CREATE)
    drive = os.path.splitdrive(path)[0] or path
    usage = hostutils.disk_usage(drive)

    total_gb = usage.total / units.Gi
    free_gb = usage.free / units.Gi
    used_gb = usage.used / units.Gi
    return (total_gb, free_gb, used_gb)
Esempio n. 2
0
def _get_local_hdd_info_gb():
    path = pathutils.instance_dir(action=constants.PATH_CREATE)
    drive = os.path.splitdrive(path)[0] or path
    usage = hostutils.disk_usage(drive)

    total_gb = usage.total / units.Gi
    free_gb = usage.free / units.Gi
    used_gb = usage.used / units.Gi
    return (total_gb, free_gb, used_gb)
    def test_disk_usage_windows(self, mock_system, mock_ctype):
        response = collections.namedtuple('response', 'value')

        mock_system.return_value = 'Windows'
        mock_ctype.c_ulonglong.side_effect = [response(self._FAKE_FREE),
                                              response(self._FAKE_TOTAL)]
        disk_usage = hostutils.disk_usage('C:')

        self.assertEqual(self._FAKE_TOTAL, disk_usage.total)
        self.assertEqual(self._FAKE_FREE, disk_usage.free)
        self.assertEqual(self._FAKE_USED, disk_usage.used)
Esempio n. 4
0
    def test_disk_usage_windows(self, mock_system, mock_ctype):
        response = collections.namedtuple('response', 'value')

        mock_system.return_value = 'Windows'
        mock_ctype.c_ulonglong.side_effect = [
            response(self._FAKE_FREE),
            response(self._FAKE_TOTAL)
        ]
        disk_usage = hostutils.disk_usage('C:')

        self.assertEqual(self._FAKE_TOTAL, disk_usage.total)
        self.assertEqual(self._FAKE_FREE, disk_usage.free)
        self.assertEqual(self._FAKE_USED, disk_usage.used)
    def test_disk_usage_linux(self, mock_system, mock_statvfs):
        mock_system.return_value = 'Linux'
        mock_statvfs_response = mock.MagicMock()
        mock_statvfs_response.f_bavail = self._FAKE_FREE
        mock_statvfs_response.f_frsize = 1
        mock_statvfs_response.f_blocks = self._FAKE_TOTAL
        mock_statvfs_response.f_bfree = self._FAKE_FREE
        mock_statvfs.return_value = mock_statvfs_response
        disk_usage = hostutils.disk_usage(mock.sentinel.path)

        mock_statvfs.assert_called_once_with(mock.sentinel.path)
        self.assertEqual(self._FAKE_TOTAL, disk_usage.total)
        self.assertEqual(self._FAKE_FREE, disk_usage.free)
        self.assertEqual(self._FAKE_USED, disk_usage.used)
Esempio n. 6
0
    def test_disk_usage_linux(self, mock_system, mock_statvfs):
        mock_system.return_value = 'Linux'
        mock_statvfs_response = mock.MagicMock()
        mock_statvfs_response.f_bavail = self._FAKE_FREE
        mock_statvfs_response.f_frsize = 1
        mock_statvfs_response.f_blocks = self._FAKE_TOTAL
        mock_statvfs_response.f_bfree = self._FAKE_FREE
        mock_statvfs.return_value = mock_statvfs_response
        disk_usage = hostutils.disk_usage(mock.sentinel.path)

        mock_statvfs.assert_called_once_with(mock.sentinel.path)
        self.assertEqual(self._FAKE_TOTAL, disk_usage.total)
        self.assertEqual(self._FAKE_FREE, disk_usage.free)
        self.assertEqual(self._FAKE_USED, disk_usage.used)