|
1 | 1 | import pytest
|
| 2 | +from lib.commands import SSHCommandFailed |
2 | 3 | from lib.common import wait_for, vm_image
|
| 4 | +from lib.vdi import VDI |
| 5 | +import logging |
3 | 6 | from tests.storage import vdi_is_open
|
| 7 | +from typing import TYPE_CHECKING |
| 8 | + |
| 9 | +if TYPE_CHECKING: |
| 10 | + from lib.vm import VM |
4 | 11 |
|
5 | 12 | # Requirements:
|
6 | 13 | # - one XCP-ng host >= 8.0 with an additional unused disk for the SR
|
@@ -29,6 +36,42 @@ def test_vdi_is_not_open(self, dispatch_nfs):
|
29 | 36 | vdi = dispatch_nfs
|
30 | 37 | assert not vdi_is_open(vdi)
|
31 | 38 |
|
| 39 | + @pytest.mark.small_vm |
| 40 | + @pytest.mark.usefixtures('hostA2') |
| 41 | + # Make sure this fixture is called before the parametrized one |
| 42 | + @pytest.mark.usefixtures('vm_ref') |
| 43 | + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr'], indirect=True) |
| 44 | + def test_plugin_nfs_on_on_slave(self, dispatch_nfs: 'VM'): |
| 45 | + vm = dispatch_nfs |
| 46 | + vm.start() |
| 47 | + vm.wait_for_os_booted() |
| 48 | + host = vm.get_residence_host() |
| 49 | + |
| 50 | + vdi = VDI(vm.vdi_uuids()[0], host=host) |
| 51 | + |
| 52 | + # TODO: How to find out if it's .vhd? |
| 53 | + vdi_path = f"/run/sr-mount/{vdi.sr.uuid}/{vdi.uuid}.vhd" |
| 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 | + try: |
| 58 | + assert vm.is_running_on_host(host) |
| 59 | + host.call_plugin("nfs-on-slave", "check", {"path": vdi_path}) |
| 60 | + assert False, "nfs-on-slave should have returned an error" |
| 61 | + except SSHCommandFailed as e: |
| 62 | + # The output of the host plugin would have "stdout: NfsCheckException" |
| 63 | + # and information about which process have the path open. |
| 64 | + assert "NfsCheckException" in e.stdout |
| 65 | + logging.debug(f"nfs-on-slave returns a failure as expected") |
| 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 | + |
32 | 75 | @pytest.mark.small_vm # run with a small VM to test the features
|
33 | 76 | @pytest.mark.big_vm # and ideally with a big VM to test it scales
|
34 | 77 | # Make sure this fixture is called before the parametrized one
|
|
0 commit comments