fix(proxmox): send guest-agent scripts as bytes

Proxmox base64-encodes the input-data of an agent exec in Perl, which dies
with "Wide character in subroutine entry" as soon as the payload contains
non-ASCII — a Cyrillic comment in a script is enough, so running any such
script on a VM failed with a 500.

Hand the same UTF-8 bytes over as latin-1: the JSON carries plain bytes,
Perl is happy and the guest still receives valid UTF-8.
This commit is contained in:
2026-08-22 01:35:56 +05:00
parent 6796903712
commit 6ac505e481
2 changed files with 28 additions and 1 deletions

View File

@@ -1852,9 +1852,16 @@ class ProxmoxClient(VmMixin, LxcMixin, ClusterMixin, StorageMixin, NetworkMixin,
#
# Proxmox API сам кодирует input-data в base64 перед передачей
# guest agent'у, поэтому передаем сырое содержимое скрипта.
# Proxmox кодирует input-data в base64 силами Perl, а тот падает
# с "Wide character in subroutine entry" на любой строке с
# не-ASCII — например на комментариях кириллицей. Отдаём те же
# UTF-8 байты, представленные как latin-1: в JSON уходят байты,
# гость получает корректный UTF-8.
payload = script_content.encode('utf-8').decode('latin-1')
exec_result = self.proxmox.nodes(node).qemu(vmid).agent.exec.post(
command=[interpreter],
**{'input-data': script_content}
**{'input-data': payload}
)
if 'pid' not in exec_result:

View File

@@ -103,3 +103,23 @@ def test_include_live_false_skips_live_endpoint():
# Stopped container: querying /interfaces would only produce a 500.
assert _client_with_mock(px).get_container_interfaces("pve1", 130, include_live=False) == []
lxc.interfaces.get.assert_not_called()
def test_execute_script_sends_bytes_not_wide_chars():
"""Скрипт с кириллицей не должен ронять Perl-обработчик Proxmox.
PVE кодирует input-data в base64 средствами Perl и падает с
"Wide character in subroutine entry" на любой строке с не-ASCII.
Отдаём UTF-8 байты, представленные как latin-1.
"""
px = MagicMock()
agent = px.nodes.return_value.qemu.return_value.agent
agent.exec.post.return_value = {"pid": 1}
agent("exec-status").get.return_value = {"exited": 1, "exitcode": 0, "out-data": "ok"}
script = "#!/bin/sh\n# комментарий с кириллицей\necho ok\n"
_client_with_mock(px).execute_script("prod", 102, script)
sent = agent.exec.post.call_args.kwargs["input-data"]
assert all(ord(ch) < 256 for ch in sent), "в API уходят широкие символы"
assert sent.encode("latin-1").decode("utf-8") == script