Skip to content

Commit b34c3f5

Browse files
committed
Implement storage nfs-on-slave test
This new test ensures that the "nfs-on-slave" host-plugin does check something, and return different result based on the environment. Signed-off-by: Anthony PERARD <[email protected]>
1 parent 89a8cd9 commit b34c3f5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/storage/nfs/test_nfs_sr.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import pytest
22

3+
from lib.commands import SSHCommandFailed
34
from lib.common import vm_image, wait_for
5+
from lib.vdi import VDI
46
from tests.storage import vdi_is_open
57

8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from lib.vm import VM
12+
613
# Requirements:
714
# - one XCP-ng host >= 8.0 with an additional unused disk for the SR
815

@@ -30,6 +37,41 @@ def test_vdi_is_not_open(self, dispatch_nfs):
3037
vdi = dispatch_nfs
3138
assert not vdi_is_open(vdi)
3239

40+
@pytest.mark.small_vm
41+
@pytest.mark.usefixtures('hostA2')
42+
# Make sure this fixture is called before the parametrized one
43+
@pytest.mark.usefixtures('vm_ref')
44+
@pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr'], indirect=True)
45+
def test_plugin_nfs_on_on_slave(self, dispatch_nfs: 'VM'):
46+
vm = dispatch_nfs
47+
vm.start()
48+
vm.wait_for_os_booted()
49+
host = vm.get_residence_host()
50+
51+
vdi = VDI(vm.vdi_uuids()[0], host=host)
52+
53+
# TODO: Use vdi.get_image_format() once available, instead of
54+
# hard-coded ".vhd".
55+
vdi_path = f"/run/sr-mount/{vdi.sr.uuid}/{vdi.uuid}.vhd"
56+
57+
# nfs-on-slave returns an error when the VDI is open on the host.
58+
# Otherwise, it return "success", including in case "path" doesn't exist
59+
with pytest.raises(SSHCommandFailed) as excinfo:
60+
assert vm.is_running_on_host(host)
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 have 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+
3375
@pytest.mark.small_vm # run with a small VM to test the features
3476
@pytest.mark.big_vm # and ideally with a big VM to test it scales
3577
# Make sure this fixture is called before the parametrized one

0 commit comments

Comments
 (0)