Skip to content

Commit 6afd538

Browse files
committed
WIP: Implement storage nfs-on-slave test
This new test ensure that the "nfs-on-slave" host-plugin does check something, and return different result based on the environment. TODO: Still need to figure out how to find the type of VDI, to have the extension for the path. It's currently hard-coded to .vhd. Signed-off-by: Anthony PERARD <[email protected]>
1 parent 8ea7643 commit 6afd538

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/storage/nfs/test_nfs_sr.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import pytest
2+
from lib.commands import SSHCommandFailed
23
from lib.common import wait_for, vm_image
4+
from lib.vdi import VDI
5+
import logging
36
from tests.storage import vdi_is_open
7+
from typing import TYPE_CHECKING
8+
9+
if TYPE_CHECKING:
10+
from lib.vm import VM
411

512
# Requirements:
613
# - 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):
2936
vdi = dispatch_nfs
3037
assert not vdi_is_open(vdi)
3138

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+
3275
@pytest.mark.small_vm # run with a small VM to test the features
3376
@pytest.mark.big_vm # and ideally with a big VM to test it scales
3477
# Make sure this fixture is called before the parametrized one

0 commit comments

Comments
 (0)