part 4 附带:vm.boot/vm.create 500 记响应体
_boot_vm 只留 status 导致间歇 500 根因无法定位(两轮已提, 未改)。_api_call 的两个调用点现在都把响应体(截断到 500 字符单行)放进 ChvFailure 消息:vm_create_failed 与 vm_boot_failed 均含 status 与 body。body 是 VMM 的报错文本, 不含秘密;超长截断并标明。 新测试:test_wake_vm_boot_failed_records_body、 test_wake_vm_create_failed_records_body、 test_wake_vm_boot_failed_body_truncated。
This commit is contained in:
1 parent
7a227323f2
commit
f20cbc79cd
2 files changed
+55
-4
No files matched your search
@@ -213,6 +213,42 @@ class WakeFailureTest(CloseupCase):
|
||||
with self.assertRaises(ChvFailure) as ctx:
|
||||
ex.wake_vm(self._task())
|
||||
self.assertEqual(ctx.exception.kind, "vm_boot_failed")
|
||||
|
||||
def test_wake_vm_boot_failed_records_body(self):
|
||||
# part 4:vm.boot 500 只留 status 即无法定位——body 要进
|
||||
# 失败消息(截断后,见 _truncate_api_body)。
|
||||
def api(socket_path, method, path, payload=None):
|
||||
if method == "PUT" and path == "/vm.boot":
|
||||
return (500, {"error": "boom-detail-500"})
|
||||
return (200, {})
|
||||
ex = self.make_exec(api_client=api)
|
||||
with self.assertRaises(ChvFailure) as ctx:
|
||||
ex.wake_vm(self._task())
|
||||
self.assertEqual(ctx.exception.kind, "vm_boot_failed")
|
||||
self.assertIn("boom-detail-500", str(ctx.exception))
|
||||
self.assertIn("status=500", str(ctx.exception))
|
||||
|
||||
def test_wake_vm_create_failed_records_body(self):
|
||||
def api(socket_path, method, path, payload=None):
|
||||
if method == "PUT" and path == "/vm.create":
|
||||
return (500, "No bootitem named default")
|
||||
return (200, {})
|
||||
ex = self.make_exec(api_client=api)
|
||||
with self.assertRaises(ChvFailure) as ctx:
|
||||
ex.wake_vm(self._task())
|
||||
self.assertEqual(ctx.exception.kind, "vm_create_failed")
|
||||
self.assertIn("No bootitem named default", str(ctx.exception))
|
||||
|
||||
def test_wake_vm_boot_failed_body_truncated(self):
|
||||
def api(socket_path, method, path, payload=None):
|
||||
if method == "PUT" and path == "/vm.boot":
|
||||
return (500, {"error": "x" * 2000})
|
||||
return (200, {})
|
||||
ex = self.make_exec(api_client=api)
|
||||
with self.assertRaises(ChvFailure) as ctx:
|
||||
ex.wake_vm(self._task())
|
||||
self.assertIn("已截断", str(ctx.exception))
|
||||
self.assertLess(len(str(ctx.exception)), 1200)
|
||||
self.assertIn("vm_failed", self._audit_events())
|
||||
self.assertEqual(ex._vms, {})
|
||||
|
||||
|
||||
Reference in new issue
Block a user