mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 04:06:47 +00:00
chore: remove code nothing uses
Each was checked with git grep across every tracked file (templates, JS, shell, unit files and the extensionless console daemons) and for dynamic use (URL names, template names, registries): - vrtManager: host_is_up, is_kvm_supported, get_emulators, get_file_extensions, both get_network_forward, get_snapshots, get_storages_images, get_os_type, get_host_arch, the get_pretty_* trio and, in util, is_kvm_available, randomMAC, get_max_vcpus, compareMAC, pretty_mem, pretty_bytes and validate_uuid; with them the port constants only host_is_up read. Some were reached only by their tests, which go too. - The flavor edit page: nothing linked to it; flavors are created and deleted on the Flavors page and edited through the API. - computes.validate_name, UserForm.identity_has_errors, the has_perm template tag, the ALLOW_EMPTY_PASSWORD setting nothing reads, hidePleaseWaitDialog, default_app_config (ignored since Django 4.1) and the Python < 3.6 lines of secret_generator.py.
This commit is contained in:
parent
02412b7ea5
commit
764cbb3c43
26 changed files with 307 additions and 690 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import contextlib
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
|
|
@ -21,29 +20,6 @@ from vrtManager import connection
|
|||
from vrtManager.connection import CONN_SSH, CONN_TCP, SSH_COMMAND, wvmConnectionManager
|
||||
|
||||
|
||||
def closed_port():
|
||||
sock = socket.socket()
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
port = sock.getsockname()[1]
|
||||
sock.close()
|
||||
return port
|
||||
|
||||
|
||||
class HostIsUpTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.manager = wvmConnectionManager.__new__(wvmConnectionManager)
|
||||
|
||||
def test_reachable_host_is_true(self):
|
||||
server = socket.socket()
|
||||
server.bind(("127.0.0.1", 0))
|
||||
server.listen(1)
|
||||
self.addCleanup(server.close)
|
||||
self.assertIs(self.manager.host_is_up(CONN_TCP, f"127.0.0.1:{server.getsockname()[1]}"), True)
|
||||
|
||||
def test_unreachable_host_is_false_not_an_exception(self):
|
||||
self.assertIs(self.manager.host_is_up(CONN_TCP, f"127.0.0.1:{closed_port()}"), False)
|
||||
|
||||
|
||||
class ConnectionManagerTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
patcher = patch("vrtManager.connection.wvmEventLoop")
|
||||
|
|
|
|||
|
|
@ -6,16 +6,10 @@ if not settings.configured:
|
|||
settings.configure(MAC_OUI="52:54:10")
|
||||
|
||||
from vrtManager.util import (
|
||||
compareMAC,
|
||||
get_xml_path,
|
||||
is_kvm_available,
|
||||
pretty_bytes,
|
||||
pretty_mem,
|
||||
randomMAC,
|
||||
randomPasswd,
|
||||
randomUUID,
|
||||
validate_macaddr,
|
||||
validate_uuid,
|
||||
vol_dev_type,
|
||||
vol_driver_type,
|
||||
xml_escape,
|
||||
|
|
@ -31,38 +25,6 @@ class TestVrtManagerUtil(unittest.TestCase):
|
|||
# Ensure successive UUIDs are distinct
|
||||
self.assertNotEqual(uuid_str, randomUUID())
|
||||
|
||||
def test_validate_uuid(self):
|
||||
valid_dashed = "c9a646d3-9c61-4cd8-8024-f6b72a6642d9"
|
||||
self.assertEqual(validate_uuid(valid_dashed), valid_dashed)
|
||||
|
||||
valid_no_dash = "c9a646d39c614cd88024f6b72a6642d9"
|
||||
self.assertEqual(validate_uuid(valid_no_dash), valid_dashed)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
validate_uuid("invalid-uuid-too-short")
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
validate_uuid(12345)
|
||||
|
||||
def test_random_mac(self):
|
||||
mac = randomMAC()
|
||||
self.assertTrue(mac.startswith("52:54:10:"))
|
||||
parts = mac.split(":")
|
||||
self.assertEqual(len(parts), 6)
|
||||
for part in parts:
|
||||
self.assertEqual(len(part), 2)
|
||||
int(part, 16) # valid hex
|
||||
|
||||
def test_compare_mac(self):
|
||||
mac1 = "52:54:10:00:00:01"
|
||||
mac2 = "52:54:10:00:00:02"
|
||||
self.assertEqual(compareMAC(mac1, mac1), 0)
|
||||
self.assertEqual(compareMAC(mac1, mac2), -1)
|
||||
self.assertEqual(compareMAC(mac2, mac1), 1)
|
||||
# Different lengths
|
||||
self.assertEqual(compareMAC("52:54", "52:54:10"), -1)
|
||||
self.assertEqual(compareMAC("52:54:10", "52:54"), 1)
|
||||
|
||||
def test_validate_macaddr(self):
|
||||
self.assertIsNone(validate_macaddr(None))
|
||||
self.assertIsNone(validate_macaddr("52:54:10:aa:bb:cc"))
|
||||
|
|
@ -103,23 +65,6 @@ class TestVrtManagerUtil(unittest.TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
get_xml_path(xml)
|
||||
|
||||
def test_is_kvm_available(self):
|
||||
kvm_xml = "<capabilities><guest><arch name='x86_64'><domain type='kvm'/></arch></guest></capabilities>"
|
||||
qemu_xml = "<capabilities><guest><arch name='x86_64'><domain type='qemu'/></arch></guest></capabilities>"
|
||||
self.assertTrue(is_kvm_available(kvm_xml))
|
||||
self.assertFalse(is_kvm_available(qemu_xml))
|
||||
|
||||
def test_pretty_mem(self):
|
||||
# Value in KB
|
||||
self.assertEqual(pretty_mem(1024), " 1 MB")
|
||||
self.assertEqual(pretty_mem(1024 * 1024), "1024 MB")
|
||||
self.assertEqual(pretty_mem(16 * 1024 * 1024), "16.00 GB")
|
||||
|
||||
def test_pretty_bytes(self):
|
||||
# Value in Bytes
|
||||
self.assertEqual(pretty_bytes(10 * 1024 * 1024), "10.00 MB")
|
||||
self.assertEqual(pretty_bytes(2 * 1024 * 1024 * 1024), "2.00 GB")
|
||||
|
||||
def test_vol_dev_type(self):
|
||||
self.assertEqual(vol_dev_type("ide"), "hd")
|
||||
self.assertEqual(vol_dev_type("fdc"), "fd")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue