Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
56 changes: 56 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
import os
import sys

from pathlib import Path
from collections import namedtuple

from container_ci_suite.utils import check_variables

if not check_variables():
sys.exit(1)

TAGS = {
"rhel8": "-el8",
"rhel9": "-el9",
"rhel10": "-el10",
}
TEST_DIR = Path(__file__).parent.absolute()
Vars = namedtuple(
"Vars",
[
"OS",
"VERSION",
"IMAGE_NAME",
"TEST_DIR",
"TAG",
"TEST_APP",
"VERY_LONG_DB_NAME",
"VERY_LONG_USER_NAME",
"DB_NAME",
],
)
VERSION = os.getenv("VERSION")
OS = os.getenv("TARGET").lower()
TEST_APP = TEST_DIR / "test-app"
VERY_LONG_DB_NAME = "very_long_database_name_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
VERY_LONG_USER_NAME = "very_long_user_name_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# MariaDB 11.3+ enforces stricter SSL/TLS verification (certificate & hostname checks),
# so tests may require this option for compatibility.
# https://mariadb.org/mission-impossible-zero-configuration-ssl/
DB_NAME = "--disable-ssl-verify-server-cert db" if VERSION == "11.8" else "db"
VARS = Vars(
OS=OS,
VERSION=VERSION,
IMAGE_NAME=os.getenv("IMAGE_NAME"),
TEST_DIR=Path(__file__).parent.absolute(),
TAG=TAGS.get(OS),
TEST_APP=TEST_APP,
VERY_LONG_DB_NAME=VERY_LONG_DB_NAME,
VERY_LONG_USER_NAME=VERY_LONG_USER_NAME,
DB_NAME=DB_NAME,
)


def get_previous_major_version():
version_dict = {
"10.3": "10.2",
"10.5": "10.3",
"10.11": "10.5",
"11.8": "10.11",
}
return version_dict.get(VARS.VERSION)
17 changes: 17 additions & 0 deletions test/run-pytest
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
# VERSION specifies the major version of the MariaDB in format of X.Y
# OS specifies RHEL version (e.g. OS=rhel10)
#

THISDIR=$(dirname ${BASH_SOURCE[0]})

git show -s

PYTHON_VERSION="3.12"
if [[ ! -f "/usr/bin/python$PYTHON_VERSION" ]]; then
PYTHON_VERSION="3.13"
fi
cd "${THISDIR}" && "python${PYTHON_VERSION}" -m pytest -s -rA --showlocals -vv test_container_*.py
113 changes: 113 additions & 0 deletions test/test_container_basics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import shutil
import tempfile

from container_ci_suite.container_lib import ContainerTestLib
from container_ci_suite.container_lib import ContainerTestLibUtils
from container_ci_suite.engines.podman_wrapper import PodmanCLIWrapper
from pathlib import Path

from conftest import VARS


def build_s2i_app(app_path: Path) -> ContainerTestLib:
container_lib = ContainerTestLib(VARS.IMAGE_NAME)
app_name = app_path.name
s2i_app = container_lib.build_as_df(
app_path=app_path,
s2i_args="--pull-policy=never",
src_image=VARS.IMAGE_NAME,
dst_image=f"{VARS.IMAGE_NAME}-{app_name}",
)
return s2i_app


class TestMariaDBBasicsContainer:
"""
Test MariaDB container configuration.
"""

def setup_method(self):
self.s2i_db = build_s2i_app(app_path=VARS.TEST_DIR / "test-app")
self.s2i_db.set_new_db_type(db_type="mysql")

def teardown_method(self):
self.s2i_db.cleanup()

def test_s2i_usage(self):
"""
Test container creation fails with invalid combinations of arguments.
"""
cid_config_build = "s2i_config_build"
self.s2i_db.assert_container_creation_fails(
cid_file_name=cid_config_build,
command="",
container_args=[
"-e MYSQL_USER=root",
"-e MYSQL_PASSWORD=pass",
"-e MYSQL_DATABASE=db",
"-e MYSQL_ROOT_PASSWORD=pass",
],
)
assert self.s2i_db.create_container(
cid_file_name=cid_config_build,
container_args=[
"-e MYSQL_USER=config_test_user",
"-e MYSQL_PASSWORD=config_test_user",
"-e MYSQL_DATABASE=db",
"-e MYSQL_OPERATIONS_USER=operations_user",
"-e MYSQL_OPERATIONS_PASSWORD=operations_user",
],
)
cip = self.s2i_db.get_cip(cid_file_name=cid_config_build)
assert cip
assert self.s2i_db.test_db_connection(
container_ip=cip, username="operations_user", password="operations_user"
)
cid = self.s2i_db.get_cid(cid_file_name=cid_config_build)
db_configuration = PodmanCLIWrapper.podman_exec_shell_command(
cid_file_name=cid,
cmd="cat /etc/my.cnf /etc/my.cnf.d/*",
)
assert db_configuration
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")

def test_s2i_usage_with_mount(self):
"""
Test container creation fails with invalid combinations of arguments.
"""
data_dir = tempfile.mkdtemp(prefix="/tmp/mysql-test_data")
shutil.copytree(VARS.TEST_DIR / "test-app", f"{data_dir}/test-app")
assert ContainerTestLibUtils.commands_to_run(
commands_to_run=[
f"chown -R 27:27 {data_dir}/test-app",
]
)
cid_s2i_test_mount = "s2i_test_mount"
self.s2i_db.create_container(
cid_file_name=cid_s2i_test_mount,
container_args=[
"-e MYSQL_USER=config_test_user",
"-e MYSQL_PASSWORD=config_test_user",
"-e MYSQL_DATABASE=db",
"-e MYSQL_OPERATIONS_USER=operations_user",
"-e MYSQL_OPERATIONS_PASSWORD=operations_pass",
f"-v {data_dir}/test-app:/opt/app-root/src/:z",
],
)
cip_test_mount = self.s2i_db.get_cip(cid_file_name=cid_s2i_test_mount)
assert cip_test_mount
assert self.s2i_db.test_db_connection(
container_ip=cip_test_mount,
username="operations_user",
password="operations_pass",
max_attempts=10,
)
cid = self.s2i_db.get_cid(cid_file_name=cid_s2i_test_mount)
assert cid
db_configuration = PodmanCLIWrapper.podman_exec_shell_command(
cid_file_name=cid,
cmd="cat /etc/my.cnf /etc/my.cnf.d/*",
)
assert db_configuration
PodmanCLIWrapper.call_podman_command(cmd=f"stop {cid}")
shutil.rmtree(data_dir)
Loading