mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
refactor(instances): a new disk's name prefix comes from vol_dev_type
get_new_disk_dev() mapped virtio to vd, ide to hd, fdc to fd and other buses to sd itself; vrtManager.util.vol_dev_type() has that mapping, and the bus change in vrtManager uses it with the same sd fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
cc104716e0
commit
f97708a7b7
2 changed files with 13 additions and 10 deletions
|
|
@ -6,9 +6,10 @@ from unittest.mock import patch
|
|||
|
||||
from computes.models import Compute
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
from django.urls import reverse
|
||||
from instances.models import Instance
|
||||
from instances.utils import get_new_disk_dev
|
||||
|
||||
|
||||
def dev(name, bus):
|
||||
|
|
@ -84,3 +85,12 @@ class NewDiskNameTestCase(TestCase):
|
|||
def test_a_cdrom_without_media_is_empty(self):
|
||||
call = self.attach("add_cdrom", {"bus": "scsi", "media": ""}, status=1)
|
||||
self.assertEqual((call.kwargs["target_bus"], call.args[1]), ("scsi", ""))
|
||||
|
||||
|
||||
class BusPrefixTestCase(SimpleTestCase):
|
||||
def test_each_bus_names_its_disks_with_its_prefix(self):
|
||||
for bus, name in (("virtio", "vdb"), ("ide", "hdb"), ("fdc", "fdb"), ("sata", "sdb"), ("scsi", "sdb"),
|
||||
("usb", "sdb"), ("xen", "sdb")):
|
||||
with self.subTest(bus=bus):
|
||||
taken = [{"dev": name[:2] + "a"}]
|
||||
self.assertEqual(get_new_disk_dev(taken, [], bus), name) # a CD-ROM's name is taken too
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from logs.audit import reason, write
|
|||
from operations.models import Operation
|
||||
from vrtManager.connection import other_hosts, wvmConnect
|
||||
from vrtManager.instance import wvmInstance, wvmInstances
|
||||
from vrtManager.util import ConnectionFailed, message
|
||||
from vrtManager.util import ConnectionFailed, message, vol_dev_type
|
||||
|
||||
from .models import Instance
|
||||
|
||||
|
|
@ -206,14 +206,7 @@ def check_user_quota(user, instance, cpu, memory, disk_size):
|
|||
def get_new_disk_dev(media, disks, bus):
|
||||
existing_disk_devs = []
|
||||
existing_media_devs = []
|
||||
if bus == "virtio":
|
||||
dev_base = "vd"
|
||||
elif bus == "ide":
|
||||
dev_base = "hd"
|
||||
elif bus == "fdc":
|
||||
dev_base = "fd"
|
||||
else:
|
||||
dev_base = "sd"
|
||||
dev_base = vol_dev_type(bus) or "sd"
|
||||
|
||||
if disks:
|
||||
existing_disk_devs = [disk["dev"] for disk in disks]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue