mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +00:00
fix(computes): hosts that do not answer no longer keep the Computes page from the others
The Computes page read its hosts on a pool of eight threads shared by the process: eight hosts that hang held all of them for as long as they hung, and every other host was then shown not connected. Each host is now read on a thread of its own (a daemon thread, which does not keep the process from exiting), one at a time per host as before. The UUID of a host added before host UUIDs were kept is read on that thread too, within the page's wait, instead of after it. A host's charts asked for each reading without a time limit: a reading the host kept waiting left the charts saying "Updated" and stopped the polling. A reading now ends after 30 s; the charts then say since when they are not updated, and the next reading goes out.
This commit is contained in:
parent
a998e68757
commit
1f6cc15ddf
5 changed files with 93 additions and 32 deletions
|
|
@ -113,7 +113,7 @@ class GraphScriptTestCase(TestCase):
|
|||
script = (settings.BASE_DIR / "static/js/host_graphs.js").read_text()
|
||||
js = """
|
||||
const vm = require("vm");
|
||||
const charts = [], requests = [];
|
||||
const charts = [], requests = [], timeouts = [];
|
||||
const element = (dataset) => ({dataset, textContent: "", classList: {add: () => {}, remove: () => {}}});
|
||||
const elements = {graph_state: element(DATASET),
|
||||
cpu_now: element({}), mem_now: element({})};
|
||||
|
|
@ -129,7 +129,7 @@ class GraphScriptTestCase(TestCase):
|
|||
this.update = () => {};
|
||||
charts.push(this);
|
||||
}, {defaults: {}}),
|
||||
$: {getJSON: (url, params) => { requests.push(params); return {fail() { return this; }}; }},
|
||||
$: {ajax: (options) => { requests.push(options.data); timeouts.push(options.timeout); return {fail() { return this; }}; }},
|
||||
pollWhileVisible: (interval, request, onData) => { poll = {request, onData}; },
|
||||
};
|
||||
const context = vm.createContext(page);
|
||||
|
|
@ -144,7 +144,7 @@ class GraphScriptTestCase(TestCase):
|
|||
poll.onData({cpudata: null, memdata: {total: null, usage: null}, timeline: "t"});
|
||||
poll.request();
|
||||
const label = charts[0].options.plugins.tooltip.callbacks.label({dataset: {label: "Usage"}, formattedValue: "3", dataIndex: 0});
|
||||
console.log(JSON.stringify({requests, label, shown, state: elements.graph_state.textContent,
|
||||
console.log(JSON.stringify({requests, timeouts, label, shown, state: elements.graph_state.textContent,
|
||||
cpu: charts[0].data.datasets[0].data,
|
||||
mem: charts[1].data.datasets[0].data, memMax: charts[1].options.scales.y.max}));
|
||||
""".replace("SCRIPT", json.dumps(script)).replace("CHARTS", json.dumps(CHARTS_JS.read_text())).replace(
|
||||
|
|
@ -153,6 +153,8 @@ class GraphScriptTestCase(TestCase):
|
|||
self.assertEqual(out.returncode, 0, out.stderr)
|
||||
result = json.loads(out.stdout)
|
||||
self.assertEqual(result["requests"], [{}, {"cpu_sample": "token-1"}, {}])
|
||||
# a reading the host keeps waiting ends: the charts then say they are not updated
|
||||
self.assertEqual(result["timeouts"], [30000] * 3)
|
||||
self.assertEqual(result["cpu"], [3, None])
|
||||
# a host that could not be read leaves a gap and keeps the memory axis
|
||||
self.assertEqual((result["mem"], result["memMax"]), ([1, None], 2))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class ListHostsTests(TestCase):
|
|||
def read(self, compute):
|
||||
if compute.name.startswith("slow"):
|
||||
self.release.wait(5)
|
||||
return True, None, None
|
||||
return True, None, None, ""
|
||||
|
||||
def test_hosts_that_do_not_answer_are_waited_for_together_and_shown_so(self):
|
||||
with patch("computes.views._read_host", side_effect=self.read), patch("computes.views.LIST_WAIT", 0.5):
|
||||
|
|
@ -43,3 +43,33 @@ class ListHostsTests(TestCase):
|
|||
self.client.get(reverse("computes"))
|
||||
self.assertEqual(sorted(call.args[0].name for call in read.call_args_list),
|
||||
["fast", "fast", "slow-1", "slow-2"])
|
||||
|
||||
def test_many_hosts_that_do_not_answer_leave_the_others_read(self):
|
||||
# each host has its own thread: nine stuck hosts, read first, take no place of the one that answers
|
||||
for number in range(3, 10):
|
||||
Compute.objects.create(name=f"slow-{number}", hostname="192.0.2.1", login="wvc", password="", type=1,
|
||||
host_uuid=f"{number}" * 8 + "-0000-0000-0000-000000000000")
|
||||
Compute.objects.filter(name="fast").update(name="z-fast") # the page lists by name: the last one
|
||||
with patch("computes.views._read_host", side_effect=self.read), patch("computes.views.LIST_WAIT", 0.5):
|
||||
response = self.client.get(reverse("computes"))
|
||||
shown = {compute.name: compute.status for compute in response.context["computes"]}
|
||||
self.assertIs(shown["z-fast"], True)
|
||||
self.assertEqual(sum(status is False for status in shown.values()), 9)
|
||||
|
||||
def test_a_compute_given_another_host_is_read_anew(self):
|
||||
# a read of its old host still running: its answer is not the new host's
|
||||
old = Compute.objects.get(name="slow-1")
|
||||
with patch("computes.views._read_host", side_effect=self.read) as read, patch("computes.views.LIST_WAIT", 0.2):
|
||||
self.client.get(reverse("computes"))
|
||||
Compute.objects.filter(pk=old.pk).update(hostname="192.0.2.99")
|
||||
self.client.get(reverse("computes"))
|
||||
hosts = [call.args[0].hostname for call in read.call_args_list if call.args[0].pk == old.pk]
|
||||
self.assertEqual(hosts, ["192.0.2.1", "192.0.2.99"])
|
||||
|
||||
def test_a_host_uuid_is_read_with_the_host_and_kept(self):
|
||||
# one added before host UUIDs were kept: read within the list's wait, saved after it
|
||||
Compute.objects.filter(name="fast").update(host_uuid="")
|
||||
uuid = "abcdabcd-0000-0000-0000-000000000000"
|
||||
with patch("computes.views._read_host", return_value=(True, None, None, uuid)):
|
||||
self.client.get(reverse("computes"))
|
||||
self.assertEqual(Compute.objects.get(name="fast").host_uuid, uuid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue