Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions container_ci_suite/engines/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
import re
import subprocess
import time
from typing import Optional, Literal, Union
from typing import Optional, Literal, Union, Dict
from enum import Enum
from urllib.parse import quote, urlencode

from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper

Expand Down Expand Up @@ -410,6 +411,7 @@ def postgresql_cmd(
password: str,
container_id: Optional[str] = None,
database: str = "db",
uri_params: Dict[str, str] = {},
port: int = 5432,
extra_args: str = "",
sql_command: Optional[str] = None,
Expand Down Expand Up @@ -448,13 +450,16 @@ def postgresql_cmd(
>>> output = db.postgresql_cmd("172.17.0.2", "user", "pass",
... sql_command="-c 'SELECT 1;'")
"""
connection_string = f"postgresql://{username}@{container_ip}:{port}/{database}"
encoded_username = quote(username)
encoded_database = quote(database)
encoded_params = f"?{urlencode(uri_params)}" if uri_params else ""
connection_string = f"postgresql://{encoded_username}@{container_ip}:{port}/{encoded_database}{encoded_params}"
if not container_id:
container_id = self.image_name
cmd_parts = [
podman_run_command,
docker_args,
f"-e PGPASSWORD={password}",
f'-e PGPASSWORD="{password}"',
container_id,
"psql",
"-v ON_ERROR_STOP=1",
Expand All @@ -477,6 +482,7 @@ def test_connection(
username: str,
password: str,
database: str = "db",
uri_params: Dict[str, str] = {},
max_attempts: int = 60,
sleep_time: int = 3,
sql_cmd: Optional[str] = None,
Expand Down Expand Up @@ -516,6 +522,7 @@ def test_connection(
username=username,
password=password,
database=database,
uri_params=uri_params,
sql_command=sql_cmd,
)
else: # mysql or mariadb
Expand Down