async def _update(self) -> None: try: mon = Mon() df = mon.df() except Exception as e: raise StorageError("error obtaining info from cluster") from e self._state.stats = StorageStatsModel( total=df.stats.total_bytes, available=df.stats.total_avail_bytes, used=df.stats.total_used_bytes, raw_used=df.stats.total_used_raw_bytes, raw_used_ratio=df.stats.total_used_raw_ratio) by_id: Dict[int, StoragePoolModel] = {} by_name: Dict[str, StoragePoolModel] = {} for p in df.pools: pool: StoragePoolModel = StoragePoolModel( id=p.id, name=p.name, stats=StoragePoolStatsModel(used=p.stats.bytes_used, percent_used=p.stats.percent_used, max_available=p.stats.max_avail)) by_id[p.id] = pool by_name[p.name] = pool self._state.pools_by_name = by_name self._state.pools_by_id = by_id
async def main(): await storage.tick() print(await storage.usage()) print(storage.available) print(storage.used) print(storage.total) assert storage.total == storage.used + storage.available mon = Mon() print(mon.df().json(indent=2))
def test_mon_df( ceph_conf_file_fs: Generator[fake_filesystem.FakeFilesystem, None, None], mocker: MockerFixture, get_data_contents: Callable[[str, str], str] ): mon = Mon() mon.call = mocker.MagicMock( return_value=json.loads(get_data_contents(DATA_DIR, 'mon_df_raw.json')) ) res = mon.df() assert res.stats.total_bytes == 0
def test_mon_df( ceph_conf_file_fs: Generator[fake_filesystem.FakeFilesystem, None, None], mocker: MockerFixture, get_data_contents: Callable[[str, str], str], ): from gravel.controllers.orch.ceph import Ceph, Mon ceph = Ceph() mon = Mon(ceph) mon.call = mocker.MagicMock(return_value=json.loads( get_data_contents(DATA_DIR, "mon_df_raw.json"))) res = mon.df() assert res.stats.total_bytes == 0