|
| 1 | +import pytest |
| 2 | + |
| 3 | +from lib.commands import SSHCommandFailed |
| 4 | +from lib.common import Defer, vm_image, wait_for |
| 5 | +from lib.sr import SR |
| 6 | +from lib.vdi import VDI, ImageFormat |
| 7 | +from lib.vm import VM |
| 8 | +from tests.storage import ( |
| 9 | + MAX_VDI_SIZE, |
| 10 | + CoalesceOperation, |
| 11 | + ImageFormat, |
| 12 | + XVACompression, |
| 13 | + coalesce_integrity, |
| 14 | + full_vdi_write, |
| 15 | + vdi_export_import, |
| 16 | + vdi_is_open, |
| 17 | + xva_export_import, |
| 18 | +) |
| 19 | + |
| 20 | +# Requirements: |
| 21 | +# - one XCP-ng host >= 8.2 |
| 22 | +# - a valid lvmohba config |
| 23 | + |
| 24 | +class TestLVMOHBASRCreateDestroy: |
| 25 | + """ |
| 26 | + Tests that do not use fixtures that setup the SR or import VMs, |
| 27 | + because they precisely need to test SR creation and destruction, |
| 28 | + and VM import. |
| 29 | + """ |
| 30 | + |
| 31 | + def test_create_and_destroy_sr(self, host, lvmohba_device_config, image_format: ImageFormat): |
| 32 | + # Create and destroy tested in the same test to leave the host as unchanged as possible |
| 33 | + sr = host.sr_create('lvmohba', "lvmohba-SR-test", |
| 34 | + lvmohba_device_config | {'preferred-image-formats': image_format}, |
| 35 | + shared=True, verify=True) |
| 36 | + # import a VM in order to detect vm import issues here rather than in the vm_on_xfs_fixture used in |
| 37 | + # the next tests, because errors in fixtures break teardown |
| 38 | + vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid) |
| 39 | + vm.destroy(verify=True) |
| 40 | + sr.destroy(verify=True) |
| 41 | + |
| 42 | +@pytest.mark.usefixtures('image_format') |
| 43 | +@pytest.mark.usefixtures("lvmohba_sr") |
| 44 | +class TestLVMOHBASR: |
| 45 | + @pytest.mark.quicktest |
| 46 | + def test_quicktest(self, lvmohba_sr): |
| 47 | + lvmohba_sr.run_quicktest() |
| 48 | + |
| 49 | + @pytest.mark.disk_space_allocation |
| 50 | + def test_vdi_is_not_open(self, vdi_on_lvmohba_sr): |
| 51 | + assert not vdi_is_open(vdi_on_lvmohba_sr) |
| 52 | + |
| 53 | + @pytest.mark.small_vm # run with a small VM to test the features |
| 54 | + @pytest.mark.big_vm # and ideally with a big VM to test it scales |
| 55 | + def test_start_and_shutdown_VM(self, vm_on_lvmohba_sr): |
| 56 | + vm = vm_on_lvmohba_sr |
| 57 | + vm.start() |
| 58 | + vm.wait_for_os_booted() |
| 59 | + vm.shutdown(verify=True) |
| 60 | + |
| 61 | + @pytest.mark.small_vm |
| 62 | + @pytest.mark.big_vm |
| 63 | + def test_snapshot(self, vm_on_lvmohba_sr): |
| 64 | + vm = vm_on_lvmohba_sr |
| 65 | + vm.start() |
| 66 | + try: |
| 67 | + vm.wait_for_os_booted() |
| 68 | + vm.test_snapshot_on_running_vm() |
| 69 | + finally: |
| 70 | + vm.shutdown(verify=True) |
| 71 | + |
| 72 | + @pytest.mark.small_vm |
| 73 | + @pytest.mark.parametrize("vdi_op", ["snapshot", "clone"]) |
| 74 | + @pytest.mark.disk_space_allocation |
| 75 | + def test_coalesce(self, storage_test_vm: 'VM', vdi_on_lvmohba_sr: 'VDI', vdi_op: CoalesceOperation, defer: Defer): |
| 76 | + coalesce_integrity(storage_test_vm, vdi_on_lvmohba_sr, vdi_op, defer) |
| 77 | + |
| 78 | + @pytest.mark.small_vm |
| 79 | + @pytest.mark.disk_space_allocation |
| 80 | + @pytest.mark.disk_throughput_intensive |
| 81 | + def test_full_vdi_write(self, storage_test_vm: VM, vdi_on_lvmohba_sr: VDI, defer: Defer): |
| 82 | + full_vdi_write(storage_test_vm, vdi_on_lvmohba_sr, defer) |
| 83 | + |
| 84 | + @pytest.mark.small_vm |
| 85 | + def test_invalid_vdi_size(self, lvmohba_sr: SR, image_format: ImageFormat): |
| 86 | + with pytest.raises(SSHCommandFailed) as excinfo: |
| 87 | + lvmohba_sr.create_vdi(virtual_size=MAX_VDI_SIZE[image_format] + 1) |
| 88 | + assert 'VDI Invalid size' in excinfo.value.stdout |
| 89 | + |
| 90 | + @pytest.mark.small_vm |
| 91 | + @pytest.mark.parametrize("compression", ["none", "gzip", "zstd"]) |
| 92 | + @pytest.mark.disk_space_allocation |
| 93 | + def test_xva_export_import(self, vm_on_lvmohba_sr: VM, compression: XVACompression, temp_large_dir: str, |
| 94 | + defer: Defer): |
| 95 | + xva_export_import(vm_on_lvmohba_sr, compression, temp_large_dir, defer) |
| 96 | + |
| 97 | + @pytest.mark.small_vm |
| 98 | + @pytest.mark.disk_space_allocation |
| 99 | + def test_vdi_export_import(self, storage_test_vm: VM, lvmohba_sr: SR, image_format: ImageFormat, |
| 100 | + temp_large_dir: str, defer: Defer): |
| 101 | + vdi_export_import(storage_test_vm, lvmohba_sr, image_format, temp_large_dir, defer) |
| 102 | + |
| 103 | + # *** tests with reboots (longer tests). |
| 104 | + |
| 105 | + @pytest.mark.reboot |
| 106 | + @pytest.mark.small_vm |
| 107 | + def test_reboot(self, host, lvmohba_sr, vm_on_lvmohba_sr): |
| 108 | + sr = lvmohba_sr |
| 109 | + vm = vm_on_lvmohba_sr |
| 110 | + host.reboot(verify=True) |
| 111 | + wait_for(sr.all_pbds_attached, "Wait for PBD attached") |
| 112 | + # start the VM as a way to check that the underlying SR is operational |
| 113 | + vm.start(on=host.uuid) |
| 114 | + vm.wait_for_os_booted() |
| 115 | + vm.shutdown(verify=True) |
| 116 | + |
| 117 | + # *** End of tests with reboots |
0 commit comments