Ejemplo n.º 1
0
class TempCluster:
    def __init__(self, build_dir: str):
        self.build_dir = Path(build_dir).resolve()
        assert self.build_dir.exists(), "{} does not exist".format(build_dir)
        assert self.build_dir.is_dir(), "{} is not a directory".format(
            build_dir)
        tmp_dir = self.build_dir.joinpath(
            'tmp', ''.join(
                choice(LocalCluster.valid_letters_for_secret)
                for i in range(16)))
        tmp_dir.mkdir(parents=True)
        self.cluster = LocalCluster(
            tmp_dir, self.build_dir.joinpath('bin', 'fdbserver'),
            self.build_dir.joinpath('bin', 'fdbmonitor'),
            self.build_dir.joinpath('bin', 'fdbcli'))
        self.log = self.cluster.log
        self.etc = self.cluster.etc
        self.data = self.cluster.data
        self.tmp_dir = tmp_dir

    def __enter__(self):
        self.cluster.__enter__()
        self.cluster.create_database()
        return self

    def __exit__(self, xc_type, exc_value, traceback):
        self.cluster.__exit__(xc_type, exc_value, traceback)
        shutil.rmtree(self.tmp_dir)
Ejemplo n.º 2
0
class TempCluster:
    def __init__(self,
                 build_dir: str,
                 process_number: int = 1,
                 port: str = None):
        self.build_dir = Path(build_dir).resolve()
        assert self.build_dir.exists(), "{} does not exist".format(build_dir)
        assert self.build_dir.is_dir(), "{} is not a directory".format(
            build_dir)
        tmp_dir = self.build_dir.joinpath(
            "tmp",
            "".join(
                choice(LocalCluster.valid_letters_for_secret)
                for i in range(16)),
        )
        tmp_dir.mkdir(parents=True)
        self.cluster = LocalCluster(
            tmp_dir,
            self.build_dir.joinpath("bin", "fdbserver"),
            self.build_dir.joinpath("bin", "fdbmonitor"),
            self.build_dir.joinpath("bin", "fdbcli"),
            process_number,
            port=port,
        )
        self.log = self.cluster.log
        self.etc = self.cluster.etc
        self.data = self.cluster.data
        self.tmp_dir = tmp_dir

    def __enter__(self):
        self.cluster.__enter__()
        self.cluster.create_database()
        return self

    def __exit__(self, xc_type, exc_value, traceback):
        self.cluster.__exit__(xc_type, exc_value, traceback)
        shutil.rmtree(self.tmp_dir)

    def close(self):
        self.cluster.__exit__(None, None, None)
        shutil.rmtree(self.tmp_dir)