Skip to content
Snippets Groups Projects
Commit 4a21b4e8 authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

change(test_postgresql): return message on replication check

parent 1b65a39d
No related branches found
No related tags found
No related merge requests found
......@@ -232,7 +232,7 @@ def check_psql(db_conn: dict, query: str) -> bool:
return True
def check_replication(primary: dict, standby: dict) -> bool:
def check_replication(primary: dict, standby: dict) -> tuple:
"""Check if replication is working between the primary and standby servers.
:param primary: Database connection parameters for primary server
......@@ -240,7 +240,7 @@ def check_replication(primary: dict, standby: dict) -> bool:
:param standby: Database connection parameters for standby server
:type standby: dict
:return: Wether replication between primary/stanbdy is working or not
:rtype: bool
:rtype: tuple
"""
# connections
......@@ -248,8 +248,8 @@ def check_replication(primary: dict, standby: dict) -> bool:
primary_client = psycopg2.connect(**primary)
standby_client = psycopg2.connect(**standby)
except psycopg2.Error:
error("Cannot connect to the databases")
return False
msg = "connection error"
return False, msg
# random id
rand = uuid.uuid4().hex
......@@ -262,7 +262,8 @@ def check_replication(primary: dict, standby: dict) -> bool:
primary_psql = primary_client.cursor()
primary_psql.execute(write_query)
except psycopg2.Error:
return False
msg = "write error"
return False, msg
# read
max_time = 6.0
......@@ -273,11 +274,13 @@ def check_replication(primary: dict, standby: dict) -> bool:
try:
standby_psql = primary_client.cursor()
standby_psql.execute(read_query)
msg = "took ~{}s".format(str(timer))
break
except psycopg2.Error:
pass
else:
return False
msg = "read error"
return False, msg
# delete
try:
......@@ -291,7 +294,7 @@ def check_replication(primary: dict, standby: dict) -> bool:
primary_client.close()
standby_client.close()
return True
return True, msg
def check_ha(db_conn: dict, errors: int = 0) -> int:
......@@ -350,11 +353,12 @@ def check_ha(db_conn: dict, errors: int = 0) -> int:
primary["port"] = 54321
standby = db_conn
standby["port"] = 54322
if not check_replication(primary, standby):
error("Cannot replicate data between primary/standby")
status, info = check_replication(primary, standby)
if not status:
error("Cannot replicate data between primary/standby: {}".format(info))
errors += 1
else:
success("Can replicate data between primary/standby")
success("Can replicate data between primary/standby: {}".format(info))
return errors
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment