mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 19:56:48 +00:00
fix(interfaces): no create, start, stop or delete where libvirt cannot change interfaces
libvirt's udev interface backend (RHEL 9 and later, Debian 12) only reads interfaces, so the create form and the start, stop and delete buttons only failed there. The pages ask the host with an invalid definition, which defines nothing: a backend without define refuses it as not supported. There they show the interface state and a note instead, and posts change nothing; the host's devices, needed only by the create form, are not read. Any other answer keeps the pages as they were.
This commit is contained in:
parent
35fea424ee
commit
0bb4337043
9 changed files with 175 additions and 12 deletions
42
interfaces/test_live_interfaces.py
Normal file
42
interfaces/test_live_interfaces.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""Live check that asking a host whether it can change interfaces defines
|
||||
nothing, and that the interfaces page follows the answer. Runs only with
|
||||
TEST_LIBVIRT_HOST set; TEST_LIBVIRT_SSH_HOST/_LOGIN add an ssh compute."""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from computes.models import Compute
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from vrtManager.connection import wvmConnect
|
||||
|
||||
|
||||
@unittest.skipUnless(os.environ.get("TEST_LIBVIRT_HOST"), "Set TEST_LIBVIRT_HOST to run the live libvirt tests")
|
||||
class LiveInterfacesTestCase(TestCase):
|
||||
def hosts(self):
|
||||
yield "tcp", (
|
||||
os.environ["TEST_LIBVIRT_HOST"],
|
||||
os.environ.get("TEST_LIBVIRT_LOGIN", ""),
|
||||
os.environ.get("TEST_LIBVIRT_PASSWORD", ""),
|
||||
int(os.environ.get("TEST_LIBVIRT_TYPE", 1)),
|
||||
)
|
||||
if os.environ.get("TEST_LIBVIRT_SSH_HOST"):
|
||||
yield "ssh", (os.environ["TEST_LIBVIRT_SSH_HOST"], os.environ.get("TEST_LIBVIRT_SSH_LOGIN", "root"), "", 2)
|
||||
|
||||
def test_the_question_defines_nothing_and_the_page_follows_the_answer(self):
|
||||
self.client.force_login(get_user_model().objects.create_superuser("live-iface", "li@example.com", "x"))
|
||||
for name, args in self.hosts():
|
||||
with self.subTest(name):
|
||||
conn = wvmConnect(*args)
|
||||
before = sorted(i.XMLDesc(0) for i in conn.wvm.listAllInterfaces(0))
|
||||
changeable = conn.can_change_interfaces()
|
||||
self.assertIsInstance(changeable, bool)
|
||||
self.assertEqual(sorted(i.XMLDesc(0) for i in conn.wvm.listAllInterfaces(0)), before)
|
||||
hostname, login, password, conn_type = args
|
||||
compute = Compute.objects.create(
|
||||
name=f"live-{name}", hostname=hostname, login=login, password=password, type=conn_type
|
||||
)
|
||||
page = self.client.get(reverse("interfaces", args=[compute.id])).content.decode()
|
||||
self.assertEqual("#AddInterface" in page, changeable)
|
||||
self.assertEqual("does not support changing network interfaces" in page, not changeable)
|
||||
Loading…
Add table
Add a link
Reference in a new issue