Skip to content

Commit 8e81f48

Browse files
committed
Container PyTest suite for mysql-container
Migration matrix is here: - run_container_creation_tests -> test_container_configuration.py - run_configuration_tests -> test_container_configuration.py - run_general_tests -> test_container_general.py - run_change_password_test -> test_container_password.py - run_change_password_new_user_test -> test_container_password.py - run_replication_test -> Not Yet - run_s2i_test -> test_container_basics.py - run_ssl_test -> test_container_ssl.py - run_datadir_actions_test -> test_container_general.py Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent ed58dd7 commit 8e81f48

11 files changed

+864
-40
lines changed

test/conftest.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
import sys
3+
4+
from pathlib import Path
5+
from collections import namedtuple
6+
7+
from container_ci_suite.utils import check_variables
8+
9+
if not check_variables():
10+
sys.exit(1)
11+
12+
TAGS = {
13+
"rhel8": "-el8",
14+
"rhel9": "-el9",
15+
"rhel10": "-el10",
16+
}
17+
TEST_DIR = Path(__file__).parent.absolute()
18+
Vars = namedtuple(
19+
"Vars",
20+
[
21+
"OS",
22+
"VERSION",
23+
"IMAGE_NAME",
24+
"TEST_DIR",
25+
"TAG",
26+
"TEST_APP",
27+
"VERY_LONG_DB_NAME",
28+
"VERY_LONG_USER_NAME",
29+
],
30+
)
31+
VERSION = os.getenv("VERSION")
32+
OS = os.getenv("TARGET").lower()
33+
TEST_APP = TEST_DIR / "test-app"
34+
VERY_LONG_DB_NAME = "very_long_database_name_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
35+
VERY_LONG_USER_NAME = "very_long_user_name_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
36+
VARS = Vars(
37+
OS=OS,
38+
VERSION=VERSION,
39+
IMAGE_NAME=os.getenv("IMAGE_NAME"),
40+
TEST_DIR=Path(__file__).parent.absolute(),
41+
TAG=TAGS.get(OS),
42+
TEST_APP=TEST_APP,
43+
VERY_LONG_DB_NAME=VERY_LONG_DB_NAME,
44+
VERY_LONG_USER_NAME=VERY_LONG_USER_NAME,
45+
)

test/constants.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/run-pytest

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
#
3+
# IMAGE_NAME specifies a name of the candidate image used for testing.
4+
# The image has to be available before this script is executed.
5+
# VERSION specifies the major version of the MariaDB in format of X.Y
6+
# OS specifies RHEL version (e.g. OS=rhel10)
7+
#
8+
9+
THISDIR=$(dirname ${BASH_SOURCE[0]})
10+
11+
git show -s
12+
13+
PYTHON_VERSION="3.12"
14+
if [[ ! -f "/usr/bin/python$PYTHON_VERSION" ]]; then
15+
PYTHON_VERSION="3.13"
16+
fi
17+
cd "${THISDIR}" && "python${PYTHON_VERSION}" -m pytest -s -rA --showlocals -vv test_container_*.py

test/test_container_basics.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import shutil
2+
import tempfile
3+
4+
from container_ci_suite.container_lib import ContainerTestLib
5+
from container_ci_suite.container_lib import ContainerTestLibUtils
6+
from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper
7+
from pathlib import Path
8+
9+
from conftest import VARS
10+
11+
12+
def build_s2i_app(app_path: Path) -> ContainerTestLib:
13+
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
14+
app_name = app_path.name
15+
s2i_app = container_lib.build_as_df(
16+
app_path=app_path,
17+
s2i_args="--pull-policy=never",
18+
src_image=VARS.IMAGE_NAME,
19+
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
20+
)
21+
return s2i_app
22+
23+
24+
class TestMySqlBasicsContainer:
25+
"""
26+
Test MySQL container configuration.
27+
"""
28+
29+
def setup_method(self):
30+
self.s2i_db = build_s2i_app(app_path=VARS.TEST_DIR / "test-app")
31+
self.s2i_db.set_new_db_type(db_type="mysql")
32+
33+
def teardown_method(self):
34+
self.s2i_db.cleanup()
35+
36+
def test_s2i_usage(self):
37+
"""
38+
Test container creation fails with invalid combinations of arguments.
39+
"""
40+
cid_config_build = "s2i_config_build"
41+
self.s2i_db.assert_container_creation_fails(
42+
cid_file_name=cid_config_build,
43+
command="",
44+
container_args=[
45+
"-e MYSQL_USER=root",
46+
"-e MYSQL_PASSWORD=pass",
47+
"-e MYSQL_DATABASE=db",
48+
"-e MYSQL_ROOT_PASSWORD=pass",
49+
],
50+
)
51+
assert self.s2i_db.create_container(
52+
cid_file_name=cid_config_build,
53+
container_args=[
54+
"-e MYSQL_USER=config_test_user",
55+
"-e MYSQL_PASSWORD=config_test_user",
56+
"-e MYSQL_DATABASE=db",
57+
"-e MYSQL_OPERATIONS_USER=operations_user",
58+
"-e MYSQL_OPERATIONS_PASSWORD=operations_user",
59+
],
60+
)
61+
cip = self.s2i_db.get_cip(cid_file_name=cid_config_build)
62+
assert cip
63+
assert self.s2i_db.test_db_connection(
64+
container_ip=cip, username="operations_user", password="operations_user"
65+
)
66+
cid = self.s2i_db.get_cid(cid_file_name=cid_config_build)
67+
db_configuration = PodmanCLIWrapper.podman_exec_shell_command(
68+
cid_file_name=cid,
69+
cmd="cat /etc/my.cnf /etc/my.cnf.d/*",
70+
)
71+
assert db_configuration
72+
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")
73+
74+
def test_s2i_usage_with_mount(self):
75+
"""
76+
Test container creation fails with invalid combinations of arguments.
77+
"""
78+
data_dir = tempfile.mkdtemp(prefix="/tmp/mysql-test_data")
79+
shutil.copytree(VARS.TEST_DIR / "test-app", f"{data_dir}/test-app")
80+
assert ContainerTestLibUtils.commands_to_run(
81+
commands_to_run=[
82+
f"chown -R 27:27 {data_dir}/test-app",
83+
]
84+
)
85+
cid_s2i_test_mount = "s2i_test_mount"
86+
self.s2i_db.create_container(
87+
cid_file_name=cid_s2i_test_mount,
88+
container_args=[
89+
"-e MYSQL_USER=config_test_user",
90+
"-e MYSQL_PASSWORD=config_test_user",
91+
"-e MYSQL_DATABASE=db",
92+
"-e MYSQL_OPERATIONS_USER=operations_user",
93+
"-e MYSQL_OPERATIONS_PASSWORD=operations_pass",
94+
f"-v {data_dir}/test-app:/opt/app-root/src/:z",
95+
],
96+
)
97+
cip_test_mount = self.s2i_db.get_cip(cid_file_name=cid_s2i_test_mount)
98+
assert cip_test_mount
99+
assert self.s2i_db.test_db_connection(
100+
container_ip=cip_test_mount,
101+
username="operations_user",
102+
password="operations_pass",
103+
max_attempts=10,
104+
)
105+
cid = self.s2i_db.get_cid(cid_file_name=cid_s2i_test_mount)
106+
assert cid
107+
db_configuration = PodmanCLIWrapper.podman_exec_shell_command(
108+
cid_file_name=cid,
109+
cmd="cat /etc/my.cnf /etc/my.cnf.d/*",
110+
)
111+
assert db_configuration
112+
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")
113+
shutil.rmtree(data_dir)

0 commit comments

Comments
 (0)