mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
- 25 vrtManager test modules configured settings themselves when Django had none (MAC_OUI, and in test_network_ip a fake django module): under manage.py test settings are always configured, so it never ran. - webvirtcloud/tests/test_common_tags.py tested no tag: it fetched an unknown URL, as test_error_pages and test_logging already do. - .gitignore covers the parallel runs' test_db_N.sqlite3 files too.
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import unittest
|
|
from unittest.mock import MagicMock
|
|
|
|
from libvirt import VIR_DOMAIN_BLOCK_RESIZE_BYTES, VIR_STORAGE_VOL_BLOCK, VIR_STORAGE_VOL_FILE
|
|
from vrtManager.instance import wvmInstance
|
|
|
|
SIZE = 10 << 30
|
|
|
|
|
|
def vm(active, vol_type):
|
|
inst = wvmInstance.__new__(wvmInstance)
|
|
inst.instance = MagicMock()
|
|
inst.instance.isActive.return_value = active
|
|
vol = MagicMock()
|
|
vol.info.return_value = [vol_type, 0, 0]
|
|
inst.get_volume_by_path = MagicMock(return_value=vol)
|
|
inst.resize_disk([{"path": "/dev/vg/disk", "size_new": SIZE}])
|
|
return inst, vol
|
|
|
|
|
|
class ResizeDiskTestCase(unittest.TestCase):
|
|
def test_running_block_volume_grows_in_the_pool_then_in_qemu(self):
|
|
inst, vol = vm(active=True, vol_type=VIR_STORAGE_VOL_BLOCK)
|
|
vol.resize.assert_called_once_with(SIZE)
|
|
inst.instance.blockResize.assert_called_once_with("/dev/vg/disk", SIZE, VIR_DOMAIN_BLOCK_RESIZE_BYTES)
|
|
|
|
def test_running_image_file_grows_through_qemu_only(self):
|
|
# qemu-img cannot take the image lock QEMU holds
|
|
inst, vol = vm(active=True, vol_type=VIR_STORAGE_VOL_FILE)
|
|
vol.resize.assert_not_called()
|
|
inst.instance.blockResize.assert_called_once()
|
|
|
|
def test_stopped_vm_grows_the_volume(self):
|
|
inst, vol = vm(active=False, vol_type=VIR_STORAGE_VOL_FILE)
|
|
vol.resize.assert_called_once_with(SIZE)
|
|
inst.instance.blockResize.assert_not_called()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|