1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +00:00

fix(instances): the new-VM host dialog says when no compute is reachable

The dialog looped over every compute and skipped the unreachable ones,
so its "No compute is reachable." message showed only when there were no
computes at all. With hosts that were all offline it was an empty list.

The index view now gives the dialog the reachable computes, and the
template lists those, so the message covers that case.

Fixes #176

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
catborise 2026-10-24 11:29:38 +03:00
parent 9c6e07a467
commit 4f0ae3b30d
3 changed files with 58 additions and 28 deletions

View file

@ -112,3 +112,34 @@ class CreateDialogCpuTestCase(TestCase):
# the earlier opening's answer (99) is ignored; a failed read is a dash
self.assertEqual(result["final"], [["42%", "42", "42%"], ["0%", None, "—"], ["0%", None, "…"]])
self.assertEqual(result["all"], urls[:2] + urls + urls)
class CreateDialogHostsTestCase(TestCase):
"""The dialog lists the reachable computes; without one it says so."""
def setUp(self):
self.client.force_login(get_user_model().objects.create_superuser("cd-admin", "cd@example.com", "pw"))
for i in (1, 2):
Compute.objects.create(name=f"cd{i}", hostname=f"192.0.2.{i}", login="u", password="p", type=1)
for name, value in (("cpu_count", 1), ("ram_size", 1024), ("ram_usage", 0)):
p = patch.object(Compute, name, new_callable=PropertyMock, return_value=value)
p.start()
self.addCleanup(p.stop)
p = patch("instances.views.utils.refr")
p.start()
self.addCleanup(p.stop)
def dialog(self, reachable):
with patch.object(Compute, "status", property(lambda compute: compute.name in reachable)):
response = self.client.get(reverse("instances:index"))
return html.fromstring(response.content).get_element_by_id("AddInstance")
def test_only_reachable_computes_are_listed(self):
dialog = self.dialog({"cd2"})
self.assertEqual([e.text for e in dialog.xpath(".//a/div/div[1]")], ["cd2"])
self.assertNotIn("No compute is reachable.", dialog.text_content())
def test_no_reachable_compute_is_said(self):
dialog = self.dialog(set())
self.assertEqual(dialog.xpath(".//a"), [])
self.assertIn("No compute is reachable.", dialog.text_content())