Beispiel #1
0
def _init_cluster(data_dir=None, *, cleanup_atexit=True, init_settings=None):
    if init_settings is None:
        init_settings = {}
    if (not os.environ.get('EDGEDB_DEBUG_SERVER')
            and not os.environ.get('EDGEDB_LOG_LEVEL')):
        _env = {'EDGEDB_LOG_LEVEL': 'silent'}
    else:
        _env = {}

    if data_dir is None:
        cluster = edgedb_cluster.TempCluster(env=_env, testmode=True)
        destroy = True
    else:
        cluster = edgedb_cluster.Cluster(data_dir=data_dir, env=_env)
        destroy = False

    if cluster.get_status() == 'not-initialized':
        cluster.init(server_settings=init_settings)

    cluster.start(port='dynamic')
    cluster.set_superuser_password('test')

    if cleanup_atexit:
        atexit.register(_shutdown_cluster, cluster, destroy=destroy)

    return cluster
Beispiel #2
0
def main():
    tests_dir, data_dir, jobs = parse_connect_args()

    if os.path.exists(data_dir):
        if not os.path.isdir(data_dir):
            die(f'{data_dir!r} exists and is not a directory')
        if os.listdir(data_dir):
            die(f'{data_dir!r} exists and is not empty')

    if not jobs:
        jobs = os.cpu_count()

    cluster = edgedb_cluster.Cluster(data_dir)
    print(f'Bootstrapping test EdgeDB instance in {data_dir}...')

    try:
        cluster.init()
        cluster.start(port='dynamic', timezone='UTC')
    except BaseException:
        if os.path.exists(data_dir):
            shutil.rmtree(data_dir)
        raise

    servers, conns = tb.start_worker_servers(cluster, num_workers=jobs)
    destroy_cluster = False

    try:
        execute(tests_dir, conns)
        print(f'Initialized and populated test EdgeDB instance in {data_dir}')
    except BaseException:
        destroy_cluster = True
        raise
    finally:
        tb.shutdown_worker_servers(servers, destroy=destroy_cluster)
Beispiel #3
0
def gen_test_dumps(*, jobs, tests_dir):
    version = str(buildmeta.get_version())
    if not jobs:
        jobs = os.cpu_count()

    with tempfile.TemporaryDirectory(dir="/tmp/",
                                     prefix="edb_gen-test-dumps_") as data_dir:
        cluster = edgedb_cluster.Cluster(data_dir, testmode=True)
        print(f"Generating test dumps for version {version}"
              f" with a temporary EdgeDB instance in {data_dir}...")

        try:
            cluster.init()
            cluster.start(port=0)
            cluster.trust_local_connections()
        except BaseException:
            raise

        conn = cluster.get_connect_args()
        try:
            execute(tests_dir, conn, num_workers=jobs, version=version)
        except BaseException:
            raise
        finally:
            cluster.stop()
            cluster.destroy()
Beispiel #4
0
def inittestdb(*, data_dir, jobs, tests_dir, include):
    if os.path.exists(data_dir):
        if not os.path.isdir(data_dir):
            die(f'{data_dir!r} exists and is not a directory')
        if os.listdir(data_dir):
            die(f'{data_dir!r} exists and is not empty')

    if not jobs:
        jobs = os.cpu_count()

    cluster = edgedb_cluster.Cluster(data_dir, testmode=True)
    print(f'Bootstrapping test EdgeDB instance in {data_dir}...')

    try:
        cluster.init()
        cluster.start(port=0)
        cluster.trust_local_connections()
    except BaseException:
        if os.path.exists(data_dir):
            shutil.rmtree(data_dir)
        raise

    conn = cluster.get_connect_args()
    destroy_cluster = False

    try:
        execute(tests_dir, conn, num_workers=jobs, include=include)
        print(f'Initialized and populated test EdgeDB instance in {data_dir}')
    except BaseException:
        destroy_cluster = True
        raise
    finally:
        cluster.stop()
        if destroy_cluster:
            cluster.destroy()
