Start MySQL service before password setup
This commit is contained in:
@@ -25,6 +25,8 @@ from deploy_tool.installer import (
|
||||
configure_mysql_weak_password_policy,
|
||||
default_mysql_install_log_path,
|
||||
default_mysql_server_install_log_path,
|
||||
ensure_mysql_service_running,
|
||||
query_mysql_service_state,
|
||||
run_elevated_command_with_log,
|
||||
TOMCAT_VERSION,
|
||||
install_maven,
|
||||
@@ -243,6 +245,7 @@ class InstallerTests(unittest.TestCase):
|
||||
return_value=Path("MySQLInstallerConsole.exe"),
|
||||
),
|
||||
patch("deploy_tool.installer.wait_for_mysql_executable", return_value=Path("mysql.exe")),
|
||||
patch("deploy_tool.installer.ensure_mysql_service_running"),
|
||||
patch("deploy_tool.installer.configure_mysql_weak_password_policy") as configure,
|
||||
):
|
||||
messages = []
|
||||
@@ -281,6 +284,7 @@ class InstallerTests(unittest.TestCase):
|
||||
),
|
||||
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.ensure_mysql_service_running"),
|
||||
patch("deploy_tool.installer.configure_mysql_weak_password_policy") as configure,
|
||||
):
|
||||
messages = []
|
||||
@@ -314,8 +318,9 @@ class InstallerTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
log_path = Path(tmp) / "mysql-server-install.log"
|
||||
|
||||
def inspect_wrapper(command, on_wait=None):
|
||||
def inspect_wrapper(command, on_wait=None, show_window=True):
|
||||
self.assertEqual(command[0], "powershell.exe")
|
||||
self.assertTrue(show_window)
|
||||
script_path = Path(command[-1])
|
||||
self.assertTrue(script_path.exists())
|
||||
script = script_path.read_text(encoding="utf-8-sig")
|
||||
@@ -409,6 +414,7 @@ class InstallerTests(unittest.TestCase):
|
||||
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.ensure_mysql_service_running") as ensure_service,
|
||||
patch("deploy_tool.installer.configure_mysql_weak_password_policy") as configure,
|
||||
patch("deploy_tool.installer.find_mysql_installer_console") as find_console,
|
||||
):
|
||||
@@ -416,10 +422,41 @@ class InstallerTests(unittest.TestCase):
|
||||
executable = install_mysql(messages.append)
|
||||
|
||||
self.assertEqual(executable, mysql)
|
||||
ensure_service.assert_called_once_with(messages.append)
|
||||
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_reads_mysql_windows_service_state_without_console_window(self):
|
||||
running = CompletedProcess([], 0, stdout=b"STATE : 4 RUNNING\r\n", stderr=b"")
|
||||
|
||||
with patch("deploy_tool.installer.subprocess.run", return_value=running) as run:
|
||||
state = query_mysql_service_state()
|
||||
|
||||
self.assertEqual(state, 4)
|
||||
self.assertEqual(run.call_args.args[0], ["sc.exe", "query", "MySQL80"])
|
||||
self.assertEqual(
|
||||
run.call_args.kwargs["creationflags"],
|
||||
getattr(subprocess, "CREATE_NO_WINDOW", 0),
|
||||
)
|
||||
|
||||
def test_starts_stopped_mysql_windows_service(self):
|
||||
commands = []
|
||||
|
||||
def elevated_runner(command):
|
||||
commands.append(command)
|
||||
return 0
|
||||
|
||||
with (
|
||||
patch("deploy_tool.installer.query_mysql_service_state", side_effect=[1, 2, 4]),
|
||||
patch("deploy_tool.installer.time.sleep"),
|
||||
):
|
||||
messages = []
|
||||
ensure_mysql_service_running(messages.append, elevated_runner=elevated_runner)
|
||||
|
||||
self.assertEqual(commands, [["sc.exe", "start", "MySQL80"]])
|
||||
self.assertTrue(any("已启动" in message for message in messages))
|
||||
|
||||
def test_mysql_without_validation_component_still_sets_and_verifies_password(self):
|
||||
no_component = CompletedProcess([], 0, stdout="", stderr="")
|
||||
success = CompletedProcess([], 0, stdout="1\n", stderr="")
|
||||
|
||||
Reference in New Issue
Block a user