forked from opendatahub-io/opendatahub-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
33 lines (28 loc) · 1.1 KB
/
utils.py
File metadata and controls
33 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from ocp_resources.pod import Pod
from tests.model_registry.constants import MODEL_REGISTRY_DB_SECRET_STR_DATA
import base64
def create_mysql_credentials_file(model_registry_db_instance_pod: Pod) -> None:
"""
Setup MySQL configuration file with credentials.
"""
credentials_file_content = f"""[client]
user={MODEL_REGISTRY_DB_SECRET_STR_DATA["database-user"]}
password={MODEL_REGISTRY_DB_SECRET_STR_DATA["database-password"]}
"""
b64_content = base64.b64encode(credentials_file_content.encode("utf-8")).decode("utf-8")
model_registry_db_instance_pod.execute(
command=["bash", "-c", f"echo '{b64_content}' | base64 --decode > /tmp/.my.cnf"]
)
def execute_mysql_command(sql_query: str, model_registry_db_instance_pod: Pod) -> str:
"""
Execute a MySQL command on the model registry database instance pod.
"""
return model_registry_db_instance_pod.execute(
command=[
"mysql",
"--defaults-file=/tmp/.my.cnf",
"-e",
sql_query,
MODEL_REGISTRY_DB_SECRET_STR_DATA["database-name"],
]
)