Beispiel #1
0
def test_set_pool_size(
    ceph_conf_file_fs: Generator[fake_filesystem.FakeFilesystem, None, None],
    mocker: MockerFixture,
):
    from gravel.controllers.orch.ceph import Ceph, Mon

    def argscheck(cls: Any, args: Dict[str, Any]) -> Any:
        assert "prefix" in args
        assert "pool" in args
        assert "var" in args
        assert "val" in args
        assert args["prefix"] == "osd pool set"
        assert args["pool"] == "foobar"
        assert args["var"] in ["size", "min_size"]

        if args["var"] == "size":
            assert args["val"] == "2"
            assert "i_really_mean_it" not in args
        else:
            assert args["var"] == "min_size"
            assert args["val"] == "1"

    mocker.patch.object(
        Mon,
        "call",
        new=argscheck  # type:ignore
    )
    ceph = Ceph()
    mon = Mon(ceph)
    mon.set_pool_size("foobar", 2)
Beispiel #2
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)
Beispiel #3
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)