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

fix(storages): a pool the host does not have goes back to the pools list

Opening /computes/<id>/storage/<pool>/ for a pool the host does not
have (or a host that does not answer) raised libvirt's error out of
the view: a 500. Now the pools list shows the reason, as the network
page does.
This commit is contained in:
catborise 2026-11-03 14:45:45 +03:00
parent 9bd61858cd
commit e79841ab1a
2 changed files with 21 additions and 3 deletions

View file

@ -40,6 +40,22 @@ class GetVolumesViewTests(TestCase):
self.assertEqual(response.json()["vols"], ["a.qcow2", "b.qcow2"])
class PoolPageTests(TestCase):
def setUp(self):
get_user_model().objects.create_superuser(username="pool_admin", password="password", email="pool_admin@example.com")
self.client.login(request=RequestFactory().get("/"), username="pool_admin", password="password")
self.compute = Compute.objects.create(name="PoolCompute", hostname="localhost", type=1, login="u", password="p")
@patch("storages.views.wvmStorage")
def test_a_pool_the_host_does_not_have_goes_back_to_the_pools_with_the_reason(self, mock_wvm):
from libvirt import libvirtError
mock_wvm.side_effect = libvirtError("Storage pool not found: no storage pool with matching name 'default'")
response = self.client.get(reverse("storage", args=[self.compute.id, "default"]))
self.assertRedirects(response, reverse("storages", args=[self.compute.id]), fetch_redirect_response=False)
self.assertIn("no storage pool with matching name", str(list(get_messages(response.wsgi_request))[0]))
class VolumeDeleteTests(TestCase):
"""A volume a VM still needs is refused with its reason, on the page and in the API."""

View file

@ -119,9 +119,11 @@ def storage(request, compute_id, pool):
compute = get_object_or_404(Compute, pk=compute_id)
form = CreateVolumeForm()
conn = wvmStorage(
compute.hostname, compute.login, compute.password, compute.type, pool
)
try:
conn = wvmStorage(compute.hostname, compute.login, compute.password, compute.type, pool)
except libvirtError as lib_err: # no such pool on the host, or the host does not answer
messages.error(request, lib_err)
return HttpResponseRedirect(reverse("storages", args=[compute_id]))
if request.method == "POST" and "iso_upload" in request.POST:
try: