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

fix(storages): a volume another compute's VM uses on shared storage is not deleted

A pool on shared storage (an NFS share, or a directory mounted from one)
holds the same file at the same path on every host that mounts it. A
VM's delete checks the panel's other computes before it deletes its disk
files, but the pool page, its API and a VM's disk delete checked only
their own host: a disk of a VM on another compute could be deleted. They
now ask the other computes too, and refuse while one uses the file or
cannot be reached. The other computes are asked before this host's lock
is taken, and before a VM's disk is detached.
This commit is contained in:
catborise 2026-11-13 10:31:22 +03:00
parent fb3b2f479e
commit 143a74b145
11 changed files with 277 additions and 196 deletions

View file

@ -3,7 +3,7 @@ Disk and media mutation views must be superuser-only (matching the UI, where
the Disk tab is only rendered for superusers), and even for superusers the
views must not act on volumes or option values taken blindly from the client.
"""
from unittest.mock import patch
from unittest.mock import ANY, patch
from django.contrib.auth import get_user_model
from django.contrib.messages import get_messages
@ -118,6 +118,22 @@ class DiskViewsTenantIsolationTestCase(TestCase):
mock_wvm.return_value.detach_disk.assert_called_once_with("vda")
self.assertEqual(mock_storage.call_args[0][-1], "default")
mock_storage.return_value.del_volume.assert_called_once_with("vm-disk.qcow2")
mock_storage.return_value.check_unused_elsewhere.assert_called_once_with("vm-disk.qcow2", ANY)
def test_delete_vol_of_a_volume_another_compute_uses_keeps_the_disk_attached(self):
from vrtManager.util import InUse
self.client.force_login(self.superuser)
with patch("instances.models.wvmInstance") as mock_wvm, patch(
"instances.views.wvmStorage"
) as mock_storage:
mock_wvm.return_value.get_disk_devices.return_value = [VM_DISK]
mock_wvm.return_value.get_managed_save_image.return_value = 0
mock_storage.return_value.check_unused_elsewhere.side_effect = InUse("in use on another compute")
res = self._post("delete_vol", {"dev": "vda", "path": VM_DISK["path"]})
self.assertEqual([str(m) for m in get_messages(res.wsgi_request)], ["in use on another compute"])
mock_wvm.return_value.detach_disk.assert_not_called()
mock_storage.return_value.del_volume.assert_not_called()
def test_delete_vol_refuses_dev_not_attached_to_vm(self):
self.client.force_login(self.superuser)

View file

@ -1578,6 +1578,12 @@ def delete_vol(request, pk):
_("Volume %(vol)s is used by another VM; detach it instead") % {"vol": disk["image"]},
)
return _back(request, pk, "disks")
try: # before the disk is detached
conn_delete.check_unused_elsewhere(
disk["image"], lambda paths: utils.paths_used_on_other_computes(instance.compute, paths))
except util.OperationError as err:
messages.error(request, str(err))
return _back(request, pk, "disks")
volume = f"{disk['storage']}/{disk['image']}"
with audit_vm(request, instance, f"detach disk {dev}"):

Binary file not shown.

View file

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-13 07:27+0000\n"
"POT-Creation-Date: 2026-11-13 07:41+0000\n"
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
@ -2734,7 +2734,7 @@ msgstr ""
"VNC olarak değiştirin."
#: instances/api/viewsets.py:149 instances/api/viewsets.py:167
#: instances/views.py:816 instances/views.py:836 instances/views.py:1813
#: instances/views.py:816 instances/views.py:836 instances/views.py:1819
msgid "Templates cannot be started."
msgstr "Şablon makineler başlatılamaz."
@ -3099,7 +3099,7 @@ msgstr ""
msgid "Create VM"
msgstr "Sanal makine oluştur"
#: instances/jobs.py:900 instances/jobs.py:945 instances/views.py:2530
#: instances/jobs.py:900 instances/jobs.py:945 instances/views.py:2536
msgid "A virtual machine with this name already exists"
msgstr "Bu isimde bir sanal makine mevcut"
@ -3463,7 +3463,7 @@ msgid "Disk source"
msgstr "Disk kaynağı"
#: instances/templates/add_instance_volume.html:21
#: instances/templates/create_instance_w2.html:134 instances/views.py:2550
#: instances/templates/create_instance_w2.html:134 instances/views.py:2556
msgid "New disk"
msgstr "Yeni disk"
@ -3489,7 +3489,7 @@ msgid "Storage pool"
msgstr "Depolama havuzu"
#: instances/templates/add_instance_volume.html:41
#: instances/templates/create_instance_w2.html:46 storages/forms.py:107
#: instances/templates/create_instance_w2.html:46 storages/forms.py:119
#: storages/templates/storage.html:182
msgid "Letters, digits, dot, dash and underscore."
msgstr "Harf, rakam, nokta, tire ve alt çizgi."
@ -3507,8 +3507,8 @@ msgstr "Biçem"
#: instances/templates/add_instance_volume.html:61
#: instances/templates/create_instance_w2.html:154
#: instances/templates/create_instance_w2.html:220 storages/forms.py:113
#: storages/forms.py:133 storages/templates/storage.html:197
#: instances/templates/create_instance_w2.html:220 storages/forms.py:125
#: storages/forms.py:145 storages/templates/storage.html:197
msgid "Preallocate metadata (qcow2)"
msgstr "Meta veriyi önceden ayır (qcow2)"
@ -3845,11 +3845,11 @@ msgstr "Seçin…"
msgid "Custom CPU Models"
msgstr "Özel CPU modelleri"
#: instances/templates/create_instance_w2.html:146 storages/forms.py:112
#: instances/templates/create_instance_w2.html:146 storages/forms.py:124
msgid "Size (GiB)"
msgstr "Boyut (GiB)"
#: instances/templates/create_instance_w2.html:161 instances/views.py:2551
#: instances/templates/create_instance_w2.html:161 instances/views.py:2557
msgid "Existing volumes"
msgstr "Mevcut birimler"
@ -3885,7 +3885,7 @@ msgstr "Aygıt"
msgid "Remove"
msgstr "Kaldır"
#: instances/templates/create_instance_w2.html:194 instances/views.py:2552
#: instances/templates/create_instance_w2.html:194 instances/views.py:2558
msgid "Clone from template"
msgstr "Şablondan klonla"
@ -6394,7 +6394,7 @@ msgstr ""
"%(vol)s birimi başka bir sanal makine tarafından kullanılıyor; onun yerine "
"ayırın"
#: instances/views.py:1590
#: instances/views.py:1596
#, python-format
msgid ""
"The guest has not released disk %(dev)s yet; volume %(vol)s was kept. Delete "
@ -6403,66 +6403,66 @@ msgstr ""
"Konuk sistem %(dev)s diskini henüz bırakmadı; %(vol)s birimi korundu. Sanal "
"makine kapatıldığında depolama havuzundan silin."
#: instances/views.py:1601
#: instances/views.py:1607
#, python-format
msgid "Disk %(dev)s was detached, but its volume was kept: %(err)s"
msgstr "%(dev)s diski ayrıldı, ancak birimi korundu: %(err)s"
#: instances/views.py:1629
#: instances/views.py:1635
#, python-format
msgid "This VM cannot take a CD-ROM on the %(bus)s bus now"
msgstr "Bu sanal makineye şu anda %(bus)s veri yolunda CD-ROM eklenemez"
#: instances/views.py:1632
#: instances/views.py:1638
msgid "A USB CD-ROM needs an ISO image: libvirt has no empty USB drive"
msgstr "USB CD-ROM bir ISO imajı ister: libvirt boş USB sürücü desteklemiyor"
#: instances/views.py:1637
#: instances/views.py:1643
#, python-format
msgid "%(image)s is already in a CD-ROM of this VM"
msgstr "%(image)s bu sanal makinenin bir CD-ROM'unda zaten takılı"
#: instances/views.py:1718
#: instances/views.py:1724
#, python-format
msgid "Pool %(pool)s was not read again: %(err)s"
msgstr "%(pool)s havuzu yeniden okunamadı: %(err)s"
#: instances/views.py:1739
#: instances/views.py:1745
#, python-format
msgid "Snapshot was not deleted: %(err)s"
msgstr "Anlık görüntü silinmedi: %(err)s"
#: instances/views.py:1857
#: instances/views.py:1863
msgid "Add at least one device to the boot order."
msgstr "Ön yükleme sırasına en az bir aygıt ekleyin."
#: instances/views.py:1863 vrtManager/instance.py:1161
#: instances/views.py:1869 vrtManager/instance.py:1161
msgid "Invalid Device Type for boot order"
msgstr "Ön yükleme sırası için geçersiz aygıt türü"
#: instances/views.py:1874
#: instances/views.py:1880
msgid "Boot order changed. It applies at the next start."
msgstr "Ön yükleme sırası değiştirildi. Sonraki başlatmada uygulanır."
#: instances/views.py:1876
#: instances/views.py:1882
msgid "Boot order changed successfully."
msgstr "Ön yükleme sırası başarıyla değiştirildi."
#: instances/views.py:1896
#: instances/views.py:1902
msgid "The XML is empty"
msgstr "XML boş"
#: instances/views.py:1900 instances/views.py:2541
#: instances/views.py:1906 instances/views.py:2547
#, python-format
msgid "The XML is not well-formed: %(error)s"
msgstr "XML düzgün biçimlendirilmemiş: %(error)s"
#: instances/views.py:1902
#: instances/views.py:1908
#, python-format
msgid "The XML must keep the VM's UUID %(uuid)s."
msgstr "XML, sanal makinenin %(uuid)s UUID'sini korumalıdır."
#: instances/views.py:1906
#: instances/views.py:1912
msgid ""
"The definition has changed since the editor was opened. Reload the page to "
"edit the current one."
@ -6470,40 +6470,40 @@ msgstr ""
"Düzenleyici açıldığından beri tanım değişti. Geçerli tanımı düzenlemek için "
"sayfayı yeniden yükleyin."
#: instances/views.py:1922
#: instances/views.py:1928
msgid "The XML definition was saved."
msgstr "XML tanımı kaydedildi."
#: instances/views.py:1924
#: instances/views.py:1930
msgid "The XML definition was saved; the VM uses it from its next start."
msgstr ""
"XML tanımı kaydedildi; sanal makine onu sonraki başlatmasından itibaren "
"kullanır."
#: instances/views.py:2005
#: instances/views.py:2011
msgid "Select one network interface to change"
msgstr "Değiştirilecek bir ağ arabirimi seçin"
#: instances/views.py:2043
#: instances/views.py:2049
msgid "Network Device Config is changed. Please shutdown instance to activate."
msgstr ""
"Ağ aygıtı yapılandırması değiştirildi. Aktifleştirmek için lütfen sanal "
"makineyi kapatın."
#: instances/views.py:2045
#: instances/views.py:2051
msgid "Network device changed"
msgstr "Ağ aygıtı değiştirildi"
#: instances/views.py:2057
#: instances/views.py:2063
msgid "No network selected"
msgstr "Ağ seçilmedi"
#: instances/views.py:2062
#: instances/views.py:2068
#, python-format
msgid "The VM already has a network device with MAC %(mac)s"
msgstr "Sanal makinede %(mac)s MAC adresli bir ağ aygıtı zaten var"
#: instances/views.py:2081
#: instances/views.py:2087
msgid ""
"The running VM has no free PCI slot for another network device: shut it down "
"and add the device then; Add PCIe slots on the Disks tab gives it free ones "
@ -6513,21 +6513,21 @@ msgstr ""
"aygıtı sonra ekleyin; Diskler sekmesindeki PCIe yuvaları ekle, sonraki "
"başlatmadan itibaren ona boş yuvalar verir."
#: instances/views.py:2127 instances/views.py:2133
#: instances/views.py:2133 instances/views.py:2139
msgid "The VM has it"
msgstr "Sanal makinede var"
#: instances/views.py:2168
#: instances/views.py:2174
#, python-format
msgid "The host has no USB device %(device)s; reload the page"
msgstr "Sunucuda %(device)s USB aygıtı yok; sayfayı yeniden yükleyin"
#: instances/views.py:2189
#: instances/views.py:2195
#, python-format
msgid "The host has no PCI device %(device)s"
msgstr "Sunucuda %(device)s PCI aygıtı yok"
#: instances/views.py:2207
#: instances/views.py:2213
#, python-format
msgid ""
"Removal of PCI device %(address)s requested: the guest has not let it go yet;"
@ -6537,20 +6537,20 @@ msgstr ""
"bırakmadı; bırakana ya da sanal makine durana kadar çalışan sanal makinede "
"kalır."
#: instances/views.py:2252 instances/views.py:2282
#: instances/views.py:2258 instances/views.py:2288
msgid "Select a network interface and a QoS direction"
msgstr "Bir ağ arabirimi ve bir QoS yönü seçin"
#: instances/views.py:2255 vrtManager/network.py:470
#: instances/views.py:2261 vrtManager/network.py:470
msgid "QoS rates must be whole numbers"
msgstr "QoS hızları tam sayı olmalıdır"
#: instances/views.py:2262 networks/views.py:230
#: instances/views.py:2268 networks/views.py:230
#, python-format
msgid "%(qos_dir)s QoS is set"
msgstr "%(qos_dir)s QoS ayarlandı"
#: instances/views.py:2267
#: instances/views.py:2273
#, python-format
msgid ""
"%(qos_dir)s QoS is set. A running VM gets it after it is powered off and on."
@ -6558,12 +6558,12 @@ msgstr ""
"%(qos_dir)s QoS ayarlandı. Çalışan bir sanal makine, kapatılıp açıldıktan "
"sonra bunu alır."
#: instances/views.py:2289 networks/views.py:256
#: instances/views.py:2295 networks/views.py:256
#, python-format
msgid "%(qos_dir)s QoS is deleted"
msgstr "%(qos_dir)s QoS silindi"
#: instances/views.py:2294
#: instances/views.py:2300
#, python-format
msgid ""
"%(qos_dir)s QoS is deleted. A running VM keeps the old limit until it is "
@ -6572,21 +6572,21 @@ msgstr ""
"%(qos_dir)s QoS silindi. Çalışan bir sanal makine, kapatılıp açılana kadar "
"eski sınırı korur."
#: instances/views.py:2322
#: instances/views.py:2328
msgid "Only one owner is allowed and the one already added"
msgstr "Sadece bir sahibe izin verilmiştir ve bir sahip zaten eklenmiş"
#: instances/views.py:2324
#: instances/views.py:2330
#, python-format
msgid "%(user)s is already an owner"
msgstr "%(user)s zaten bir sahip"
#: instances/views.py:2369
#: instances/views.py:2375
#, python-format
msgid "Console settings were not saved: %(errors)s"
msgstr "Konsol ayarları kaydedilmedi: %(errors)s"
#: instances/views.py:2391
#: instances/views.py:2397
msgid ""
"Error setting console password. You should check that your instance have an "
"graphic device."
@ -6594,37 +6594,37 @@ msgstr ""
"Konsol parolası ayarlanırken hata oluştu. Sanal makinenin bir grafik aygıtına"
" sahip olduğundan emin olunuz."
#: instances/views.py:2438
#: instances/views.py:2444
msgid "Shut the VM down to change whether it is a template."
msgstr "Şablon olup olmadığını değiştirmek için sanal makineyi kapatın."
#: instances/views.py:2444
#: instances/views.py:2450
#, python-format
msgid "%(quota)s: '%(instance_name)s' stays a template."
msgstr "%(quota)s: '%(instance_name)s' şablon olarak kalıyor."
#: instances/views.py:2528
#: instances/views.py:2534
msgid "The XML has no name"
msgstr "XML'de ad yok"
#: instances/views.py:2543 webvirtcloud/middleware.py:156
#: instances/views.py:2549 webvirtcloud/middleware.py:156
#, python-format
msgid "libvirt Error - %(exception)s"
msgstr "libvirt Hatası - %(exception)s"
#: instances/views.py:2550
#: instances/views.py:2556
msgid "An empty disk of the size you set"
msgstr "Belirlediğiniz boyutta boş bir disk"
#: instances/views.py:2551
#: instances/views.py:2557
msgid "Volumes already in a pool"
msgstr "Bir havuzda zaten bulunan birimler"
#: instances/views.py:2552
#: instances/views.py:2558
msgid "A copy of a template volume"
msgstr "Bir şablon biriminin kopyası"
#: instances/views.py:2630
#: instances/views.py:2636
msgid ""
"This host has no running storage pool for the VM's disks: add or start one on"
" its Storage page."
@ -6632,29 +6632,29 @@ msgstr ""
"Bu sunucuda sanal makinenin diskleri için çalışan bir depolama havuzu yok: "
"Depolama sayfasından bir tane ekleyin ya da başlatın."
#: instances/views.py:2632
#: instances/views.py:2638
msgid "This host has no network for the VM: add one on its Networks page."
msgstr ""
"Bu sunucuda sanal makine için ağ yok: Ağlar sayfasından bir tane ekleyin."
#: instances/views.py:2664
#: instances/views.py:2670
#, python-format
msgid "The machine type is q35, not %(machine)s: UEFI Secure Boot needs it"
msgstr "Makine türü %(machine)s değil q35: UEFI Secure Boot bunu gerektiriyor"
#: instances/views.py:2691
#: instances/views.py:2697
msgid "Flavor Created"
msgstr "Flavor Oluşturuldu"
#: instances/views.py:2699
#: instances/views.py:2705
msgid "Create Flavor"
msgstr "Kullanıcı Oluştur"
#: instances/views.py:2711
#: instances/views.py:2717
msgid "Flavor Deleted"
msgstr "Flavor Silindi"
#: instances/views.py:2717
#: instances/views.py:2723
msgid "Only the size template goes; VMs made from it keep their size."
msgstr ""
"Yalnızca boyut şablonu silinir; ondan oluşturulan sanal makineler boyutlarını"
@ -7053,7 +7053,7 @@ msgstr "IPv4 ağ öneki /30 veya daha kısa olmalıdır"
msgid "For libvirt, the IPv6 network prefix must be /64"
msgstr "Libvirt için IPv6 ağ prefixi /64 olmak zorundadır"
#: networks/forms.py:36 storages/forms.py:35
#: networks/forms.py:36 storages/forms.py:47
msgid "No pool name has been entered"
msgstr "Havuz adı girilmedi"
@ -7069,7 +7069,7 @@ msgstr "IPv6 alt ağı"
msgid "Bridge or interface"
msgstr "Köprü veya arabirim"
#: networks/forms.py:56 storages/forms.py:59
#: networks/forms.py:56 storages/forms.py:71
msgid "The pool name must not contain any special characters"
msgstr "Havuz adı herhangi bir özel karakter içermemelidir"
@ -7086,7 +7086,7 @@ msgid "The pool bridge name must not contain any special characters"
msgstr "Havuz köprü adı herhangi bir özel karakter içeremez"
#: networks/forms.py:85 networks/forms.py:89 networks/forms.py:93
#: storages/forms.py:100
#: storages/forms.py:112
msgid "This field is required."
msgstr "Bu alan gerekli."
@ -8215,82 +8215,82 @@ msgstr ""
msgid "The worker stopped before the job changed anything"
msgstr "Worker, iş herhangi bir şeyi değiştirmeden önce durdu"
#: storages/api/viewsets.py:143 storages/api/viewsets.py:159
#: storages/api/viewsets.py:195 storages/api/viewsets.py:215
#: storages/api/viewsets.py:144 storages/api/viewsets.py:160
#: storages/api/viewsets.py:196 storages/api/viewsets.py:218
msgid "Pool is not active"
msgstr "Havuz etkin değil"
#: storages/forms.py:38 storages/templates/storage.html:102
#: storages/forms.py:50 storages/templates/storage.html:102
#: storages/templates/storages.html:43
msgid "Path"
msgstr "Yol"
#: storages/forms.py:39
#: storages/forms.py:51
msgid "Device or remote path"
msgstr "Aygıt veya uzak yol"
#: storages/forms.py:40
#: storages/forms.py:52
msgid "Erase the device"
msgstr "Aygıtı temizle"
#: storages/forms.py:41 storages/templates/create_stg_block.html:110
#: storages/forms.py:53 storages/templates/create_stg_block.html:110
msgid "Ceph user"
msgstr "Ceph kullanıcısı"
#: storages/forms.py:42 storages/templates/create_stg_block.html:98
#: storages/forms.py:54 storages/templates/create_stg_block.html:98
msgid "Ceph monitor"
msgstr "Ceph monitörü"
#: storages/forms.py:43 storages/templates/create_stg_block.html:104
#: storages/forms.py:55 storages/templates/create_stg_block.html:104
msgid "Ceph pool"
msgstr "Ceph havuzu"
#: storages/forms.py:44 storages/templates/create_stg_block.html:116
#: storages/forms.py:56 storages/templates/create_stg_block.html:116
msgid "Ceph secret"
msgstr "Ceph parolası"
#: storages/forms.py:45 storages/templates/create_stg_block.html:139
#: storages/forms.py:57 storages/templates/create_stg_block.html:139
msgid "Server"
msgstr "Sunucu"
#: storages/forms.py:62
#: storages/forms.py:74
msgid "This host has a pool of that name"
msgstr "Bu sunucuda bu adda bir havuz var"
#: storages/forms.py:71
#: storages/forms.py:83
msgid "The target must not contain any special characters"
msgstr "Hedef herhangi bir özel karakter içeremez"
#: storages/forms.py:75
#: storages/forms.py:87
#, python-format
msgid "%(path)s is a system directory of the host"
msgstr "%(path)s, sunucunun bir sistem dizini"
#: storages/forms.py:81
#: storages/forms.py:93
#, python-format
msgid "Pool %(pool)s uses this path"
msgstr "%(pool)s havuzu bu yolu kullanıyor"
#: storages/forms.py:84
#: storages/forms.py:96
#, python-format
msgid "Pool %(pool)s uses %(path)s: one pool's directory cannot hold another's"
msgstr ""
"%(pool)s havuzu %(path)s yolunu kullanıyor: bir havuzun dizini başka bir "
"havuzunkini içeremez"
#: storages/forms.py:92
#: storages/forms.py:104
msgid "The disk source must not contain any special characters"
msgstr "Disk kaynağı herhangi bir özel karakter içermemelidir"
#: storages/forms.py:102
#: storages/forms.py:114
msgid "Choose one of the host's Ceph secrets"
msgstr "Sunucunun Ceph parolalarından birini seçin"
#: storages/forms.py:120 storages/forms.py:140
#: storages/forms.py:132 storages/forms.py:152
msgid "The image name must not contain any special characters"
msgstr "İmaj adı herhangi bir özel karakter içeremez"
#: storages/forms.py:144
#: storages/forms.py:156
msgid "The image name must not exceed 120 characters"
msgstr "İmaj adı 120 karakterden fazla olamaz"
@ -8774,36 +8774,36 @@ msgstr "Son parça bildirilen dosya boyutuyla eşleşmiyor"
msgid "The partial upload is missing"
msgstr "Kısmi yükleme bulunamadı"
#: storages/views.py:29
#: storages/views.py:30
msgid "No file chunk was submitted."
msgstr "Dosya parçası gönderilmedi."
#: storages/views.py:35
#: storages/views.py:36
msgid "Invalid chunk parameters."
msgstr "Geçersiz parça parametreleri."
#: storages/views.py:37
#: storages/views.py:38
msgid "Invalid chunk index or total chunks."
msgstr "Geçersiz parça dizini veya toplam parça sayısı."
#: storages/views.py:42
#: storages/views.py:43
msgid "Invalid file size."
msgstr "Geçersiz dosya boyutu."
#: storages/views.py:51
#: storages/views.py:52
msgid "Upload session is busy. Please retry."
msgstr "Yükleme oturumu meşgul. Lütfen yeniden deneyin."
#: storages/views.py:53
#: storages/views.py:54
msgid "ISO image already exists"
msgstr "ISO imajı zaten mevcut"
#: storages/views.py:174
#: storages/views.py:177
#, python-format
msgid "Volume: %(vol)s is deleted."
msgstr "Birim: %(vol)s silindi."
#: storages/views.py:191
#: storages/views.py:194
#, python-format
msgid "Image file %(name)s is created successfully"
msgstr "İmaj dosyası %(name)s başarıyla oluşturuldu"
@ -10292,7 +10292,7 @@ msgstr ""
"%(name)s havuzu çalışan %(vms)s sanal makinelerinin disklerini tutuyor; önce "
"onları kapatın"
#: vrtManager/storage.py:231
#: vrtManager/storage.py:234
#, python-format
msgid ""
"VMs %(vms)s have disks in pool %(name)s and would no longer start; detach "
@ -10301,7 +10301,12 @@ msgstr ""
"%(vms)s sanal makinelerinin %(name)s havuzunda diskleri var ve artık "
"başlamaz; önce bu diskleri ayırın"
#: vrtManager/storage.py:263
#: vrtManager/storage.py:269
#, python-format
msgid "Volume %(name)s is in use on another compute that shares this storage"
msgstr "%(name)s birimi bu depolamayı paylaşan başka bir sunucuda kullanılıyor"
#: vrtManager/storage.py:275
#, python-format
msgid ""
"Volume %(name)s is in use: a VM's disk, a backing file or a snapshot's file"
@ -10309,7 +10314,7 @@ msgstr ""
"%(name)s birimi kullanımda: bir sanal makinenin diski, bir temel (backing) "
"dosya ya da bir anlık görüntünün dosyası"
#: vrtManager/storage.py:356
#: vrtManager/storage.py:368
#, python-format
msgid "The running VMs %(vms)s use volume %(name)s; shut them down to copy it"
msgstr ""

Binary file not shown.

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-13 07:27+0000\n"
"POT-Creation-Date: 2026-11-13 07:41+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@ -2629,7 +2629,7 @@ msgid ""
msgstr "不支持控制台类型 '%(type)s'。请将虚拟机图形切换为 VNC。"
#: instances/api/viewsets.py:149 instances/api/viewsets.py:167
#: instances/views.py:816 instances/views.py:836 instances/views.py:1813
#: instances/views.py:816 instances/views.py:836 instances/views.py:1819
msgid "Templates cannot be started."
msgstr "模板无法启动。"
@ -2962,7 +2962,7 @@ msgstr "MAC 地址 %(mac)s 已属于此主机上另一台虚拟机的网卡"
msgid "Create VM"
msgstr "创建虚拟机"
#: instances/jobs.py:900 instances/jobs.py:945 instances/views.py:2530
#: instances/jobs.py:900 instances/jobs.py:945 instances/views.py:2536
msgid "A virtual machine with this name already exists"
msgstr "同名虚拟机已存在"
@ -3314,7 +3314,7 @@ msgid "Disk source"
msgstr "磁盘来源"
#: instances/templates/add_instance_volume.html:21
#: instances/templates/create_instance_w2.html:134 instances/views.py:2550
#: instances/templates/create_instance_w2.html:134 instances/views.py:2556
msgid "New disk"
msgstr "新磁盘"
@ -3340,7 +3340,7 @@ msgid "Storage pool"
msgstr "存储池"
#: instances/templates/add_instance_volume.html:41
#: instances/templates/create_instance_w2.html:46 storages/forms.py:107
#: instances/templates/create_instance_w2.html:46 storages/forms.py:119
#: storages/templates/storage.html:182
msgid "Letters, digits, dot, dash and underscore."
msgstr "字母、数字、点、短横线和下划线。"
@ -3358,8 +3358,8 @@ msgstr "格式"
#: instances/templates/add_instance_volume.html:61
#: instances/templates/create_instance_w2.html:154
#: instances/templates/create_instance_w2.html:220 storages/forms.py:113
#: storages/forms.py:133 storages/templates/storage.html:197
#: instances/templates/create_instance_w2.html:220 storages/forms.py:125
#: storages/forms.py:145 storages/templates/storage.html:197
msgid "Preallocate metadata (qcow2)"
msgstr "预分配元数据(qcow2)"
@ -3684,11 +3684,11 @@ msgstr "请选择…"
msgid "Custom CPU Models"
msgstr "自定义 CPU 型号"
#: instances/templates/create_instance_w2.html:146 storages/forms.py:112
#: instances/templates/create_instance_w2.html:146 storages/forms.py:124
msgid "Size (GiB)"
msgstr "大小(GiB)"
#: instances/templates/create_instance_w2.html:161 instances/views.py:2551
#: instances/templates/create_instance_w2.html:161 instances/views.py:2557
msgid "Existing volumes"
msgstr "已有卷"
@ -3724,7 +3724,7 @@ msgstr "设备"
msgid "Remove"
msgstr "移除"
#: instances/templates/create_instance_w2.html:194 instances/views.py:2552
#: instances/templates/create_instance_w2.html:194 instances/views.py:2558
msgid "Clone from template"
msgstr "从模板克隆"
@ -6041,108 +6041,108 @@ msgstr "磁盘 %(dev)s 有待生效的更改;请在虚拟机关机后删除它
msgid "Volume %(vol)s is used by another VM; detach it instead"
msgstr "卷 %(vol)s 正被另一台虚拟机使用;请改为分离它"
#: instances/views.py:1590
#: instances/views.py:1596
#, python-format
msgid ""
"The guest has not released disk %(dev)s yet; volume %(vol)s was kept. Delete "
"it from the storage pool once the VM is shut down."
msgstr "客户机尚未释放磁盘 %(dev)s;卷 %(vol)s 已保留。请在虚拟机关机后从存储池中删除它。"
#: instances/views.py:1601
#: instances/views.py:1607
#, python-format
msgid "Disk %(dev)s was detached, but its volume was kept: %(err)s"
msgstr "磁盘 %(dev)s 已分离,但其卷已保留:%(err)s"
#: instances/views.py:1629
#: instances/views.py:1635
#, python-format
msgid "This VM cannot take a CD-ROM on the %(bus)s bus now"
msgstr "该虚拟机现在无法在 %(bus)s 总线上添加 CD-ROM"
#: instances/views.py:1632
#: instances/views.py:1638
msgid "A USB CD-ROM needs an ISO image: libvirt has no empty USB drive"
msgstr "USB CD-ROM 需要 ISO 镜像:libvirt 不支持空的 USB 驱动器"
#: instances/views.py:1637
#: instances/views.py:1643
#, python-format
msgid "%(image)s is already in a CD-ROM of this VM"
msgstr "%(image)s 已在此虚拟机的某个光驱中"
#: instances/views.py:1718
#: instances/views.py:1724
#, python-format
msgid "Pool %(pool)s was not read again: %(err)s"
msgstr "未重新读取存储池 %(pool)s:%(err)s"
#: instances/views.py:1739
#: instances/views.py:1745
#, python-format
msgid "Snapshot was not deleted: %(err)s"
msgstr "快照未删除:%(err)s"
#: instances/views.py:1857
#: instances/views.py:1863
msgid "Add at least one device to the boot order."
msgstr "请至少向启动顺序中添加一个设备。"
#: instances/views.py:1863 vrtManager/instance.py:1161
#: instances/views.py:1869 vrtManager/instance.py:1161
msgid "Invalid Device Type for boot order"
msgstr "启动顺序的设备类型无效"
#: instances/views.py:1874
#: instances/views.py:1880
msgid "Boot order changed. It applies at the next start."
msgstr "启动顺序已更改,将在下次启动时生效。"
#: instances/views.py:1876
#: instances/views.py:1882
msgid "Boot order changed successfully."
msgstr "启动顺序已成功更改。"
#: instances/views.py:1896
#: instances/views.py:1902
msgid "The XML is empty"
msgstr "XML 为空"
#: instances/views.py:1900 instances/views.py:2541
#: instances/views.py:1906 instances/views.py:2547
#, python-format
msgid "The XML is not well-formed: %(error)s"
msgstr "XML 格式不正确:%(error)s"
#: instances/views.py:1902
#: instances/views.py:1908
#, python-format
msgid "The XML must keep the VM's UUID %(uuid)s."
msgstr "XML 必须保留虚拟机的 UUID %(uuid)s。"
#: instances/views.py:1906
#: instances/views.py:1912
msgid ""
"The definition has changed since the editor was opened. Reload the page to "
"edit the current one."
msgstr "自打开编辑器以来定义已被更改。请重新加载页面以编辑当前定义。"
#: instances/views.py:1922
#: instances/views.py:1928
msgid "The XML definition was saved."
msgstr "XML 定义已保存。"
#: instances/views.py:1924
#: instances/views.py:1930
msgid "The XML definition was saved; the VM uses it from its next start."
msgstr "XML 定义已保存;虚拟机从下次启动起使用它。"
#: instances/views.py:2005
#: instances/views.py:2011
msgid "Select one network interface to change"
msgstr "请选择一个要更改的网络接口"
#: instances/views.py:2043
#: instances/views.py:2049
msgid "Network Device Config is changed. Please shutdown instance to activate."
msgstr "网络设备配置已更改。请关闭虚拟机以使其生效。"
#: instances/views.py:2045
#: instances/views.py:2051
msgid "Network device changed"
msgstr "网络设备已更改"
#: instances/views.py:2057
#: instances/views.py:2063
msgid "No network selected"
msgstr "未选择网络"
#: instances/views.py:2062
#: instances/views.py:2068
#, python-format
msgid "The VM already has a network device with MAC %(mac)s"
msgstr "虚拟机已有 MAC 地址为 %(mac)s 的网络设备"
#: instances/views.py:2081
#: instances/views.py:2087
msgid ""
"The running VM has no free PCI slot for another network device: shut it down "
"and add the device then; Add PCIe slots on the Disks tab gives it free ones "
@ -6150,136 +6150,136 @@ msgid ""
msgstr ""
"运行中的虚拟机没有可用 PCI 插槽来添加网络设备:请关机后再添加设备。“磁盘”选项卡上的“添加 PCIe 插槽”可使其从下次启动起获得可用插槽。"
#: instances/views.py:2127 instances/views.py:2133
#: instances/views.py:2133 instances/views.py:2139
msgid "The VM has it"
msgstr "虚拟机已有此设备"
#: instances/views.py:2168
#: instances/views.py:2174
#, python-format
msgid "The host has no USB device %(device)s; reload the page"
msgstr "主机没有 USB 设备 %(device)s;请重新加载页面"
#: instances/views.py:2189
#: instances/views.py:2195
#, python-format
msgid "The host has no PCI device %(device)s"
msgstr "主机上没有 PCI 设备 %(device)s"
#: instances/views.py:2207
#: instances/views.py:2213
#, python-format
msgid ""
"Removal of PCI device %(address)s requested: the guest has not let it go yet;"
" it stays in the running VM until it does or the VM stops."
msgstr "已请求移除 PCI 设备 %(address)s:客户机尚未释放它;在客户机释放或虚拟机停止之前,它仍保留在运行中的虚拟机中。"
#: instances/views.py:2252 instances/views.py:2282
#: instances/views.py:2258 instances/views.py:2288
msgid "Select a network interface and a QoS direction"
msgstr "请选择网络接口和 QoS 方向"
#: instances/views.py:2255 vrtManager/network.py:470
#: instances/views.py:2261 vrtManager/network.py:470
msgid "QoS rates must be whole numbers"
msgstr "QoS 速率必须为整数"
#: instances/views.py:2262 networks/views.py:230
#: instances/views.py:2268 networks/views.py:230
#, python-format
msgid "%(qos_dir)s QoS is set"
msgstr "%(qos_dir)s QoS 已设置"
#: instances/views.py:2267
#: instances/views.py:2273
#, python-format
msgid ""
"%(qos_dir)s QoS is set. A running VM gets it after it is powered off and on."
msgstr "%(qos_dir)s QoS 已设置。运行中的虚拟机需关机再开机后才能生效。"
#: instances/views.py:2289 networks/views.py:256
#: instances/views.py:2295 networks/views.py:256
#, python-format
msgid "%(qos_dir)s QoS is deleted"
msgstr "%(qos_dir)s QoS 已删除"
#: instances/views.py:2294
#: instances/views.py:2300
#, python-format
msgid ""
"%(qos_dir)s QoS is deleted. A running VM keeps the old limit until it is "
"powered off and on."
msgstr "%(qos_dir)s QoS 已删除。运行中的虚拟机在关机再开机之前保留旧的限制。"
#: instances/views.py:2322
#: instances/views.py:2328
msgid "Only one owner is allowed and the one already added"
msgstr "只允许一个所有者,且已添加"
#: instances/views.py:2324
#: instances/views.py:2330
#, python-format
msgid "%(user)s is already an owner"
msgstr "%(user)s 已是所有者"
#: instances/views.py:2369
#: instances/views.py:2375
#, python-format
msgid "Console settings were not saved: %(errors)s"
msgstr "控制台设置未保存:%(errors)s"
#: instances/views.py:2391
#: instances/views.py:2397
msgid ""
"Error setting console password. You should check that your instance have an "
"graphic device."
msgstr "设置控制台密码出错。请检查虚拟机是否有图形设备。"
#: instances/views.py:2438
#: instances/views.py:2444
msgid "Shut the VM down to change whether it is a template."
msgstr "请关闭虚拟机以更改其是否为模板。"
#: instances/views.py:2444
#: instances/views.py:2450
#, python-format
msgid "%(quota)s: '%(instance_name)s' stays a template."
msgstr "%(quota)s:“%(instance_name)s”仍为模板。"
#: instances/views.py:2528
#: instances/views.py:2534
msgid "The XML has no name"
msgstr "XML 中没有名称"
#: instances/views.py:2543 webvirtcloud/middleware.py:156
#: instances/views.py:2549 webvirtcloud/middleware.py:156
#, python-format
msgid "libvirt Error - %(exception)s"
msgstr "libvirt 错误 - %(exception)s"
#: instances/views.py:2550
#: instances/views.py:2556
msgid "An empty disk of the size you set"
msgstr "按设定大小创建的空磁盘"
#: instances/views.py:2551
#: instances/views.py:2557
msgid "Volumes already in a pool"
msgstr "存储池中已有的卷"
#: instances/views.py:2552
#: instances/views.py:2558
msgid "A copy of a template volume"
msgstr "模板卷的副本"
#: instances/views.py:2630
#: instances/views.py:2636
msgid ""
"This host has no running storage pool for the VM's disks: add or start one on"
" its Storage page."
msgstr "此主机没有可用于虚拟机磁盘的运行中存储池:请在其“存储”页面添加或启动一个。"
#: instances/views.py:2632
#: instances/views.py:2638
msgid "This host has no network for the VM: add one on its Networks page."
msgstr "此主机没有可供虚拟机使用的网络:请在其“网络”页面添加一个。"
#: instances/views.py:2664
#: instances/views.py:2670
#, python-format
msgid "The machine type is q35, not %(machine)s: UEFI Secure Boot needs it"
msgstr "机器类型为 q35,而不是 %(machine)s:UEFI 安全启动需要它"
#: instances/views.py:2691
#: instances/views.py:2697
msgid "Flavor Created"
msgstr "规格已创建"
#: instances/views.py:2699
#: instances/views.py:2705
msgid "Create Flavor"
msgstr "创建规格"
#: instances/views.py:2711
#: instances/views.py:2717
msgid "Flavor Deleted"
msgstr "规格已删除"
#: instances/views.py:2717
#: instances/views.py:2723
msgid "Only the size template goes; VMs made from it keep their size."
msgstr "仅删除此规格;由它创建的虚拟机保持其大小。"
@ -6660,7 +6660,7 @@ msgstr "IPv4 网络前缀必须为 /30 或更短"
msgid "For libvirt, the IPv6 network prefix must be /64"
msgstr "libvirt 要求 IPv6 网络前缀为 /64"
#: networks/forms.py:36 storages/forms.py:35
#: networks/forms.py:36 storages/forms.py:47
msgid "No pool name has been entered"
msgstr "未输入地址池名称"
@ -6676,7 +6676,7 @@ msgstr "IPv6 子网"
msgid "Bridge or interface"
msgstr "网桥或接口"
#: networks/forms.py:56 storages/forms.py:59
#: networks/forms.py:56 storages/forms.py:71
msgid "The pool name must not contain any special characters"
msgstr "地址池名称不能包含特殊字符"
@ -6693,7 +6693,7 @@ msgid "The pool bridge name must not contain any special characters"
msgstr "地址池网桥名称不能包含特殊字符"
#: networks/forms.py:85 networks/forms.py:89 networks/forms.py:93
#: storages/forms.py:100
#: storages/forms.py:112
msgid "This field is required."
msgstr "此字段为必填项。"
@ -7755,80 +7755,80 @@ msgstr "恢复在一小时内无法读取任务状态;请检查虚拟机,然
msgid "The worker stopped before the job changed anything"
msgstr "工作进程在任务做出任何更改之前停止"
#: storages/api/viewsets.py:143 storages/api/viewsets.py:159
#: storages/api/viewsets.py:195 storages/api/viewsets.py:215
#: storages/api/viewsets.py:144 storages/api/viewsets.py:160
#: storages/api/viewsets.py:196 storages/api/viewsets.py:218
msgid "Pool is not active"
msgstr "存储池未激活"
#: storages/forms.py:38 storages/templates/storage.html:102
#: storages/forms.py:50 storages/templates/storage.html:102
#: storages/templates/storages.html:43
msgid "Path"
msgstr "路径"
#: storages/forms.py:39
#: storages/forms.py:51
msgid "Device or remote path"
msgstr "设备或远程路径"
#: storages/forms.py:40
#: storages/forms.py:52
msgid "Erase the device"
msgstr "擦除设备"
#: storages/forms.py:41 storages/templates/create_stg_block.html:110
#: storages/forms.py:53 storages/templates/create_stg_block.html:110
msgid "Ceph user"
msgstr "Ceph 用户"
#: storages/forms.py:42 storages/templates/create_stg_block.html:98
#: storages/forms.py:54 storages/templates/create_stg_block.html:98
msgid "Ceph monitor"
msgstr "Ceph 监视器"
#: storages/forms.py:43 storages/templates/create_stg_block.html:104
#: storages/forms.py:55 storages/templates/create_stg_block.html:104
msgid "Ceph pool"
msgstr "Ceph 存储池"
#: storages/forms.py:44 storages/templates/create_stg_block.html:116
#: storages/forms.py:56 storages/templates/create_stg_block.html:116
msgid "Ceph secret"
msgstr "Ceph 机密"
#: storages/forms.py:45 storages/templates/create_stg_block.html:139
#: storages/forms.py:57 storages/templates/create_stg_block.html:139
msgid "Server"
msgstr "服务器"
#: storages/forms.py:62
#: storages/forms.py:74
msgid "This host has a pool of that name"
msgstr "此主机已有同名存储池"
#: storages/forms.py:71
#: storages/forms.py:83
msgid "The target must not contain any special characters"
msgstr "目标不能包含特殊字符"
#: storages/forms.py:75
#: storages/forms.py:87
#, python-format
msgid "%(path)s is a system directory of the host"
msgstr "%(path)s 是主机的系统目录"
#: storages/forms.py:81
#: storages/forms.py:93
#, python-format
msgid "Pool %(pool)s uses this path"
msgstr "存储池 %(pool)s 正在使用此路径"
#: storages/forms.py:84
#: storages/forms.py:96
#, python-format
msgid "Pool %(pool)s uses %(path)s: one pool's directory cannot hold another's"
msgstr "存储池 %(pool)s 正在使用 %(path)s:一个存储池的目录不能包含另一个存储池的目录"
#: storages/forms.py:92
#: storages/forms.py:104
msgid "The disk source must not contain any special characters"
msgstr "磁盘源不能包含特殊字符"
#: storages/forms.py:102
#: storages/forms.py:114
msgid "Choose one of the host's Ceph secrets"
msgstr "请选择此主机上的一个 Ceph 机密"
#: storages/forms.py:120 storages/forms.py:140
#: storages/forms.py:132 storages/forms.py:152
msgid "The image name must not contain any special characters"
msgstr "镜像名称不能包含特殊字符"
#: storages/forms.py:144
#: storages/forms.py:156
msgid "The image name must not exceed 120 characters"
msgstr "镜像名称不能超过 120 个字符"
@ -8296,36 +8296,36 @@ msgstr "最后一个分块与声明的文件大小不符"
msgid "The partial upload is missing"
msgstr "部分上传的文件不存在"
#: storages/views.py:29
#: storages/views.py:30
msgid "No file chunk was submitted."
msgstr "未提交文件分块。"
#: storages/views.py:35
#: storages/views.py:36
msgid "Invalid chunk parameters."
msgstr "分块参数无效。"
#: storages/views.py:37
#: storages/views.py:38
msgid "Invalid chunk index or total chunks."
msgstr "分块索引或分块总数无效。"
#: storages/views.py:42
#: storages/views.py:43
msgid "Invalid file size."
msgstr "文件大小无效。"
#: storages/views.py:51
#: storages/views.py:52
msgid "Upload session is busy. Please retry."
msgstr "上传会话繁忙,请重试。"
#: storages/views.py:53
#: storages/views.py:54
msgid "ISO image already exists"
msgstr "ISO 镜像已存在"
#: storages/views.py:174
#: storages/views.py:177
#, python-format
msgid "Volume: %(vol)s is deleted."
msgstr "卷 %(vol)s 已删除。"
#: storages/views.py:191
#: storages/views.py:194
#, python-format
msgid "Image file %(name)s is created successfully"
msgstr "镜像文件 %(name)s 创建成功"
@ -9685,20 +9685,25 @@ msgid ""
"Pool %(name)s holds disks of the running VMs %(vms)s; shut them down first"
msgstr "存储池 %(name)s 中有运行中的虚拟机 %(vms)s 的磁盘;请先关闭它们"
#: vrtManager/storage.py:231
#: vrtManager/storage.py:234
#, python-format
msgid ""
"VMs %(vms)s have disks in pool %(name)s and would no longer start; detach "
"those disks first"
msgstr "虚拟机 %(vms)s 使用存储池 %(name)s 中的磁盘,将无法再启动;请先分离这些磁盘"
#: vrtManager/storage.py:263
#: vrtManager/storage.py:269
#, python-format
msgid "Volume %(name)s is in use on another compute that shares this storage"
msgstr "卷 %(name)s 正在被共享此存储的另一台主机使用"
#: vrtManager/storage.py:275
#, python-format
msgid ""
"Volume %(name)s is in use: a VM's disk, a backing file or a snapshot's file"
msgstr "卷 %(name)s 正在使用中:它是虚拟机的磁盘、后备文件或快照文件"
#: vrtManager/storage.py:356
#: vrtManager/storage.py:368
#, python-format
msgid "The running VMs %(vms)s use volume %(name)s; shut them down to copy it"
msgstr "正在运行的虚拟机 %(vms)s 使用卷 %(name)s;请先将其关闭再复制"

View file

@ -4,6 +4,7 @@ from admin.permissions import IsSuperUser
from appsettings.settings import app_settings
from computes.models import Compute
from computes.utils import libvirt_compute_lock
from instances.utils import paths_used_on_other_computes
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext as _
from drf_spectacular.utils import extend_schema, inline_serializer
@ -206,9 +207,11 @@ class VolumeViewSet(viewsets.ViewSet):
subject, action = f"Storage pool {storage_pk}", f"delete volume {pk}"
if conn.is_active():
# no VM operation attaches it between the check and the delete
with audit(request, compute, subject, action), libvirt_compute_lock(compute):
conn.del_volume(pk)
with audit(request, compute, subject, action):
conn.check_unused_elsewhere(pk, lambda paths: paths_used_on_other_computes(compute, paths))
# no VM operation attaches it between the check and the delete
with libvirt_compute_lock(compute):
conn.del_volume(pk)
return Response({"status": "Volume: " + pk + " is deleted"})
else:
failed(request, compute, subject, action, "pool is not active")

View file

@ -113,6 +113,31 @@ class VolumeDeleteTests(TestCase):
request()
self.assertEqual(inside, [[(self.compute.pk, False)]])
def test_the_other_computes_are_asked_before_the_lock(self):
# shared storage: another host's VM may use the file at the same path;
# a host that does not answer does not hold this one's lock meanwhile
for module, request in (
("storages.views", lambda: self.client.post(reverse("storage", args=[self.compute.id, "default"]),
{"del_volume": "1", "volname": "disk.qcow2"})),
("storages.api.viewsets", lambda: self.client.delete(
f"/api/v1/computes/{self.compute.id}/storages/default/volumes/disk.qcow2/")),
):
with self.subTest(module), patch(f"{module}.wvmStorage") as mock_wvm, \
patch(f"{module}.libvirt_compute_lock") as lock, \
patch(f"{module}.paths_used_on_other_computes", return_value=set()) as others:
conn = mock_wvm.return_value
conn.is_active.return_value = True
conn.get_size.return_value = (1, 1)
def check(name, elsewhere, lock=lock):
lock.assert_not_called()
elsewhere(["/pool/disk.qcow2"])
conn.check_unused_elsewhere.side_effect = check
request()
others.assert_called_once_with(self.compute, ["/pool/disk.qcow2"])
conn.del_volume.assert_called_once_with("disk.qcow2")
@patch("storages.views.wvmStorage")
def test_a_busy_compute_is_a_message(self, mock_wvm):
conn = self.refused(mock_wvm)

View file

@ -5,6 +5,7 @@ from admin.decorators import superuser_only
from appsettings.settings import app_settings
from computes.models import Compute
from computes.utils import libvirt_compute_lock
from instances.utils import paths_used_on_other_computes
from django.contrib import messages
from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
@ -162,9 +163,11 @@ def storage(request, compute_id, pool):
if "del_volume" in request.POST:
volname = request.POST.get("volname", "")
try:
# no VM operation attaches it between the check and the delete
with audit(request, compute, subject, f"delete volume {volname}"), libvirt_compute_lock(compute):
conn.del_volume(volname)
with audit(request, compute, subject, f"delete volume {volname}"):
conn.check_unused_elsewhere(volname, lambda paths: paths_used_on_other_computes(compute, paths))
# no VM operation attaches it between the check and the delete
with libvirt_compute_lock(compute):
conn.del_volume(volname)
except OperationError as err:
messages.error(request, str(err))
except claims.Busy as busy:

View file

@ -259,8 +259,17 @@ class wvmStorage(wvmConnect):
vol = self.get_volume(name)
return vol.XMLDesc(0)
def check_unused_elsewhere(self, name, elsewhere):
"""Refuses a volume a VM of another host sharing this storage uses:
elsewhere(paths) gives those the other hosts use
(instances.utils.paths_used_on_other_computes). Asked before this
host's lock, which a host that does not answer would hold meanwhile."""
path = self.pool.storageVolLookupByName(name).path()
if path in elsewhere([path]):
raise util.InUse(gettext_noop("Volume %(name)s is in use on another compute that shares this storage"), name=name)
def del_volume(self, name):
"""libvirt deletes any volume; one a VM still needs is refused."""
"""libvirt deletes any volume; one a VM of this host still needs is refused."""
vol = self.pool.storageVolLookupByName(name)
if vol.path() in self.paths_in_use():
raise util.InUse(gettext_noop("Volume %(name)s is in use: a VM's disk, a backing file or a snapshot's file"), name=name)

View file

@ -191,6 +191,15 @@ class DeleteVolumeTestCase(unittest.TestCase):
conn.del_volume("disk.qcow2")
vols["disk.qcow2"].delete.assert_called_once_with(0)
def test_a_volume_another_compute_uses_is_refused(self):
# shared storage: another host's VM has the same file at the same path
conn, _vols = storage([], [volume("/pool/disk.qcow2")])
asked = []
conn.check_unused_elsewhere("disk.qcow2", lambda paths: asked.append(paths) or set())
self.assertEqual(asked, [["/pool/disk.qcow2"]])
with self.assertRaisesRegex(util.InUse, "disk.qcow2 is in use on another compute"):
conn.check_unused_elsewhere("disk.qcow2", set)
class RunningCopyTestCase(unittest.TestCase):
"""A running guest's disk is not copied: the copy would mix instants."""