|
1 | 1 | import pytest |
2 | 2 |
|
| 3 | +from lib.commands import SSHCommandFailed |
3 | 4 | from lib.common import vm_image, wait_for |
| 5 | +from lib.vdi import VDI |
4 | 6 | from tests.storage import vdi_is_open |
5 | 7 |
|
| 8 | +from typing import TYPE_CHECKING |
| 9 | + |
| 10 | +if TYPE_CHECKING: |
| 11 | + from lib.vm import VM |
| 12 | + |
6 | 13 | # Requirements: |
7 | 14 | # - one XCP-ng host >= 8.0 with an additional unused disk for the SR |
8 | 15 |
|
@@ -30,6 +37,39 @@ def test_vdi_is_not_open(self, dispatch_nfs): |
30 | 37 | vdi = dispatch_nfs |
31 | 38 | assert not vdi_is_open(vdi) |
32 | 39 |
|
| 40 | + @pytest.mark.small_vm |
| 41 | + @pytest.mark.usefixtures('hostA2') |
| 42 | + def test_plugin_nfs_on_on_slave(self, vm_on_nfs_sr: 'VM'): |
| 43 | + vm = vm_on_nfs_sr |
| 44 | + vm.start() |
| 45 | + vm.wait_for_os_booted() |
| 46 | + host = vm.get_residence_host() |
| 47 | + |
| 48 | + vdi = VDI(vm.vdi_uuids()[0], host=host) |
| 49 | + image_format = vdi.get_image_format() |
| 50 | + if not image_format: |
| 51 | + image_format = "vhd" |
| 52 | + |
| 53 | + vdi_path = f"/run/sr-mount/{vdi.sr.uuid}/{vdi.uuid}.{image_format}" |
| 54 | + |
| 55 | + # nfs-on-slave returns an error when the VDI is open on the host. |
| 56 | + # Otherwise, it return "success", including in case "path" doesn't exist |
| 57 | + with pytest.raises(SSHCommandFailed) as excinfo: |
| 58 | + assert vm.is_running_on_host(host) |
| 59 | + host.call_plugin("nfs-on-slave", "check", {"path": vdi_path}) |
| 60 | + |
| 61 | + # The output of the host plugin would have "stdout: NfsCheckException" |
| 62 | + # and information about which process has the path open. |
| 63 | + assert "NfsCheckException" in excinfo.value.stdout |
| 64 | + |
| 65 | + for member in host.pool.hosts: |
| 66 | + # skip the host where the VM is running |
| 67 | + if member.uuid == host.uuid: |
| 68 | + continue |
| 69 | + member.call_plugin("nfs-on-slave", "check", {"path": vdi_path}) |
| 70 | + |
| 71 | + vm.shutdown(verify=True) |
| 72 | + |
33 | 73 | @pytest.mark.small_vm # run with a small VM to test the features |
34 | 74 | @pytest.mark.big_vm # and ideally with a big VM to test it scales |
35 | 75 | # Make sure this fixture is called before the parametrized one |
|
0 commit comments