Track MySQL server installation separately
This commit is contained in:
@@ -11,12 +11,13 @@ from unittest.mock import patch
|
||||
import deploy_tool.installer as installer_module
|
||||
from deploy_tool.installer import (
|
||||
MAVEN_ARCHIVE_NAME,
|
||||
MYSQL_INITIAL_ROOT_PASSWORD,
|
||||
MYSQL_VERSION,
|
||||
MYSQL_ROOT_PASSWORD,
|
||||
MYSQL_INSTALLER_SHA256,
|
||||
MYSQL_INSTALLER_URL,
|
||||
build_mysql_installer_command,
|
||||
build_windows_command_parameters,
|
||||
build_mysql_server_install_command,
|
||||
configure_mysql_weak_password_policy,
|
||||
default_mysql_install_log_path,
|
||||
TOMCAT_VERSION,
|
||||
@@ -121,24 +122,19 @@ class InstallerTests(unittest.TestCase):
|
||||
self.assertIn("/L*V", command)
|
||||
self.assertIn("mysql-install.log", command)
|
||||
self.assertEqual(MYSQL_VERSION, "8.0.43")
|
||||
self.assertIn("root_passwd=123456", command[-1])
|
||||
self.assertIn("open_win_firewall=false", command[-1])
|
||||
self.assertFalse(any("CONSOLEARGS" in argument for argument in command))
|
||||
self.assertEqual(MYSQL_INSTALLER_SHA256, "F60502EB1EE10A9C1D0A26706A627D224DFAE466D82EF3EB9D76A8A718DB9D80")
|
||||
self.assertIn("downloads.mysql.com/archives/", MYSQL_INSTALLER_URL)
|
||||
|
||||
def test_formats_mysql_consoleargs_as_an_msi_property_value(self):
|
||||
command = build_mysql_installer_command(
|
||||
Path(r"C:\Temp Folder\mysql-installer.msi"),
|
||||
Path(r"C:\Log Folder\mysql-install.log"),
|
||||
)
|
||||
def test_builds_tracked_mysql_server_console_command_with_strong_initial_password(self):
|
||||
command = build_mysql_server_install_command(Path("MySQLInstallerConsole.exe"))
|
||||
|
||||
parameters = build_windows_command_parameters(command)
|
||||
|
||||
self.assertIn('/i "C:\\Temp Folder\\mysql-installer.msi"', parameters)
|
||||
self.assertIn('/L*V "C:\\Log Folder\\mysql-install.log"', parameters)
|
||||
self.assertIn('CONSOLEARGS="install server;8.0.43;x64:*:', parameters)
|
||||
self.assertIn('root_passwd=123456 --silent --auto-handle-prereqs"', parameters)
|
||||
self.assertNotIn('"CONSOLEARGS=', parameters)
|
||||
self.assertEqual(command[0:2], ["MySQLInstallerConsole.exe", "--install"])
|
||||
self.assertIn("server;8.0.43;x64:*:", command[2])
|
||||
self.assertIn(f"root_passwd={MYSQL_INITIAL_ROOT_PASSWORD}", command[2])
|
||||
self.assertNotIn(f"root_passwd={MYSQL_ROOT_PASSWORD}", command[2])
|
||||
self.assertIn("--silent", command)
|
||||
self.assertIn("--auto-handle-prereqs", command)
|
||||
|
||||
def test_mysql_is_not_installed_from_stale_winget_manifest(self):
|
||||
with self.assertRaises(ValueError):
|
||||
@@ -154,13 +150,19 @@ class InstallerTests(unittest.TestCase):
|
||||
|
||||
def elevated_runner(command):
|
||||
commands.append(command)
|
||||
self.assertTrue(Path(command[2]).exists())
|
||||
if command[0] == "msiexec.exe":
|
||||
self.assertTrue(Path(command[2]).exists())
|
||||
return 0
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
install_log = Path(tmp) / "logs" / "mysql-install.log"
|
||||
with (
|
||||
patch("deploy_tool.installer.MYSQL_INSTALLER_SHA256", checksum),
|
||||
patch("deploy_tool.installer.find_mysql_installer_console", return_value=None),
|
||||
patch(
|
||||
"deploy_tool.installer.wait_for_mysql_installer_console",
|
||||
return_value=Path("MySQLInstallerConsole.exe"),
|
||||
),
|
||||
patch("deploy_tool.installer.wait_for_mysql_executable", return_value=Path("mysql.exe")),
|
||||
patch("deploy_tool.installer.configure_mysql_weak_password_policy") as configure,
|
||||
):
|
||||
@@ -176,11 +178,44 @@ class InstallerTests(unittest.TestCase):
|
||||
self.assertEqual(commands[0][0], "msiexec.exe")
|
||||
self.assertIn("/passive", commands[0])
|
||||
self.assertIn(str(install_log), commands[0])
|
||||
self.assertEqual(commands[1][0], "MySQLInstallerConsole.exe")
|
||||
self.assertEqual(commands[1][1], "--install")
|
||||
self.assertTrue(any("校验通过" in message for message in messages))
|
||||
self.assertTrue(any("进度窗口" in message for message in messages))
|
||||
self.assertTrue(any(str(install_log) in message for message in messages))
|
||||
configure.assert_called_once()
|
||||
|
||||
def test_reuses_existing_mysql_installer_without_downloading_bundle(self):
|
||||
commands = []
|
||||
|
||||
def elevated_runner(command):
|
||||
commands.append(command)
|
||||
return 0
|
||||
|
||||
def unexpected_download(_url, _timeout):
|
||||
self.fail("MySQL bundle should not be downloaded when Installer already exists")
|
||||
|
||||
with (
|
||||
patch(
|
||||
"deploy_tool.installer.find_mysql_installer_console",
|
||||
return_value=Path("MySQLInstallerConsole.exe"),
|
||||
),
|
||||
patch("deploy_tool.installer.wait_for_mysql_executable", return_value=Path("mysql.exe")),
|
||||
patch("deploy_tool.installer.configure_mysql_weak_password_policy") as configure,
|
||||
):
|
||||
messages = []
|
||||
executable = install_mysql(
|
||||
messages.append,
|
||||
opener=unexpected_download,
|
||||
elevated_runner=elevated_runner,
|
||||
)
|
||||
|
||||
self.assertEqual(executable, Path("mysql.exe"))
|
||||
self.assertEqual(len(commands), 1)
|
||||
self.assertEqual(commands[0][0], "MySQLInstallerConsole.exe")
|
||||
self.assertTrue(any("检测到已有 MySQL Installer" in message for message in messages))
|
||||
configure.assert_called_once()
|
||||
|
||||
def test_uses_persistent_mysql_install_log_location(self):
|
||||
with patch.dict("os.environ", {"LOCALAPPDATA": r"C:\Users\tester\AppData\Local"}):
|
||||
log_path = default_mysql_install_log_path()
|
||||
@@ -211,7 +246,8 @@ class InstallerTests(unittest.TestCase):
|
||||
self.assertIn("SET PERSIST validate_password.policy = 'LOW'", sql)
|
||||
self.assertIn("SET PERSIST validate_password.length = 6", sql)
|
||||
self.assertIn("ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'", sql)
|
||||
self.assertEqual(configure_call.kwargs["env"]["MYSQL_PWD"], MYSQL_ROOT_PASSWORD)
|
||||
self.assertEqual(configure_call.kwargs["env"]["MYSQL_PWD"], MYSQL_INITIAL_ROOT_PASSWORD)
|
||||
self.assertEqual(run.call_args_list[2].kwargs["env"]["MYSQL_PWD"], MYSQL_ROOT_PASSWORD)
|
||||
self.assertNotIn(MYSQL_ROOT_PASSWORD, configure_call.args[0])
|
||||
self.assertTrue(any("永久允许 6 位弱密码" in message for message in messages))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user