mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-07 14:35:52 +02:00
MariaDB 11.8/12.1: tests, downgrade note, doc
- test/upgrader_mariadb_version_test.sh: upgrader arg parsing and repo URL - test/test_upgrade_mariadb_version.py: mariadb_version file read, downgrade - test/run_mariadb_tests.sh: run all MariaDB version tests - cyberpanel_upgrade.sh: prompt mentions re-run for downgrade (11.8/12.1) - to-do/MARIADB-11.8-LTS-UPGRADE.md: 11.8/12.1 choice, downgrade, test commands
This commit is contained in:
14
test/run_mariadb_tests.sh
Executable file
14
test/run_mariadb_tests.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# Run all MariaDB version tests (upgrader + upgrade.py logic).
|
||||
# From repo root: ./test/run_mariadb_tests.sh
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$REPO_ROOT"
|
||||
echo "=== Upgrader MariaDB version tests ==="
|
||||
./test/upgrader_mariadb_version_test.sh
|
||||
echo ""
|
||||
echo "=== Upgrade.py mariadb_version read tests ==="
|
||||
python3 test/test_upgrade_mariadb_version.py
|
||||
echo ""
|
||||
echo "=== All MariaDB version tests passed (11.8, 12.1, downgrade). ==="
|
||||
112
test/test_upgrade_mariadb_version.py
Normal file
112
test/test_upgrade_mariadb_version.py
Normal file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Unit tests for plogical/upgrade.py MariaDB version read from /etc/cyberpanel/mariadb_version.
|
||||
Tests that 11.8 and 12.1 are both accepted and that downgrade (12.1 -> 11.8) is supported.
|
||||
Run from repo root: python3 test/test_upgrade_mariadb_version.py
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
# Logic extracted from Upgrade.fix_almalinux9_mariadb() - read mariadb_version file
|
||||
def read_mariadb_version_from_file(filepath):
|
||||
mariadb_ver = "11.8"
|
||||
try:
|
||||
if os.path.isfile(filepath):
|
||||
with open(filepath, "r") as f:
|
||||
raw = f.read().strip()
|
||||
if raw in ("11.8", "12.1"):
|
||||
mariadb_ver = raw
|
||||
except Exception:
|
||||
pass
|
||||
return mariadb_ver
|
||||
|
||||
|
||||
def test_default_no_file():
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
path = os.path.join(d, "nonexistent")
|
||||
assert read_mariadb_version_from_file(path) == "11.8"
|
||||
print("OK: default when file missing = 11.8")
|
||||
|
||||
|
||||
def test_11_8():
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".tmp") as f:
|
||||
f.write("11.8")
|
||||
path = f.name
|
||||
try:
|
||||
assert read_mariadb_version_from_file(path) == "11.8"
|
||||
print("OK: file 11.8 -> 11.8")
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def test_12_1():
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".tmp") as f:
|
||||
f.write("12.1")
|
||||
path = f.name
|
||||
try:
|
||||
assert read_mariadb_version_from_file(path) == "12.1"
|
||||
print("OK: file 12.1 -> 12.1")
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def test_downgrade_simulation():
|
||||
# Simulate writing 12.1 then 11.8 (downgrade) - both must work
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".tmp") as f:
|
||||
f.write("12.1")
|
||||
path = f.name
|
||||
try:
|
||||
assert read_mariadb_version_from_file(path) == "12.1"
|
||||
print("OK: downgrade step 1 - 12.1")
|
||||
finally:
|
||||
pass
|
||||
with open(path, "w") as f:
|
||||
f.write("11.8")
|
||||
try:
|
||||
assert read_mariadb_version_from_file(path) == "11.8"
|
||||
print("OK: downgrade step 2 - 11.8 (downgrade supported)")
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def test_invalid_falls_back():
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".tmp") as f:
|
||||
f.write("10.11")
|
||||
path = f.name
|
||||
try:
|
||||
assert read_mariadb_version_from_file(path) == "11.8"
|
||||
print("OK: invalid 10.11 -> 11.8")
|
||||
finally:
|
||||
os.unlink(path)
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".tmp") as f:
|
||||
f.write("13")
|
||||
path = f.name
|
||||
try:
|
||||
assert read_mariadb_version_from_file(path) == "11.8"
|
||||
print("OK: invalid 13 -> 11.8")
|
||||
finally:
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def test_repo_command_format():
|
||||
mariadb_ver = "12.1"
|
||||
command = "curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash -s -- --mariadb-server-version='%s'" % mariadb_ver
|
||||
assert "12.1" in command
|
||||
assert "--mariadb-server-version='12.1'" in command
|
||||
print("OK: repo command includes version 12.1")
|
||||
mariadb_ver = "11.8"
|
||||
command = "curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash -s -- --mariadb-server-version='%s'" % mariadb_ver
|
||||
assert "--mariadb-server-version='11.8'" in command
|
||||
print("OK: repo command includes version 11.8")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_default_no_file()
|
||||
test_11_8()
|
||||
test_12_1()
|
||||
test_downgrade_simulation()
|
||||
test_invalid_falls_back()
|
||||
test_repo_command_format()
|
||||
print("\nAll upgrade.py MariaDB version tests passed.")
|
||||
sys.exit(0)
|
||||
105
test/upgrader_mariadb_version_test.sh
Executable file
105
test/upgrader_mariadb_version_test.sh
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/bin/bash
|
||||
# Test script for cyberpanel_upgrade.sh MariaDB version handling (11.8, 12.1, downgrade).
|
||||
# Run from repo root: ./test/upgrader_mariadb_version_test.sh
|
||||
# Does not require root or a real CyberPanel install.
|
||||
|
||||
set -e
|
||||
FAILED=0
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
UPGRADE_SCRIPT="$REPO_ROOT/cyberpanel_upgrade.sh"
|
||||
|
||||
# Default (same as cyberpanel_upgrade.sh)
|
||||
MARIADB_VER="11.8"
|
||||
|
||||
# Parse --mariadb-version from "$@" (same logic as Check_Argument in cyberpanel_upgrade.sh)
|
||||
parse_mariadb_version() {
|
||||
if [[ "$*" = *"--mariadb-version "* ]]; then
|
||||
MARIADB_VER=$(echo "$*" | sed -n 's/.*--mariadb-version \([^ ]*\).*/\1/p' | head -1)
|
||||
MARIADB_VER="${MARIADB_VER:-11.8}"
|
||||
fi
|
||||
if [[ "$MARIADB_VER" != "11.8" ]] && [[ "$MARIADB_VER" != "12.1" ]]; then
|
||||
MARIADB_VER="11.8"
|
||||
fi
|
||||
}
|
||||
|
||||
assert_equals() {
|
||||
local expected="$1"
|
||||
local actual="$2"
|
||||
local name="${3:-value}"
|
||||
if [[ "$actual" != "$expected" ]]; then
|
||||
echo "FAIL: $name expected '\''$expected'\'' got '\''$actual'\''"
|
||||
FAILED=1
|
||||
else
|
||||
echo "OK: $name = $actual"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "=== 1. Default (no --mariadb-version) ==="
|
||||
MARIADB_VER="11.8"
|
||||
parse_mariadb_version ""
|
||||
assert_equals "11.8" "$MARIADB_VER" "default"
|
||||
|
||||
echo ""
|
||||
echo "=== 2. Explicit 11.8 ==="
|
||||
MARIADB_VER="11.8"
|
||||
parse_mariadb_version "--mariadb-version 11.8"
|
||||
assert_equals "11.8" "$MARIADB_VER" "--mariadb-version 11.8"
|
||||
|
||||
echo ""
|
||||
echo "=== 3. Explicit 12.1 ==="
|
||||
MARIADB_VER="11.8"
|
||||
parse_mariadb_version "--mariadb-version 12.1"
|
||||
assert_equals "12.1" "$MARIADB_VER" "--mariadb-version 12.1"
|
||||
|
||||
echo ""
|
||||
echo "=== 4. Downgrade: 12.1 then 11.8 (both must be accepted) ==="
|
||||
MARIADB_VER="11.8"
|
||||
parse_mariadb_version "--mariadb-version 12.1"
|
||||
assert_equals "12.1" "$MARIADB_VER" "first 12.1"
|
||||
parse_mariadb_version "--mariadb-version 11.8"
|
||||
assert_equals "11.8" "$MARIADB_VER" "then 11.8 (downgrade)"
|
||||
|
||||
echo ""
|
||||
echo "=== 5. Invalid value falls back to 11.8 ==="
|
||||
MARIADB_VER="11.8"
|
||||
parse_mariadb_version "--mariadb-version 10.11"
|
||||
assert_equals "11.8" "$MARIADB_VER" "invalid 10.11 -> 11.8"
|
||||
parse_mariadb_version "--mariadb-version 13"
|
||||
assert_equals "11.8" "$MARIADB_VER" "invalid 13 -> 11.8"
|
||||
|
||||
echo ""
|
||||
echo "=== 6. With -b and --mariadb-version ==="
|
||||
MARIADB_VER="11.8"
|
||||
parse_mariadb_version "-b v2.5.5-dev --mariadb-version 12.1"
|
||||
assert_equals "12.1" "$MARIADB_VER" "-b v2.5.5-dev --mariadb-version 12.1"
|
||||
|
||||
echo ""
|
||||
echo "=== 7. MariaDB.repo baseurl uses MARIADB_VER ==="
|
||||
MARIADB_VER="12.1"
|
||||
MARIADB_REPO="rhel9-amd64"
|
||||
baseurl="https://mirror.mariadb.org/yum/$MARIADB_VER/$MARIADB_REPO"
|
||||
assert_equals "https://mirror.mariadb.org/yum/12.1/rhel9-amd64" "$baseurl" "baseurl 12.1"
|
||||
MARIADB_VER="11.8"
|
||||
baseurl="https://mirror.mariadb.org/yum/$MARIADB_VER/$MARIADB_REPO"
|
||||
assert_equals "https://mirror.mariadb.org/yum/11.8/rhel9-amd64" "$baseurl" "baseurl 11.8"
|
||||
|
||||
echo ""
|
||||
echo "=== 8. Script contains required logic ==="
|
||||
if [[ ! -f "$UPGRADE_SCRIPT" ]]; then
|
||||
echo "FAIL: $UPGRADE_SCRIPT not found"
|
||||
FAILED=1
|
||||
else
|
||||
echo "OK: upgrade script exists"
|
||||
grep -q 'MARIADB_VER="11.8"' "$UPGRADE_SCRIPT" && echo "OK: default MARIADB_VER" || { echo "FAIL: default MARIADB_VER"; FAILED=1; }
|
||||
grep -q '/etc/cyberpanel/mariadb_version' "$UPGRADE_SCRIPT" && echo "OK: mariadb_version file" || { echo "FAIL: mariadb_version file"; FAILED=1; }
|
||||
fi
|
||||
|
||||
echo ""
|
||||
if [[ $FAILED -eq 0 ]]; then
|
||||
echo "All upgrader MariaDB version tests passed."
|
||||
exit 0
|
||||
else
|
||||
echo "Some tests failed."
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user