From 2d308d3259d33d133f228b1e99d454d3028290f4 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Wed, 10 Apr 2024 09:59:03 +0200 Subject: [PATCH] Add tests for NFS4+ only environment New NFS4 device config Run nfs tests on both device configs thanks to a paramtrized fixture Signed-off-by: Benjamin Reis --- data.py-dist | 7 +++ tests/storage/nfs/conftest.py | 49 +++++++++++++++++++ tests/storage/nfs/test_nfs_sr.py | 43 +++++++++++----- .../nfs/test_nfs_sr_crosspool_migration.py | 12 +++-- .../nfs/test_nfs_sr_intrapool_migration.py | 19 ++++--- 5 files changed, 107 insertions(+), 23 deletions(-) diff --git a/data.py-dist b/data.py-dist index f0ddf78c2..a53bd0f0f 100644 --- a/data.py-dist +++ b/data.py-dist @@ -59,6 +59,13 @@ DEFAULT_NFS_DEVICE_CONFIG = { # 'serverpath': '/path/to/shared/mount' # Path to shared mountpoint } +# Default NFS4+ only device config: +DEFAULT_NFS4_DEVICE_CONFIG = { +# 'server': '10.0.0.2', # URL/Hostname of NFS server +# 'serverpath': '/path_to_shared_mount' # Path to shared mountpoint +# 'nfsversion': '4.1' +} + # Default NFS ISO device config: DEFAULT_NFS_ISO_DEVICE_CONFIG = { # 'location': '10.0.0.2:/path/to/shared/mount' # URL/Hostname of NFS server and path to shared mountpoint diff --git a/tests/storage/nfs/conftest.py b/tests/storage/nfs/conftest.py index aef0902b2..e8c430040 100644 --- a/tests/storage/nfs/conftest.py +++ b/tests/storage/nfs/conftest.py @@ -1,6 +1,14 @@ import logging import pytest +# --- Dispatch fixture for NFS versions ---------------------------------------- + +@pytest.fixture +def dispatch_nfs(request): + yield request.getfixturevalue(request.param) + +# --- NFS3 fixtures ------------------------------------------------------------ + @pytest.fixture(scope='package') def nfs_device_config(sr_device_config): if sr_device_config is not None: @@ -39,3 +47,44 @@ def vm_on_nfs_sr(host, nfs_sr, vm_ref): # teardown logging.info("<< Destroy VM") vm.destroy(verify=True) + +# --- NFS4+ only fixtures ------------------------------------------------------ + +@pytest.fixture(scope='package') +def nfs4_device_config(sr_device_config): + if sr_device_config is not None: + # SR device config from CLI param + config = sr_device_config + else: + # SR device config from data.py defaults + try: + from data import DEFAULT_NFS4_DEVICE_CONFIG + except ImportError: + DEFAULT_NFS4_DEVICE_CONFIG = {} + if DEFAULT_NFS4_DEVICE_CONFIG: + config = DEFAULT_NFS4_DEVICE_CONFIG + else: + raise Exception("No default NFS4+ device-config found, neither in CLI nor in data.py defaults") + return config + +@pytest.fixture(scope='package') +def nfs4_sr(host, nfs4_device_config): + """ A NFS4+ SR on first host. """ + sr = host.sr_create('nfs', "NFS4-SR-test", nfs4_device_config, shared=True) + yield sr + # teardown + sr.destroy() + +@pytest.fixture(scope='module') +def vdi_on_nfs4_sr(nfs4_sr): + vdi = nfs4_sr.create_vdi('NFS4-VDI-test') + yield vdi + vdi.destroy() + +@pytest.fixture(scope='module') +def vm_on_nfs4_sr(host, nfs4_sr, vm_ref): + vm = host.import_vm(vm_ref, sr_uuid=nfs4_sr.uuid) + yield vm + # teardown + logging.info("<< Destroy VM") + vm.destroy(verify=True) diff --git a/tests/storage/nfs/test_nfs_sr.py b/tests/storage/nfs/test_nfs_sr.py index 0c2f38482..ee10cab92 100644 --- a/tests/storage/nfs/test_nfs_sr.py +++ b/tests/storage/nfs/test_nfs_sr.py @@ -5,36 +5,52 @@ # Requirements: # - one XCP-ng host >= 8.0 with an additional unused disk for the SR +# Make sure this fixture is called before the parametrized one +@pytest.mark.usefixtures('sr_device_config') class TestNFSSRCreateDestroy: - def test_create_and_destroy_sr(self, host, nfs_device_config): + @pytest.mark.parametrize('dispatch_nfs', ['nfs_device_config', 'nfs4_device_config'], indirect=True) + def test_create_and_destroy_sr(self, host, dispatch_nfs): + device_config = dispatch_nfs # Create and destroy tested in the same test to leave the host as unchanged as possible - sr = host.sr_create('nfs', "NFS-SR-test", nfs_device_config, shared=True, verify=True) + sr = host.sr_create('nfs', "NFS-SR-test", device_config, shared=True, verify=True) # import a VM in order to detect vm import issues here rather than in the vm_on_nfs fixture used in # the next tests, because errors in fixtures break teardown vm = host.import_vm(vm_image('mini-linux-x86_64-bios'), sr_uuid=sr.uuid) vm.destroy(verify=True) sr.destroy(verify=True) +# Make sure these fixtures are called before the parametrized one +@pytest.mark.usefixtures('sr_device_config', 'hosts') class TestNFSSR: @pytest.mark.quicktest - def test_quicktest(self, nfs_sr): - nfs_sr.run_quicktest() + @pytest.mark.parametrize('dispatch_nfs', ['nfs_sr', 'nfs4_sr'], indirect=True) + def test_quicktest(self, dispatch_nfs): + sr = dispatch_nfs + sr.run_quicktest() - def test_vdi_is_not_open(self, vdi_on_nfs_sr): - assert not vdi_is_open(vdi_on_nfs_sr) + @pytest.mark.parametrize('dispatch_nfs', ['vdi_on_nfs_sr', 'vdi_on_nfs4_sr'], indirect=True) + def test_vdi_is_not_open(self, dispatch_nfs): + vdi = dispatch_nfs + assert not vdi_is_open(vdi) @pytest.mark.small_vm # run with a small VM to test the features @pytest.mark.big_vm # and ideally with a big VM to test it scales - def test_start_and_shutdown_VM(self, vm_on_nfs_sr): - vm = vm_on_nfs_sr + # Make sure this fixture is called before the parametrized one + @pytest.mark.usefixtures('vm_ref') + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_start_and_shutdown_VM(self, dispatch_nfs): + vm = dispatch_nfs vm.start() vm.wait_for_os_booted() vm.shutdown(verify=True) @pytest.mark.small_vm @pytest.mark.big_vm - def test_snapshot(self, vm_on_nfs_sr): - vm = vm_on_nfs_sr + # Make sure this fixture is called before the parametrized one + @pytest.mark.usefixtures('vm_ref') + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_snapshot(self, dispatch_nfs): + vm = dispatch_nfs vm.start() try: vm.wait_for_os_booted() @@ -46,8 +62,11 @@ def test_snapshot(self, vm_on_nfs_sr): @pytest.mark.reboot @pytest.mark.small_vm - def test_reboot(self, host, vm_on_nfs_sr): - vm = vm_on_nfs_sr + # Make sure this fixture is called before the parametrized one + @pytest.mark.usefixtures('vm_ref') + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_reboot(self, host, dispatch_nfs): + vm = dispatch_nfs sr = vm.get_sr() host.reboot(verify=True) wait_for(sr.all_pbds_attached, "Wait for PBD attached") diff --git a/tests/storage/nfs/test_nfs_sr_crosspool_migration.py b/tests/storage/nfs/test_nfs_sr_crosspool_migration.py index 7f5d5d729..c09177f01 100644 --- a/tests/storage/nfs/test_nfs_sr_crosspool_migration.py +++ b/tests/storage/nfs/test_nfs_sr_crosspool_migration.py @@ -11,9 +11,13 @@ @pytest.mark.small_vm # run with a small VM to test the features @pytest.mark.big_vm # and ideally with a big VM to test it scales @pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1") +# Make sure these fixtures are called before the parametrized one +@pytest.mark.usefixtures('sr_device_config', 'vm_ref', 'hosts') class Test: - def test_cold_crosspool_migration(self, host, hostB1, vm_on_nfs_sr, local_sr_on_hostB1): - cold_migration_then_come_back(vm_on_nfs_sr, host, hostB1, local_sr_on_hostB1) + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_cold_crosspool_migration(self, host, hostB1, dispatch_nfs, local_sr_on_hostB1): + cold_migration_then_come_back(dispatch_nfs, host, hostB1, local_sr_on_hostB1) - def test_live_crosspool_migration(self, host, hostB1, vm_on_nfs_sr, local_sr_on_hostB1): - live_storage_migration_then_come_back(vm_on_nfs_sr, host, hostB1, local_sr_on_hostB1) + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_live_crosspool_migration(self, host, hostB1, dispatch_nfs, local_sr_on_hostB1): + live_storage_migration_then_come_back(dispatch_nfs, host, hostB1, local_sr_on_hostB1) diff --git a/tests/storage/nfs/test_nfs_sr_intrapool_migration.py b/tests/storage/nfs/test_nfs_sr_intrapool_migration.py index 97a4da5be..acde175bc 100644 --- a/tests/storage/nfs/test_nfs_sr_intrapool_migration.py +++ b/tests/storage/nfs/test_nfs_sr_intrapool_migration.py @@ -11,13 +11,18 @@ @pytest.mark.small_vm # run with a small VM to test the features @pytest.mark.big_vm # and ideally with a big VM to test it scales @pytest.mark.usefixtures("hostA2", "local_sr_on_hostA2") +# Make sure these fixtures are called before the parametrized one +@pytest.mark.usefixtures('sr_device_config', 'vm_ref', 'hosts') class Test: - def test_live_intrapool_shared_migration(self, host, hostA2, vm_on_nfs_sr): - sr = vm_on_nfs_sr.get_sr() - live_storage_migration_then_come_back(vm_on_nfs_sr, host, hostA2, sr) + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_live_intrapool_shared_migration(self, host, hostA2, dispatch_nfs): + sr = dispatch_nfs.get_sr() + live_storage_migration_then_come_back(dispatch_nfs, host, hostA2, sr) - def test_cold_intrapool_migration(self, host, hostA2, vm_on_nfs_sr, local_sr_on_hostA2): - cold_migration_then_come_back(vm_on_nfs_sr, host, hostA2, local_sr_on_hostA2) + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_cold_intrapool_migration(self, host, hostA2, dispatch_nfs, local_sr_on_hostA2): + cold_migration_then_come_back(dispatch_nfs, host, hostA2, local_sr_on_hostA2) - def test_live_intrapool_migration(self, host, hostA2, vm_on_nfs_sr, local_sr_on_hostA2): - live_storage_migration_then_come_back(vm_on_nfs_sr, host, hostA2, local_sr_on_hostA2) + @pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True) + def test_live_intrapool_migration(self, host, hostA2, dispatch_nfs, local_sr_on_hostA2): + live_storage_migration_then_come_back(dispatch_nfs, host, hostA2, local_sr_on_hostA2)