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