mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +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
|
|
@ -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