1
1
"""Tests for the MariaDB related application container images."""
2
2
3
+ import os
3
4
from itertools import product
5
+ from pathlib import Path
4
6
from typing import List
5
7
from typing import Optional
6
8
7
9
import pymysql
8
10
import pytest
9
11
from _pytest .mark import ParameterSet
10
12
from pymysql .err import OperationalError
13
+ from pytest_container .container import BindMount
14
+ from pytest_container .container import Container
11
15
from pytest_container .container import ContainerData
16
+ from pytest_container .container import ContainerLauncher
12
17
from pytest_container .container import DerivedContainer
13
18
from pytest_container .container import container_and_marks_from_pytest_param
14
19
from pytest_container .pod import Pod
@@ -265,7 +270,7 @@ def test_mariadb_healthcheck_innodb_initialized(auto_container_per_test):
265
270
266
271
267
272
def test_mariadb_healthcheck_galera_cluster_disabled (auto_container_per_test ):
268
- """
273
+ """registry.opensuse.org/devel/bci/sle-15-sp6
269
274
Ensure that Galera Cluster (multi-primary cluster) is disabled (experimental feature),
270
275
i.e. :command:`healthcheck.sh --su-mysql --galera_online` fails.
271
276
@@ -276,3 +281,80 @@ def test_mariadb_healthcheck_galera_cluster_disabled(auto_container_per_test):
276
281
_wait_for_server (conn )
277
282
278
283
conn .run_expect ([1 ], "healthcheck.sh --su-mysql --galera_online" )
284
+
285
+
286
+ _DB_ENV = {
287
+ "MARIADB_USER" : _OTHER_DB_USER ,
288
+ "MARIADB_PASSWORD" : _OTHER_DB_PW ,
289
+ "MARIADB_DATABASE" : _TEST_DB ,
290
+ "MARIADB_ROOT_PASSWORD" : MARIADB_ROOT_PASSWORD ,
291
+ "MARIADB_AUTO_UPGRADE" : "1" ,
292
+ }
293
+
294
+ OS_VERSION = os .getenv ("OS_VERSION" , "" )
295
+
296
+
297
+ @pytest .mark .parametrize ("ctr_image" , MARIADB_CONTAINERS )
298
+ @pytest .mark .skipif (
299
+ OS_VERSION in ("15.5" ,), reason = "MariaDB upgrade scenario not supported"
300
+ )
301
+ def test_mariadb_upgrade (
302
+ container_runtime : OciRuntimeBase ,
303
+ pytestconfig : pytest .Config ,
304
+ ctr_image : DerivedContainer ,
305
+ tmp_path : Path ,
306
+ ) -> None :
307
+ mounts = [BindMount (host_path = tmp_path , container_path = "/var/lib/mysql" )]
308
+ mariadb_old = Container (
309
+ url = "registry.opensuse.org/devel/bci/sle-15-sp6/containerfile/suse/mariadb:latest" ,
310
+ volume_mounts = mounts ,
311
+ extra_environment_variables = _DB_ENV ,
312
+ )
313
+ mariadb_new = DerivedContainer (
314
+ base = ctr_image ,
315
+ volume_mounts = mounts ,
316
+ extra_environment_variables = _DB_ENV ,
317
+ )
318
+ with ContainerLauncher .from_pytestconfig (
319
+ mariadb_old , container_runtime , pytestconfig
320
+ ) as launcher :
321
+ launcher .launch_container ()
322
+ con = launcher .container_data .connection
323
+ _wait_for_server (con )
324
+ mariadb_cmd = f"mariadb --user={ _OTHER_DB_USER } --password={ _OTHER_DB_PW } --host=0.0.0.0 { _TEST_DB } "
325
+
326
+ con .check_output (
327
+ f'echo "CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar(32));" | { mariadb_cmd } '
328
+ )
329
+ con .check_output (
330
+ f"echo 'INSERT INTO test (num, data) VALUES (100, \" abcdef\" )' | { mariadb_cmd } "
331
+ )
332
+ rows = (
333
+ con .check_output (f'echo "SELECT * FROM test;" | { mariadb_cmd } ' )
334
+ .strip ()
335
+ .splitlines ()
336
+ )
337
+
338
+ assert rows and len (rows ) == 2
339
+ _ , num , data = rows [- 1 ].split ()
340
+ assert num == "100" and data == "abcdef"
341
+
342
+ with ContainerLauncher .from_pytestconfig (
343
+ mariadb_new , container_runtime , pytestconfig
344
+ ) as launcher :
345
+ launcher .launch_container ()
346
+ con = launcher .container_data .connection
347
+ _wait_for_server (con )
348
+ expected_version = mariadb_new .url .split (":" )[1 ]
349
+ if expected_version != "latest" :
350
+ assert expected_version in con .check_output ("mysql --version" )
351
+ mariadb_cmd = f"mariadb --user={ _OTHER_DB_USER } --password={ _OTHER_DB_PW } --host=0.0.0.0 { _TEST_DB } "
352
+ rows = (
353
+ con .check_output (f'echo "SELECT * FROM test;" | { mariadb_cmd } ' )
354
+ .strip ()
355
+ .splitlines ()
356
+ )
357
+
358
+ assert rows and len (rows ) == 2
359
+ _ , num , data = rows [- 1 ].split ()
360
+ assert num == "100" and data == "abcdef"
0 commit comments