Beispiel #5
0
def _init_cluster(data_dir=None, *, pg_cluster=None,
                  cleanup_atexit=True, init_settings={}):
    if (not os.environ.get('EDGEDB_DEBUG_SERVER') and
            not os.environ.get('EDGEDB_LOG_LEVEL')):
        _env = {'EDGEDB_LOG_LEVEL': 'silent'}
    else:
        _env = {}

    if data_dir is None:
        cluster = edgedb_cluster.TempCluster(env=_env)
        destroy = True
    else:
        cluster = edgedb_cluster.Cluster(
            data_dir=data_dir, postgres_cluster=pg_cluster, env=_env)
        destroy = False

    if cluster.get_status() == 'not-initialized':
        cluster.init(server_settings=init_settings)

    cluster.start(port='dynamic', timezone='UTC')

    if cleanup_atexit:
        atexit.register(_shutdown_cluster, cluster, destroy=destroy)

    return cluster
Beispiel #6
0
def main(args, env):
    """Initialize EdgeDB database cluster."""
    if args.data_dir:
        cluster = edgedb_cluster.Cluster(args.data_dir,
                                         port='dynamic',
                                         env=env)
        cluster.init()
Beispiel #7
0
    def test_ctl_init_1(self):
        data_dir = tempfile.mkdtemp(prefix='edgedbtest-')
        conn = cluster = None

        try:
            env = {'EDGEDB_LOG_LEVEL': 'silent'}

            ctl.main(['-D', data_dir, 'init'], env=env)

            cluster = edgedb_cluster.Cluster(data_dir, port='dynamic', env=env)
            cluster_status = cluster.get_status()

            self.assertEqual(cluster_status, 'stopped')

            cluster.start()

            cluster_status = cluster.get_status()

            self.assertEqual(cluster_status, 'running')

        finally:
            if conn is not None:
                conn.close()

            if cluster is not None:
                cluster.stop()
                cluster.destroy()

            shutil.rmtree(data_dir, ignore_errors=True)
Beispiel #8
0
async def _inittestdb(
    *,
    jobs: int,
    data_dir: str,
    tests_dir: str,
    include: List[str],
) -> None:
    cluster = edgedb_cluster.Cluster(pathlib.Path(data_dir), testmode=True)
    print(f'Bootstrapping test EdgeDB instance in {data_dir}...')

    try:
        await cluster.init()
        await cluster.start(port=0)
        await cluster.trust_local_connections()
    except BaseException:
        if os.path.exists(data_dir):
            shutil.rmtree(data_dir)
        raise

    conn = cluster.get_connect_args()
    destroy_cluster = False

    try:
        await execute(tests_dir, conn, num_workers=jobs, include=include)
        print(f'Initialized and populated test EdgeDB instance in {data_dir}')
    except BaseException:
        destroy_cluster = True
        raise
    finally:
        cluster.stop()
        if destroy_cluster:
            cluster.destroy()
Beispiel #9
0
def main():
    args = parse_connect_args()

    if args.start_server:
        cluster = edgedb_cluster.Cluster(args.server_dir)
        if cluster.get_status() == 'not-initialized':
            cluster.init()
        cluster.start(port=args.port, timezone='UTC')
        atexit.register(cluster.stop)

    if args.background_cmd:
        env = os.environ.copy()
        if args.host:
            env['EDGEDB_HOST'] = args.host
        if args.port:
            env['EDGEDB_PORT'] = args.port

        background_cmd = subprocess.Popen(
            args.background_cmd,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
            preexec_fn=edgedb_cluster.ensure_dead_with_parent,
            env=env,
            shell=True)

        atexit.register(background_cmd.terminate)

    connect_kwargs = {
        'user': args.user,
        'password': args.password,
        'database': args.database,
        'host': args.host,
        'port': args.port,
        'timeout': args.timeout,
        'retry_on_failure': args.retry_conn,
    }

    if select.select([sys.stdin], [], [], 0.0)[0]:
        data = sys.stdin.read()

        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        try:
            loop.run_until_complete(execute(connect_kwargs, data))
        finally:
            loop.close()
            asyncio.set_event_loop(None)

        return

    Cli(connect_kwargs).run()
Beispiel #10
0
async def _gen_test_dumps(*, jobs: int, tests_dir: str, data_dir: str) -> None:
    version = str(buildmeta.get_version())
    cluster = edgedb_cluster.Cluster(pathlib.Path(data_dir), testmode=True)
    print(f"Generating test dumps for version {version}"
          f" with a temporary EdgeDB instance in {data_dir}...")

    try:
        await cluster.init()
        await cluster.start(port=0)
        await cluster.trust_local_connections()
    except BaseException:
        raise

    conn = cluster.get_connect_args()
    try:
        execute(tests_dir, conn, num_workers=jobs, version=version)
    except BaseException:
        raise
    finally:
        cluster.stop()
        cluster.destroy()