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

change(test_postgresql): output and format

parent e1ed8a76
No related branches found
No related tags found
No related merge requests found
...@@ -298,10 +298,10 @@ def check_ha(db_conn: dict, errors: int = 0) -> int: ...@@ -298,10 +298,10 @@ def check_ha(db_conn: dict, errors: int = 0) -> int:
node_host = nodes[node]["host"] node_host = nodes[node]["host"]
node_port = nodes[node]["port"] node_port = nodes[node]["port"]
if not check_listen(node_host, node_port): if not check_listen(node_host, node_port):
u.error("Cannot bind {}:{}".format(node_host, node_port)) u.error("cannot bind {}:{}".format(node_host, node_port))
errors += 1 errors += 1
else: else:
u.success("Can bind {}:{}".format(node_host, node_port)) u.success("can bind {}:{}".format(node_host, node_port))
# check fenced # check fenced
print("Checking cluster state:") print("Checking cluster state:")
...@@ -320,10 +320,10 @@ def check_ha(db_conn: dict, errors: int = 0) -> int: ...@@ -320,10 +320,10 @@ def check_ha(db_conn: dict, errors: int = 0) -> int:
standby["port"] = 54322 standby["port"] = 54322
status, info = check_replication(primary, standby) status, info = check_replication(primary, standby)
if not status: if not status:
u.error("Cannot replicate between primary/standby ({})".format(info)) u.error("cannot replicate between primary/standby ({})".format(info))
errors += 1 errors += 1
else: else:
u.success("Can replicate between primary/standby ({})".format(info)) u.success("can replicate between primary/standby ({})".format(info))
return errors return errors
...@@ -346,20 +346,20 @@ def check_local(db_conn: dict, errors: int = 0) -> int: ...@@ -346,20 +346,20 @@ def check_local(db_conn: dict, errors: int = 0) -> int:
# check listen # check listen
print("Checking local PostgreSQL node:") print("Checking local PostgreSQL node:")
if not check_listen(host, port): if not check_listen(host, port):
u.error("Cannot connect to {}:{}".format(host, port)) u.error("cannot connect to {}:{}".format(host, port))
errors += 1 errors += 1
else: else:
u.success("Can connect to {}:{}".format(host, port)) u.success("can connect to {}:{}".format(host, port))
# check read # check read
print("Checking read operation:") print("Checking read operation:")
read_query = "SELECT 1;" read_query = "SELECT 1;"
status, info = check_psql(db_conn, read_query) status, info = check_psql(db_conn, read_query)
if not status: if not status:
u.error("Cannot read from {}@{}:{} ({})".format(user, host, port, info)) u.error("cannot read from {}@{}:{} ({})".format(user, host, port, info))
errors += 1 errors += 1
else: else:
u.success("Can read from {}@{}:{}".format(user, host, port)) u.success("can read from {}@{}:{}".format(user, host, port))
# check write # check write
print("Checking write operation:") print("Checking write operation:")
...@@ -367,10 +367,10 @@ def check_local(db_conn: dict, errors: int = 0) -> int: ...@@ -367,10 +367,10 @@ def check_local(db_conn: dict, errors: int = 0) -> int:
write_query = "CREATE TABLE es_test_{} (id serial PRIMARY KEY);".format(rand) write_query = "CREATE TABLE es_test_{} (id serial PRIMARY KEY);".format(rand)
status, info = check_psql(db_conn, write_query) status, info = check_psql(db_conn, write_query)
if not status: if not status:
u.error("Cannot write on {}@{}:{} ({})".format(user, host, port, info)) u.error("cannot write on {}@{}:{} ({})".format(user, host, port, info))
errors += 1 errors += 1
else: else:
u.success("Can write on {}@{}:{}".format(user, host, port)) u.success("can write on {}@{}:{}".format(user, host, port))
# remove test table # remove test table
check_psql(db_conn, "DROP TABLE es_test_{};".format(rand)) check_psql(db_conn, "DROP TABLE es_test_{};".format(rand))
...@@ -393,11 +393,12 @@ def main(): ...@@ -393,11 +393,12 @@ def main():
db_conn.update({"password": db_pass}) db_conn.update({"password": db_pass})
# determine if HA setup and run according tests # determine if HA setup and run according tests
print("Checking availibility mode:")
if is_ha(db_port): if is_ha(db_port):
print("This setup is using a HA database") u.info("this setup is using a HA database")
errors = check_ha(db_conn) errors = check_ha(db_conn)
else: else:
print("This setup is using a local database") u.info("this setup is using a local database")
errors = check_local(db_conn) errors = check_local(db_conn)
if errors: if 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