def _create_cephfs(self, svc: ServiceModel) -> None: cephfs = CephFS() try: cephfs.create(svc.name) except CephFSError as e: raise ServiceError("unable to create cephfs service") from e try: fs: CephFSListEntryModel = cephfs.get_fs_info(svc.name) except CephFSError as e: raise ServiceError("unable to list cephfs filesystems") from e assert fs.name == svc.name mon = Mon() pools: List[CephOSDPoolEntryModel] = mon.get_pools() def get_pool(name: str) -> CephOSDPoolEntryModel: for pool in pools: if pool.pool_name == name: return pool raise ServiceError(f"unknown pool {name}") metadata_pool = get_pool(fs.metadata_pool) if metadata_pool.size != svc.replicas: mon.set_pool_size(metadata_pool.pool_name, svc.replicas) svc.pools.append(metadata_pool.pool) for name in fs.data_pools: data_pool = get_pool(name) if data_pool.size != svc.replicas: mon.set_pool_size(data_pool.pool_name, svc.replicas) svc.pools.append(data_pool.pool)
def test_get_pools( 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_osdmap_raw.json')) ) res = mon.get_pools() assert len(res) == 0
def test_get_pools( 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_osdmap_raw.json"))) res = mon.get_pools() assert len(res) == 0
def _create_cephfs(self, svc: ServiceModel) -> None: cephfs = CephFS() try: cephfs.create(svc.name) except CephFSError as e: raise ServiceError("unable to create cephfs service") from e try: fs: CephFSListEntryModel = cephfs.get_fs_info(svc.name) except CephFSError as e: raise ServiceError("unable to list cephfs filesystems") from e assert fs.name == svc.name mon = Mon() pools: List[CephOSDPoolEntryModel] = mon.get_pools() def get_pool(name: str) -> CephOSDPoolEntryModel: for pool in pools: if pool.pool_name == name: return pool raise ServiceError(f"unknown pool {name}") metadata_pool = get_pool(fs.metadata_pool) if metadata_pool.size != svc.replicas: mon.set_pool_size(metadata_pool.pool_name, svc.replicas) svc.pools.append(metadata_pool.pool) for name in fs.data_pools: data_pool = get_pool(name) if data_pool.size != svc.replicas: mon.set_pool_size(data_pool.pool_name, svc.replicas) svc.pools.append(data_pool.pool) # create cephfs default user logger.debug("authorize default user") try: cephfs.authorize(svc.name, "default") logger.info(f"created cephfs client for service '{svc.name}'") except CephFSError as e: logger.error(f"Unable to authorize cephfs client: {str(e)}") logger.exception(e)
# project aquarium's backend # Copyright (C) 2021 SUSE, LLC. from gravel.controllers.orch.ceph import Mon if __name__ == "__main__": mon = Mon() print(mon.get_osdmap()) print(mon.get_pools()) pass