Skip to content

Commit db221c8

Browse files
committed
Missed helper
1 parent b4d48b0 commit db221c8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/integration/helpers.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,3 +1087,34 @@ async def backup_operations(
10871087
"backup wasn't correctly restored: table 'backup_table_3' exists"
10881088
)
10891089
connection.close()
1090+
1091+
1092+
### Ported Mysql jubilant helpers
1093+
1094+
1095+
def execute_queries_on_unit(
1096+
unit_address: str, username: str, password: str, queries: list[str], database: str
1097+
) -> list:
1098+
"""Execute given PostgreSQL queries on a unit.
1099+
1100+
Args:
1101+
unit_address: The public IP address of the unit to execute the queries on
1102+
username: The PostgreSQL username
1103+
password: The PostgreSQL password
1104+
queries: A list of queries to execute
1105+
database: Database to execute in
1106+
1107+
Returns:
1108+
A list of rows that were potentially queried
1109+
"""
1110+
with (
1111+
psycopg2.connect(
1112+
f"dbname='{database}' user='{username}' host='{unit_address}' password='{password}' connect_timeout=10"
1113+
) as connection,
1114+
connection.cursor() as cursor,
1115+
):
1116+
for query in queries:
1117+
cursor.execute(query)
1118+
output = list(itertools.chain(*cursor.fetchall()))
1119+
1120+
return output

0 commit comments

Comments
 (0)