Show MySQL service startup error log
This commit is contained in:
@@ -26,6 +26,8 @@ from deploy_tool.installer import (
|
||||
default_mysql_install_log_path,
|
||||
default_mysql_server_install_log_path,
|
||||
ensure_mysql_service_running,
|
||||
find_mysql_error_log,
|
||||
mysql_service_failure_detail,
|
||||
query_mysql_service_state,
|
||||
run_elevated_command_with_log,
|
||||
TOMCAT_VERSION,
|
||||
@@ -422,7 +424,7 @@ class InstallerTests(unittest.TestCase):
|
||||
executable = install_mysql(messages.append)
|
||||
|
||||
self.assertEqual(executable, mysql)
|
||||
ensure_service.assert_called_once_with(messages.append)
|
||||
ensure_service.assert_called_once_with(messages.append, mysql_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))
|
||||
@@ -457,6 +459,30 @@ class InstallerTests(unittest.TestCase):
|
||||
self.assertEqual(commands, [["sc.exe", "start", "MySQL80"]])
|
||||
self.assertTrue(any("已启动" in message for message in messages))
|
||||
|
||||
def test_reports_mysql_error_log_when_service_stops_after_start(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
program_data = Path(tmp)
|
||||
data_dir = program_data / "MySQL" / "MySQL Server 8.0" / "Data"
|
||||
data_dir.mkdir(parents=True)
|
||||
error_log = data_dir / "host.err"
|
||||
error_log.write_text("[ERROR] Data Dictionary initialization failed\n", encoding="utf-8")
|
||||
|
||||
with (
|
||||
patch.dict("os.environ", {"PROGRAMDATA": str(program_data)}),
|
||||
patch("deploy_tool.installer.query_mysql_service_state", side_effect=[1, 2, 1, 1]),
|
||||
patch("deploy_tool.installer.time.sleep"),
|
||||
):
|
||||
with self.assertRaisesRegex(RuntimeError, "Data Dictionary initialization failed"):
|
||||
ensure_mysql_service_running(
|
||||
lambda _message: None,
|
||||
mysql_executable=Path("mysql.exe"),
|
||||
elevated_runner=lambda _command: 0,
|
||||
)
|
||||
self.assertEqual(find_mysql_error_log(Path("mysql.exe")), error_log)
|
||||
detail = mysql_service_failure_detail(Path("mysql.exe"), 1)
|
||||
self.assertIn("STOPPED", detail)
|
||||
self.assertIn(str(error_log), detail)
|
||||
|
||||
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