Skip to content

Commit 1606478

Browse files
committed
test: add Batch 3 mysql-* container tests (memory, perf-metrics, aria)
Happy-path container integration tests for three config/metrics plugins, iterating over the shared MARIADB_LTS_IMAGES matrix via lib.lftest.run_mariadb(). - mysql-memory: pins `--max-connections=5` so the plugin's `possible peak = server_buffers + per_thread * max_connections` calculation stays deterministic across hosts. On sclorg images the default per-thread buffers are large enough that the stock max_connections=151 pushes the peak above typical host RAM and the test would otherwise depend on the machine running it. - mysql-perf-metrics: asserts "Everything is ok." on a freshly booted server. - mysql-aria: asserts the "Aria indexes / Aria pagecache" summary line against all current MariaDB LTS images; Aria is loaded by default on every MariaDB release. mysql-system was considered for this batch but removed: it is a host-side kernel/OS config check, not a DB client, so it belongs in a cpu-usage-style "plugin runs inside the container" test.
1 parent 44ac54c commit 1606478

3 files changed

Lines changed: 246 additions & 0 deletions

File tree

  • check-plugins
    • mysql-aria/unit-test
    • mysql-memory/unit-test
    • mysql-perf-metrics/unit-test
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8; py-indent-offset: 4 -*-
3+
#
4+
# Author: Linuxfabrik GmbH, Zurich, Switzerland
5+
# Contact: info (at) linuxfabrik (dot) ch
6+
# https://www.linuxfabrik.ch/
7+
# License: The Unlicense, see LICENSE file.
8+
9+
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.md
10+
11+
"""Integration tests for the mysql-aria check plugin.
12+
13+
The plugin opens a real `pymysql` connection and reads
14+
`aria_pagecache_*` counters from `SHOW GLOBAL STATUS` plus
15+
`aria_pagecache_buffer_size` from `SHOW VARIABLES`. The Aria
16+
storage engine is MariaDB's own engine and ships enabled by
17+
default on every LTS release; on MySQL it is absent and the
18+
plugin's own fast-path reports "Aria engine not available.".
19+
A static fixture cannot drive it - we spin up an actual MariaDB
20+
server and let the plugin talk to it over TCP.
21+
22+
Per CONTRIBUTING's "Combine container tests with fixtures" rule,
23+
this file holds only the happy-path integration test. A freshly
24+
booted MariaDB has Aria loaded with a few system tables in its
25+
pagecache, which is STATE_OK with the plugin's defaults.
26+
27+
Runs against the current MariaDB LTS releases
28+
(`lib.lftest.MARIADB_LTS_IMAGES`).
29+
30+
Requirements:
31+
- podman (or docker) with a reachable socket
32+
- `pip install testcontainers`
33+
- `tools/run-unit-tests` auto-sets `CONTAINER_HOST` and
34+
`TESTCONTAINERS_RYUK_DISABLED`
35+
"""
36+
37+
import os
38+
import subprocess
39+
import sys
40+
import unittest
41+
42+
sys.path.insert(0, '..')
43+
44+
import lib.lftest
45+
from lib.globals import STATE_OK
46+
47+
48+
IMAGES = lib.lftest.MARIADB_LTS_IMAGES
49+
50+
51+
class TestCheck(unittest.TestCase):
52+
pass
53+
54+
55+
def _check_image(test, image_pair):
56+
image, label = image_pair
57+
print(f'\n=== Testing {label} ({image}) ===', flush=True)
58+
with lib.lftest.run_mariadb(image) as (_container, defaults_file):
59+
cmd = [
60+
'python3', '../mysql-aria',
61+
f'--defaults-file={defaults_file}',
62+
]
63+
print(f'Run plugin: {" ".join(cmd)}', flush=True)
64+
result = subprocess.run(
65+
cmd,
66+
cwd=os.path.dirname(os.path.abspath(__file__)),
67+
capture_output=True,
68+
text=True,
69+
)
70+
combined = result.stdout + result.stderr
71+
print(f'Script output:\n{combined.strip()}', flush=True)
72+
73+
test.assertEqual(result.returncode, STATE_OK)
74+
test.assertRegex(combined, r'Aria (indexes|pagecache)')
75+
76+
77+
lib.lftest.attach_each(TestCheck, IMAGES, _check_image, id_func=lambda it: it[1])
78+
79+
80+
if __name__ == '__main__':
81+
unittest.main()
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8; py-indent-offset: 4 -*-
3+
#
4+
# Author: Linuxfabrik GmbH, Zurich, Switzerland
5+
# Contact: info (at) linuxfabrik (dot) ch
6+
# https://www.linuxfabrik.ch/
7+
# License: The Unlicense, see LICENSE file.
8+
9+
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.md
10+
11+
"""Integration tests for the mysql-memory check plugin.
12+
13+
The plugin opens a real `pymysql` connection and reads buffer and
14+
cache sizes from `SHOW VARIABLES` / `SHOW STATUS`, calculates a
15+
total expected memory footprint, and compares it against the
16+
host's free memory. A static fixture cannot drive it - we spin up
17+
an actual MariaDB server and let the plugin talk to it over TCP.
18+
19+
Per CONTRIBUTING's "Combine container tests with fixtures" rule,
20+
this file holds only the happy-path integration test. A freshly
21+
booted, idle MariaDB with default buffer settings requests well
22+
under the plugin's memory thresholds, which is STATE_OK.
23+
24+
Runs against the current MariaDB LTS releases
25+
(`lib.lftest.MARIADB_LTS_IMAGES`).
26+
27+
Requirements:
28+
- podman (or docker) with a reachable socket
29+
- `pip install testcontainers`
30+
- `tools/run-unit-tests` auto-sets `CONTAINER_HOST` and
31+
`TESTCONTAINERS_RYUK_DISABLED`
32+
"""
33+
34+
import os
35+
import subprocess
36+
import sys
37+
import unittest
38+
39+
sys.path.insert(0, '..')
40+
41+
import lib.lftest
42+
from lib.globals import STATE_OK
43+
44+
45+
IMAGES = lib.lftest.MARIADB_LTS_IMAGES
46+
47+
48+
class TestCheck(unittest.TestCase):
49+
pass
50+
51+
52+
def _check_image(test, image_pair):
53+
image, label = image_pair
54+
print(f'\n=== Testing {label} ({image}) ===', flush=True)
55+
# The plugin calculates the possible memory peak as
56+
# `server_buffers + per_thread_buffers * max_connections`. On
57+
# sclorg images the per-thread buffers are large enough that
58+
# max_connections=151 (the default) pushes the peak over 30 GiB,
59+
# which WARNs on any host with typical RAM. Pinning max_connections
60+
# to 5 removes the host-RAM dependency so the test is deterministic
61+
# across machines.
62+
with lib.lftest.run_mariadb(
63+
image,
64+
extra_args='--max-connections=5',
65+
) as (_container, defaults_file):
66+
cmd = [
67+
'python3', '../mysql-memory',
68+
f'--defaults-file={defaults_file}',
69+
]
70+
print(f'Run plugin: {" ".join(cmd)}', flush=True)
71+
result = subprocess.run(
72+
cmd,
73+
cwd=os.path.dirname(os.path.abspath(__file__)),
74+
capture_output=True,
75+
text=True,
76+
)
77+
combined = result.stdout + result.stderr
78+
print(f'Script output:\n{combined.strip()}', flush=True)
79+
80+
test.assertEqual(result.returncode, STATE_OK)
81+
test.assertIn("|'mysql_", combined)
82+
83+
84+
lib.lftest.attach_each(TestCheck, IMAGES, _check_image, id_func=lambda it: it[1])
85+
86+
87+
if __name__ == '__main__':
88+
unittest.main()
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8; py-indent-offset: 4 -*-
3+
#
4+
# Author: Linuxfabrik GmbH, Zurich, Switzerland
5+
# Contact: info (at) linuxfabrik (dot) ch
6+
# https://www.linuxfabrik.ch/
7+
# License: The Unlicense, see LICENSE file.
8+
9+
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.md
10+
11+
"""Integration tests for the mysql-perf-metrics check plugin.
12+
13+
The plugin opens a real `pymysql` connection and reads a set of
14+
performance-related counters from `SHOW GLOBAL STATUS` and
15+
`SHOW VARIABLES`. A static fixture cannot drive it - we spin up
16+
an actual MariaDB server and let the plugin talk to it over TCP.
17+
18+
Per CONTRIBUTING's "Combine container tests with fixtures" rule,
19+
this file holds only the happy-path integration test. A freshly
20+
booted, idle MariaDB reports near-zero counters and lands on
21+
"Everything is ok.".
22+
23+
Runs against the current MariaDB LTS releases
24+
(`lib.lftest.MARIADB_LTS_IMAGES`).
25+
26+
Requirements:
27+
- podman (or docker) with a reachable socket
28+
- `pip install testcontainers`
29+
- `tools/run-unit-tests` auto-sets `CONTAINER_HOST` and
30+
`TESTCONTAINERS_RYUK_DISABLED`
31+
"""
32+
33+
import os
34+
import subprocess
35+
import sys
36+
import unittest
37+
38+
sys.path.insert(0, '..')
39+
40+
import lib.lftest
41+
from lib.globals import STATE_OK
42+
43+
44+
IMAGES = lib.lftest.MARIADB_LTS_IMAGES
45+
46+
47+
class TestCheck(unittest.TestCase):
48+
pass
49+
50+
51+
def _check_image(test, image_pair):
52+
image, label = image_pair
53+
print(f'\n=== Testing {label} ({image}) ===', flush=True)
54+
with lib.lftest.run_mariadb(image) as (_container, defaults_file):
55+
cmd = [
56+
'python3', '../mysql-perf-metrics',
57+
f'--defaults-file={defaults_file}',
58+
]
59+
print(f'Run plugin: {" ".join(cmd)}', flush=True)
60+
result = subprocess.run(
61+
cmd,
62+
cwd=os.path.dirname(os.path.abspath(__file__)),
63+
capture_output=True,
64+
text=True,
65+
)
66+
combined = result.stdout + result.stderr
67+
print(f'Script output:\n{combined.strip()}', flush=True)
68+
69+
test.assertEqual(result.returncode, STATE_OK)
70+
test.assertIn('Everything is ok', combined)
71+
72+
73+
lib.lftest.attach_each(TestCheck, IMAGES, _check_image, id_func=lambda it: it[1])
74+
75+
76+
if __name__ == '__main__':
77+
unittest.main()

0 commit comments

Comments
 (0)