Skip to content

Commit

Permalink
Mariadb upgrade scenario testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmadhankumar committed Sep 13, 2024
1 parent a101608 commit 4b5f69f
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion tests/test_mariadb.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""Tests for the MariaDB related application container images."""

import os
from itertools import product
from pathlib import Path
from typing import List
from typing import Optional

import pymysql
import pytest
from _pytest.mark import ParameterSet
from pymysql.err import OperationalError
from pytest_container.container import BindMount
from pytest_container.container import Container
from pytest_container.container import ContainerData
from pytest_container.container import ContainerLauncher
from pytest_container.container import DerivedContainer
from pytest_container.container import container_and_marks_from_pytest_param
from pytest_container.pod import Pod
Expand Down Expand Up @@ -265,7 +270,7 @@ def test_mariadb_healthcheck_innodb_initialized(auto_container_per_test):


def test_mariadb_healthcheck_galera_cluster_disabled(auto_container_per_test):
"""
"""registry.opensuse.org/devel/bci/sle-15-sp6
Ensure that Galera Cluster (multi-primary cluster) is disabled (experimental feature),
i.e. :command:`healthcheck.sh --su-mysql --galera_online` fails.
Expand All @@ -276,3 +281,80 @@ def test_mariadb_healthcheck_galera_cluster_disabled(auto_container_per_test):
_wait_for_server(conn)

conn.run_expect([1], "healthcheck.sh --su-mysql --galera_online")


_DB_ENV = {
"MARIADB_USER": _OTHER_DB_USER,
"MARIADB_PASSWORD": _OTHER_DB_PW,
"MARIADB_DATABASE": _TEST_DB,
"MARIADB_ROOT_PASSWORD": MARIADB_ROOT_PASSWORD,
"MARIADB_AUTO_UPGRADE": "1",
}

OS_VERSION = os.getenv("OS_VERSION", "")


@pytest.mark.parametrize("ctr_image", MARIADB_CONTAINERS)
@pytest.mark.skipif(
OS_VERSION in ("15.5",), reason="MariaDB upgrade scenario not supported"
)
def test_mariadb_upgrade(
container_runtime: OciRuntimeBase,
pytestconfig: pytest.Config,
ctr_image: DerivedContainer,
tmp_path: Path,
) -> None:
mounts = [BindMount(host_path=tmp_path, container_path="/var/lib/mysql")]
mariadb_old = Container(
url="registry.opensuse.org/devel/bci/sle-15-sp6/containerfile/suse/mariadb:latest",
volume_mounts=mounts,
extra_environment_variables=_DB_ENV,
)
mariadb_new = DerivedContainer(
base=ctr_image,
volume_mounts=mounts,
extra_environment_variables=_DB_ENV,
)
with ContainerLauncher.from_pytestconfig(
mariadb_old, container_runtime, pytestconfig
) as launcher:
launcher.launch_container()
con = launcher.container_data.connection
_wait_for_server(con)
mariadb_cmd = f"mariadb --user={_OTHER_DB_USER} --password={_OTHER_DB_PW} --host=0.0.0.0 {_TEST_DB}"

con.check_output(
f'echo "CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar(32));" | {mariadb_cmd}'
)
con.check_output(
f"echo 'INSERT INTO test (num, data) VALUES (100, \"abcdef\")' | {mariadb_cmd}"
)
rows = (
con.check_output(f'echo "SELECT * FROM test;" | {mariadb_cmd}')
.strip()
.splitlines()
)

assert rows and len(rows) == 2
_, num, data = rows[-1].split()
assert num == "100" and data == "abcdef"

with ContainerLauncher.from_pytestconfig(
mariadb_new, container_runtime, pytestconfig
) as launcher:
launcher.launch_container()
con = launcher.container_data.connection
_wait_for_server(con)
expected_version = mariadb_new.url.split(":")[1]
if expected_version != "latest":
assert expected_version in con.check_output("mysql --version")
mariadb_cmd = f"mariadb --user={_OTHER_DB_USER} --password={_OTHER_DB_PW} --host=0.0.0.0 {_TEST_DB}"
rows = (
con.check_output(f'echo "SELECT * FROM test;" | {mariadb_cmd}')
.strip()
.splitlines()
)

assert rows and len(rows) == 2
_, num, data = rows[-1].split()
assert num == "100" and data == "abcdef"

0 comments on commit 4b5f69f

Please sign in to comment.