1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00

fix(instances): Guest Info says when the agent fails and keeps what it answered

When the guest agent failed, the Guest Info section stayed empty with no
word: the request's error answer was not handled. An agent without the
time zone or host name command lost the OS details it had answered too.
The section now shows the agent's error, and a missing command leaves out
only its own details.
This commit is contained in:
catborise 2026-10-26 12:12:39 +03:00
parent e29a79c76d
commit 11348b2c37
4 changed files with 29 additions and 11 deletions

View file

@ -438,15 +438,17 @@
}
function load_osinfo() {
$.getJSON("{% url 'instances:osinfo' instance.id %}", function (data) {
$.each(data, function() {
$('#oshostname').text(data['host-name']);
$('#osname').text(data.id);
$('#osprettyname').text(data['pretty-name']);
$('#oskernelrelease').text(data['kernel-release']);
$('#oskernelversion').text(data['kernel-version']);
$('#osversion').text(data.version);
$('#ostimezone').text(data.zone + " / " + data.offset);
})
$('#osinfo-error').addClass('d-none');
$('#oshostname').text(data['host-name'] || '');
$('#osname').text(data.id || '');
$('#osprettyname').text(data['pretty-name'] || '');
$('#oskernelrelease').text(data['kernel-release'] || '');
$('#oskernelversion').text(data['kernel-version'] || '');
$('#osversion').text(data.version || '');
$('#ostimezone').text(data.zone ? data.zone + " / " + data.offset : '');
}).fail(function (xhr) {
var error = xhr.responseJSON && xhr.responseJSON.error;
$('#osinfo-error').text(error || "{% trans 'The guest agent did not answer' %}").removeClass('d-none');
});
}
</script>

View file

@ -1,6 +1,7 @@
{% load i18n %}
<div class="tab-pane tab-pane-bordered" id="osinfo" role="tabpanel">
<h3 class="page-header">{% trans "Guest Info" %}</h3>
<div id="osinfo-error" class="alert alert-warning d-none" role="alert"></div>
<dl class="mx-3 row">
<dt class="col-3">{% trans "Hostname" %}</dt>
<dd class="col-9" id="oshostname"></dd>

View file

@ -389,8 +389,10 @@ class wvmInstance(wvmConnect):
def osinfo(self):
info = agent_command(self.instance, "guest-get-osinfo")
info.update(agent_command(self.instance, "guest-get-timezone"))
info.update(agent_command(self.instance, "guest-get-host-name"))
# an agent without one of these commands still gives the rest
for command in ("guest-get-timezone", "guest-get-host-name"):
with contextlib.suppress(libvirtError):
info.update(agent_command(self.instance, command))
return info
def start(self, flags=0):

View file

@ -71,6 +71,19 @@ class OsInfoTestCase(unittest.TestCase):
self.assertEqual(inst.osinfo(), {"kernel-release": "6.12", "zone": "UTC", "host-name": "web"})
self.assertEqual({c.args[2] for c in agent.call_args_list}, {10})
def test_a_command_the_agent_lacks_leaves_out_only_its_details(self):
inst = wvmInstance.__new__(wvmInstance)
inst.instance = MagicMock()
def agent(dom, cmd, timeout, flags):
if json.loads(cmd)["execute"] == "guest-get-timezone":
raise libvirtError("The command guest-get-timezone has not been found")
return json.dumps({"return": {"guest-get-osinfo": {"id": "alma"}, "guest-get-host-name": {"host-name": "web"}}[
json.loads(cmd)["execute"]]})
with patch.object(module, "qemuAgentCommand", side_effect=agent):
self.assertEqual(inst.osinfo(), {"id": "alma", "host-name": "web"})
if __name__ == "__main__":
unittest.main()