Add a function to change postgresql.conf in python tests. Add test_config as an example

This commit is contained in:
anastasia
2021-05-13 17:52:31 +03:00
committed by lubennikovaav
parent 97992226d3
commit 7b281900f9
2 changed files with 54 additions and 4 deletions

View File

@@ -126,26 +126,43 @@ def pageserver(zenith_cli):
class Postgres:
""" An object representing a running postgres daemon. """
def __init__(self, zenith_cli):
def __init__(self, zenith_cli, repo_dir):
self.zenith_cli = zenith_cli
self.running = False
self.host = 'localhost'
self.port = 55432
self.repo_dir = repo_dir
# path to conf is <repo_dir>/pgdatadirs/pg1/postgresql.conf
def create_start(self):
def create_start(self, config_lines=None):
""" create the pg data directory, and start the server """
self.zenith_cli.run(['pg', 'create'])
if config_lines is None:
config_lines = []
self.config(config_lines)
# FIXME: where did the name pg1 come from?
self.zenith_cli.run(['pg', 'start', 'pg1'])
self.running = True
#lines should be an array of valid postgresql.conf rows
def config(self, lines):
#TODO use real node name, not just guessed pg1
filename = 'pgdatadirs/pg1/postgresql.conf'
config_name = os.path.join(self.repo_dir, filename)
with open(config_name, 'a') as conf:
for line in lines:
conf.write(line)
conf.write('\n')
def stop(self):
if self.running:
self.zenith_cli.run(['pg', 'stop', 'pg1'])
@zenfixture
def postgres(zenith_cli):
pg = Postgres(zenith_cli)
def postgres(zenith_cli, repo_dir):
pg = Postgres(zenith_cli, repo_dir)
yield pg
# After the yield comes any cleanup code we need.
print('Starting postgres cleanup')

View File

@@ -0,0 +1,33 @@
import pytest
import os
import getpass
import psycopg2
pytest_plugins = ("fixtures.zenith_fixtures")
def test_config(zenith_cli, pageserver, postgres, pg_bin):
zenith_cli.run_init()
pageserver.start()
print('pageserver is running')
# change config
postgres.create_start(['log_min_messages=debug1'])
print('postgres is running')
username = getpass.getuser()
conn_str = 'host={} port={} dbname=postgres user={}'.format(
postgres.host, postgres.port, username)
print('conn_str is', conn_str)
pg_conn = psycopg2.connect(conn_str)
pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cur = pg_conn.cursor()
#check that config change was applied
cur.execute('SELECT name, setting from pg_settings WHERE source!=%s and source!=%s', ("default","override",))
for record in cur:
if record[0] == 'log_min_messages':
assert(record[1] == 'debug1')
pg_conn.close()