Files
neon/test_runner/batch_others/test_import.py
Bojan Serafimov 1380a1cce1 Pass lsn
2022-06-09 12:39:29 -04:00

82 lines
3.1 KiB
Python

from fixtures.neon_fixtures import NeonEnvBuilder
from uuid import UUID
import tarfile
import os
import shutil
from pathlib import Path
def test_import(neon_env_builder,
port_distributor,
default_broker,
mock_s3_server,
test_output_dir,
pg_bin):
"""Move a timeline to a new neon stack using pg_basebackup as interface."""
node_name = "test_import"
source_repo_dir = Path(test_output_dir) / "source_repo"
destination_repo_dir = Path(test_output_dir) / "destination_repo"
basebackup_dir = Path(test_output_dir) / "basebackup"
basebackup_tar_path = Path(test_output_dir) / "basebackup.tar"
os.mkdir(basebackup_dir)
# Create a repo, put some data in, take basebackup, and shut it down
with NeonEnvBuilder(source_repo_dir, port_distributor, default_broker, mock_s3_server) as builder:
# Insert data
env = builder.init_start()
env.neon_cli.create_branch(node_name)
pg = env.postgres.create_start(node_name)
pg.safe_psql("create table t as select generate_series(1,300000)")
assert pg.safe_psql('select count(*) from t') == [(300000, )]
# Get basebackup
lsn = pg.safe_psql('select pg_current_wal_flush_lsn()')[0][0]
tenant = pg.safe_psql("show neon.tenant_id")[0][0]
timeline = pg.safe_psql("show neon.timeline_id")[0][0]
timeline_dir = source_repo_dir / "tenants" / tenant / "timelines" / timeline
pg_bin.run(["pg_basebackup", "-d", pg.connstr(), "-D", str(basebackup_dir)])
# Pack basebackup into tar file (uncompressed)
with tarfile.open(basebackup_tar_path, "w") as tf:
# TODO match iteration order to what pageserver would do
tf.add(basebackup_dir)
# Remove timeline
# env.pageserver.stop()
# shutil.rmtree(timeline_dir)
env.pageserver.http_client().timeline_detach(UUID(tenant), UUID(timeline))
# env.neon_cli.create_tenant(UUID(tenant))
env.neon_cli.raw_cli([
"timeline",
"import",
"--tenant-id", tenant,
"--timeline-id", timeline,
"--node-name", node_name,
"--tarfile", str(basebackup_tar_path),
"--lsn", lsn,
])
# pg = env.postgres.create_start(node_name, tenant_id=UUID(tenant))
assert pg.safe_psql('select count(*) from t') == [(300000, )]
# XXX
return
# Create a new repo, load the basebackup into it, and check that data is there
with NeonEnvBuilder(destination_repo_dir, port_distributor, default_broker, mock_s3_server) as builder:
env = builder.init_start()
env.neon_cli.create_tenant(UUID(tenant))
env.neon_cli.raw_cli([
"timeline",
"import",
"--tenant-id", tenant,
"--timeline-id", timeline,
"--node-name", node_name,
"--tarfile", basebackup_tar_path,
])
pg = env.postgres.create_start(node_name, tenant_id=UUID(tenant))
assert pg.safe_psql('select count(*) from t') == [(300000, )]