hotfix: autoscaler main() setup_logging arg

setup_logging() takes a log LEVEL, not a logger name; passing
'cloud.autoscaler' raised ValueError at startup, so the scaler
crash-looped under systemd and started zero workers (the host
had no worker at all until this fix). The '/opt/.../-m'
FileNotFoundError in the same journal lines is only Ubuntu's
apport hook misfiring on 'python3 -m', not a second bug.
Regression test: main() with mocked run_loop/signal must reach
the loop (this would have caught the crash before deploy).
This commit is contained in:
host committed 2026-10-26 07:02:31 +08:00
1 parent 1f4463209b
commit 26daddf909
2 files changed
+17 -1

No files matched your search

+16
View File
@@ -160,6 +160,22 @@ class AutoscalerReconcileTestCase(unittest.TestCase):
self.assertIn("--db", cmd)
self.assertEqual(cmd[cmd.index("--db") + 1], self.db_path)
def test_main_parses_args_and_starts_loop(self):
# 回归:main() 里 setup_logging 曾错传 logger 名当 level,
# 直接 ValueError,scaler 在主机上 crash-loop、一个 worker
# 都没拉起来。本测试 mock 掉 run_loop 与 signal,只验证
# main() 能走到启动循环(即参数解析与日志初始化没炸)。
from unittest import mock
import cloud.autoscaler as autoscaler_mod
with mock.patch.object(
autoscaler_mod.Autoscaler, "run_loop") as mock_loop, \
mock.patch("signal.signal"):
autoscaler_mod.main([
"--db", self.db_path, "--interval", "30",
"--", "--interval", "10"])
mock_loop.assert_called_once()
if __name__ == "__main__":
unittest.main()