Resume MySQL setup without reinstalling server

This commit is contained in:
王鹏
2026-10-09 10:32:42 +08:00
parent ef5869985a
commit e3d67d9975
2 changed files with 61 additions and 2 deletions

View File

@@ -236,6 +236,7 @@ class InstallerTests(unittest.TestCase):
install_log = Path(tmp) / "logs" / "mysql-install.log"
with (
patch("deploy_tool.installer.MYSQL_INSTALLER_SHA256", checksum),
patch("deploy_tool.installer.find_mysql_executable", return_value=None),
patch("deploy_tool.installer.find_mysql_installer_console", return_value=None),
patch(
"deploy_tool.installer.wait_for_mysql_installer_console",
@@ -278,6 +279,7 @@ class InstallerTests(unittest.TestCase):
"deploy_tool.installer.find_mysql_installer_console",
return_value=Path("MySQLInstallerConsole.exe"),
),
patch("deploy_tool.installer.find_mysql_executable", return_value=None),
patch("deploy_tool.installer.wait_for_mysql_executable", return_value=Path("mysql.exe")),
patch("deploy_tool.installer.configure_mysql_weak_password_policy") as configure,
):
@@ -374,7 +376,49 @@ class InstallerTests(unittest.TestCase):
retry_delay=0,
)
self.assertEqual(run.call_count, 1)
self.assertEqual(run.call_count, 2)
def test_mysql_password_configuration_accepts_already_configured_password(self):
denied = CompletedProcess(
[],
1,
stdout="",
stderr="ERROR 1045 (28000): Access denied for user 'root'@'localhost'",
)
query_result = CompletedProcess([], 0, stdout="", stderr="")
success = CompletedProcess([], 0, stdout="1\n", stderr="")
with patch(
"deploy_tool.installer.subprocess.run",
side_effect=[denied, query_result, success, success],
) as run:
messages = []
configure_mysql_weak_password_policy(
Path("mysql.exe"),
messages.append,
attempts=30,
retry_delay=0,
)
self.assertEqual(run.call_count, 4)
self.assertEqual(run.call_args_list[1].kwargs["env"]["MYSQL_PWD"], MYSQL_ROOT_PASSWORD)
self.assertEqual(run.call_args_list[2].kwargs["env"]["MYSQL_PWD"], MYSQL_ROOT_PASSWORD)
self.assertTrue(any("已使用默认密码" in message for message in messages))
def test_existing_mysql_skips_server_reinstallation(self):
mysql = Path(r"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe")
with (
patch("deploy_tool.installer.find_mysql_executable", return_value=mysql),
patch("deploy_tool.installer.configure_mysql_weak_password_policy") as configure,
patch("deploy_tool.installer.find_mysql_installer_console") as find_console,
):
messages = []
executable = install_mysql(messages.append)
self.assertEqual(executable, mysql)
configure.assert_called_once_with(mysql, messages.append)
find_console.assert_not_called()
self.assertTrue(any("跳过 Server 安装" in message for message in messages))
def test_mysql_without_validation_component_still_sets_and_verifies_password(self):
no_component = CompletedProcess([], 0, stdout="", stderr="")