Skip to content

Commit f356a59

Browse files
committed
Drop --sr-device-config option
This option would have received the same "stop using a test parameter" handling, but it turns out that: - we cannot tell this is a config for e.g. NFS or CephFS, although they take different parameters - all fixtures deriving from sr_device_config just take what has been given (which can not work at all when a test sessions includes more than one such SR stype) - all verification is delegated to the final `ssh xe sr-create` call - the need for overriding `data.py` with this flag seems very small indeed This drastically simplifies the `*_device_config` fixtures, and changes the variables in data.py should to drop their "DEFAULT_" prefix, since they are now the sole source of configuration. Signed-off-by: Yann Dirson <[email protected]>
1 parent b6ee0eb commit f356a59

File tree

11 files changed

+45
-147
lines changed

11 files changed

+45
-147
lines changed

conftest.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ def pytest_addoption(parser):
4747
default=[],
4848
help="VM key or OVA URL for tests that require only one VM",
4949
)
50-
parser.addoption(
51-
"--sr-device-config",
52-
action="append",
53-
default=[],
54-
help="device-config keys and values for a remote SR. "
55-
"Example: 'server:10.0.0.1,serverpath:/vms,nfsversion:4.1'.",
56-
)
5750
parser.addoption(
5851
"--second-network",
5952
action="store",
@@ -377,21 +370,6 @@ def uefi_vm(imported_vm):
377370
pytest.skip('This test requires an UEFI VM')
378371
yield vm
379372

380-
@pytest.fixture(scope='session')
381-
def sr_device_config(request):
382-
raw_config = request.param
383-
384-
if raw_config is None:
385-
# Use defaults
386-
return None
387-
388-
config = {}
389-
for key_val in raw_config.split(','):
390-
key = key_val.split(':')[0]
391-
value = key_val[key_val.index(':') + 1:]
392-
config[key] = value
393-
return config
394-
395373
@pytest.fixture(scope='session')
396374
def additional_repos(request, hosts):
397375
if request.param is None:
@@ -444,13 +422,6 @@ def pytest_generate_tests(metafunc):
444422
if not vms:
445423
vms = [None] # no --vm parameter does not mean skip the test, for us, it means use the default
446424
metafunc.parametrize("vm_ref", vms, indirect=True, scope="module")
447-
if "sr_device_config" in metafunc.fixturenames:
448-
configs = metafunc.config.getoption("sr_device_config")
449-
if not configs:
450-
# No --sr-device-config parameter doesn't mean skip the test.
451-
# For us it means use the defaults.
452-
configs = [None]
453-
metafunc.parametrize("sr_device_config", configs, indirect=True, scope="session")
454425

455426
def pytest_collection_modifyitems(items, config):
456427
# Automatically mark tests based on fixtures they require.

data.py-dist

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,46 +54,55 @@ DEFAULT_SR = 'default'
5454
CACHE_IMPORTED_VM = False
5555

5656
# Default NFS device config:
57-
DEFAULT_NFS_DEVICE_CONFIG = {
57+
NFS_DEVICE_CONFIG = {
5858
# 'server': '10.0.0.2', # URL/Hostname of NFS server
5959
# 'serverpath': '/path/to/shared/mount' # Path to shared mountpoint
6060
}
6161

6262
# Default NFS4+ only device config:
63-
DEFAULT_NFS4_DEVICE_CONFIG = {
63+
NFS4_DEVICE_CONFIG = {
6464
# 'server': '10.0.0.2', # URL/Hostname of NFS server
6565
# 'serverpath': '/path_to_shared_mount' # Path to shared mountpoint
6666
# 'nfsversion': '4.1'
6767
}
6868

6969
# Default NFS ISO device config:
70-
DEFAULT_NFS_ISO_DEVICE_CONFIG = {
70+
NFS_ISO_DEVICE_CONFIG = {
7171
# 'location': '10.0.0.2:/path/to/shared/mount' # URL/Hostname of NFS server and path to shared mountpoint
7272
}
7373

7474
# Default CIFS ISO device config:
75-
DEFAULT_CIFS_ISO_DEVICE_CONFIG = {
75+
CIFS_ISO_DEVICE_CONFIG = {
7676
# 'location': r'\\10.0.0.2\<shared folder name>',
7777
# 'username': '<user>',
7878
# 'cifspassword': '<password>',
7979
# 'type': 'cifs',
8080
# 'vers': '<1.0> or <3.0>'
8181
}
8282

83-
DEFAULT_CEPHFS_DEVICE_CONFIG = {
83+
CEPHFS_DEVICE_CONFIG = {
8484
# 'server': '10.0.0.2',
8585
# 'serverpath': '/vms'
8686
}
8787

88-
DEFAULT_MOOSEFS_DEVICE_CONFIG = {
88+
MOOSEFS_DEVICE_CONFIG = {
8989
# 'masterhost': 'mfsmaster',
9090
# 'masterport': '9421',
9191
# 'rootpath': '/vms'
9292
}
9393

94-
DEFAULT_LVMOISCSI_DEVICE_CONFIG = {
94+
LVMOISCSI_DEVICE_CONFIG = {
9595
# 'target': '192.168.1.1',
9696
# 'port': '3260',
9797
# 'targetIQN': 'target.example',
9898
# 'SCSIid': 'id'
9999
}
100+
101+
# compatibility settings for older tests
102+
DEFAULT_NFS_DEVICE_CONFIG = NFS_DEVICE_CONFIG
103+
DEFAULT_NFS4_DEVICE_CONFIG = NFS4_DEVICE_CONFIG
104+
DEFAULT_NFS_ISO_DEVICE_CONFIG = NFS_ISO_DEVICE_CONFIG
105+
DEFAULT_CIFS_ISO_DEVICE_CONFIG = CIFS_ISO_DEVICE_CONFIG
106+
DEFAULT_CEPHFS_DEVICE_CONFIG = CEPHFS_DEVICE_CONFIG
107+
DEFAULT_MOOSEFS_DEVICE_CONFIG = MOOSEFS_DEVICE_CONFIG
108+
DEFAULT_LVMOISCSI_DEVICE_CONFIG = LVMOISCSI_DEVICE_CONFIG

lib/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
ignore_ssh_banner = False
22
ssh_output_max_lines = 20
3+
4+
def sr_device_config(datakey):
5+
import data # import here to avoid depending on this user file for collecting tests
6+
return getattr(data, datakey)

tests/storage/cephfs/conftest.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
from lib.common import exec_nofail, raise_errors
5+
from lib import config
56

67
# explicit import for package-scope fixtures
78
from pkgfixtures import pool_with_saved_yum_state
@@ -22,21 +23,8 @@ def pool_with_ceph(pool_without_ceph, pool_with_saved_yum_state):
2223
yield pool
2324

2425
@pytest.fixture(scope='package')
25-
def cephfs_device_config(sr_device_config):
26-
if sr_device_config is not None:
27-
# SR device config from CLI param
28-
config = sr_device_config
29-
else:
30-
# SR device config from data.py defaults
31-
try:
32-
from data import DEFAULT_CEPHFS_DEVICE_CONFIG
33-
except ImportError:
34-
DEFAULT_CEPHFS_DEVICE_CONFIG = {}
35-
if DEFAULT_CEPHFS_DEVICE_CONFIG:
36-
config = DEFAULT_CEPHFS_DEVICE_CONFIG
37-
else:
38-
raise Exception("No default CephFS device-config found, neither in CLI nor in data.py defaults")
39-
return config
26+
def cephfs_device_config():
27+
return config.sr_device_config("CEPHFS_DEVICE_CONFIG")
4028

4129
@pytest.fixture(scope='package')
4230
def cephfs_sr(host, cephfs_device_config, pool_with_ceph):

tests/storage/iso/conftest.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import time
33
import os
44

5+
from lib import config
6+
57
# Explicitly import package-scoped fixtures (see explanation in pkgfixtures.py)
68
from pkgfixtures import formatted_and_mounted_ext4_disk
79

@@ -23,38 +25,12 @@ def local_iso_sr(host, formatted_and_mounted_ext4_disk):
2325
sr.destroy()
2426

2527
@pytest.fixture(scope='module')
26-
def nfs_iso_device_config(sr_device_config):
27-
if sr_device_config is not None:
28-
# SR device config from CLI param
29-
config = sr_device_config
30-
else:
31-
# SR device config from data.py defaults
32-
try:
33-
from data import DEFAULT_NFS_ISO_DEVICE_CONFIG
34-
except ImportError:
35-
DEFAULT_NFS_ISO_DEVICE_CONFIG = {}
36-
if DEFAULT_NFS_ISO_DEVICE_CONFIG:
37-
config = DEFAULT_NFS_ISO_DEVICE_CONFIG
38-
else:
39-
raise Exception("No default NFS ISO device-config found, neither in CLI nor in data.py defaults")
40-
return config
28+
def nfs_iso_device_config():
29+
return config.sr_device_config("NFS_ISO_DEVICE_CONFIG")
4130

4231
@pytest.fixture(scope='module')
43-
def cifs_iso_device_config(sr_device_config):
44-
if sr_device_config is not None:
45-
# SR device config from CLI param
46-
config = sr_device_config
47-
else:
48-
# SR device config from data.py defaults
49-
try:
50-
from data import DEFAULT_CIFS_ISO_DEVICE_CONFIG
51-
except ImportError:
52-
DEFAULT_CIFS_ISO_DEVICE_CONFIG = {}
53-
if DEFAULT_CIFS_ISO_DEVICE_CONFIG:
54-
config = DEFAULT_CIFS_ISO_DEVICE_CONFIG
55-
else:
56-
raise Exception("No default CIFS ISO device-config found, neither in CLI nor in data.py defaults")
57-
return config
32+
def cifs_iso_device_config():
33+
return config.sr_device_config("CIFS_ISO_DEVICE_CONFIG")
5834

5935
@pytest.fixture(scope='module')
6036
def nfs_iso_sr(host, nfs_iso_device_config):

tests/storage/lvmoiscsi/conftest.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
import logging
22
import pytest
33

4+
from lib import config
5+
46
@pytest.fixture(scope='package')
5-
def lvmoiscsi_device_config(sr_device_config):
6-
if sr_device_config is not None:
7-
# SR device config from CLI param
8-
config = sr_device_config
9-
else:
10-
# SR device config from data.py defaults
11-
try:
12-
from data import DEFAULT_LVMOISCSI_DEVICE_CONFIG
13-
except ImportError:
14-
DEFAULT_LVMOISCSI_DEVICE_CONFIG = {}
15-
if DEFAULT_LVMOISCSI_DEVICE_CONFIG:
16-
config = DEFAULT_LVMOISCSI_DEVICE_CONFIG
17-
else:
18-
raise Exception("No default lvmoiscsi device-config found, neither in CLI nor in data.py defaults")
19-
return config
7+
def lvmoiscsi_device_config():
8+
return config.sr_device_config("LVMOISCSI_DEVICE_CONFIG")
209

2110
@pytest.fixture(scope='package')
2211
def lvmoiscsi_sr(host, lvmoiscsi_device_config):

tests/storage/moosefs/conftest.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import pytest
33

4+
from lib import config
5+
46
# explicit import for package-scope fixtures
57
from pkgfixtures import pool_with_saved_yum_state
68

@@ -35,21 +37,8 @@ def pool_with_moosefs_enabled(pool_with_moosefs_installed):
3537
pool.exec_on_hosts_on_error_continue(disable_moosefs)
3638

3739
@pytest.fixture(scope='package')
38-
def moosefs_device_config(sr_device_config):
39-
if sr_device_config is not None:
40-
# SR device config from CLI param
41-
config = sr_device_config
42-
else:
43-
# SR device config from data.py defaults
44-
try:
45-
from data import DEFAULT_MOOSEFS_DEVICE_CONFIG
46-
except ImportError:
47-
DEFAULT_MOOSEFS_DEVICE_CONFIG = {}
48-
if DEFAULT_MOOSEFS_DEVICE_CONFIG:
49-
config = DEFAULT_MOOSEFS_DEVICE_CONFIG
50-
else:
51-
raise Exception("No default MooseFS device-config found, neither in CLI nor in data.py defaults")
52-
return config
40+
def moosefs_device_config():
41+
return config.sr_device_config("MOOSEFS_DEVICE_CONFIG")
5342

5443
@pytest.fixture(scope='package')
5544
def moosefs_sr(moosefs_device_config, pool_with_moosefs_enabled):

tests/storage/nfs/conftest.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import pytest
33

4+
from lib import config
5+
46
# --- Dispatch fixture for NFS versions ----------------------------------------
57

68
@pytest.fixture
@@ -10,21 +12,8 @@ def dispatch_nfs(request):
1012
# --- NFS3 fixtures ------------------------------------------------------------
1113

1214
@pytest.fixture(scope='package')
13-
def nfs_device_config(sr_device_config):
14-
if sr_device_config is not None:
15-
# SR device config from CLI param
16-
config = sr_device_config
17-
else:
18-
# SR device config from data.py defaults
19-
try:
20-
from data import DEFAULT_NFS_DEVICE_CONFIG
21-
except ImportError:
22-
DEFAULT_NFS_DEVICE_CONFIG = {}
23-
if DEFAULT_NFS_DEVICE_CONFIG:
24-
config = DEFAULT_NFS_DEVICE_CONFIG
25-
else:
26-
raise Exception("No default NFS device-config found, neither in CLI nor in data.py defaults")
27-
return config
15+
def nfs_device_config():
16+
return config.sr_device_config("NFS_DEVICE_CONFIG")
2817

2918
@pytest.fixture(scope='package')
3019
def nfs_sr(host, nfs_device_config):
@@ -51,21 +40,8 @@ def vm_on_nfs_sr(host, nfs_sr, vm_ref):
5140
# --- NFS4+ only fixtures ------------------------------------------------------
5241

5342
@pytest.fixture(scope='package')
54-
def nfs4_device_config(sr_device_config):
55-
if sr_device_config is not None:
56-
# SR device config from CLI param
57-
config = sr_device_config
58-
else:
59-
# SR device config from data.py defaults
60-
try:
61-
from data import DEFAULT_NFS4_DEVICE_CONFIG
62-
except ImportError:
63-
DEFAULT_NFS4_DEVICE_CONFIG = {}
64-
if DEFAULT_NFS4_DEVICE_CONFIG:
65-
config = DEFAULT_NFS4_DEVICE_CONFIG
66-
else:
67-
raise Exception("No default NFS4+ device-config found, neither in CLI nor in data.py defaults")
68-
return config
43+
def nfs4_device_config():
44+
return config.sr_device_config("NFS4_DEVICE_CONFIG")
6945

7046
@pytest.fixture(scope='package')
7147
def nfs4_sr(host, nfs4_device_config):

tests/storage/nfs/test_nfs_sr.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# Requirements:
66
# - one XCP-ng host >= 8.0 with an additional unused disk for the SR
77

8-
# Make sure this fixture is called before the parametrized one
9-
@pytest.mark.usefixtures('sr_device_config')
108
class TestNFSSRCreateDestroy:
119
@pytest.mark.parametrize('dispatch_nfs', ['nfs_device_config', 'nfs4_device_config'], indirect=True)
1210
def test_create_and_destroy_sr(self, host, dispatch_nfs):
@@ -19,8 +17,6 @@ def test_create_and_destroy_sr(self, host, dispatch_nfs):
1917
vm.destroy(verify=True)
2018
sr.destroy(verify=True)
2119

22-
# Make sure these fixtures are called before the parametrized one
23-
@pytest.mark.usefixtures('sr_device_config')
2420
class TestNFSSR:
2521
@pytest.mark.quicktest
2622
@pytest.mark.parametrize('dispatch_nfs', ['nfs_sr', 'nfs4_sr'], indirect=True)

tests/storage/nfs/test_nfs_sr_crosspool_migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@pytest.mark.big_vm # and ideally with a big VM to test it scales
1313
@pytest.mark.usefixtures("hostB1", "local_sr_on_hostB1")
1414
# Make sure these fixtures are called before the parametrized one
15-
@pytest.mark.usefixtures('sr_device_config', 'vm_ref')
15+
@pytest.mark.usefixtures('vm_ref')
1616
class Test:
1717
@pytest.mark.parametrize('dispatch_nfs', ['vm_on_nfs_sr', 'vm_on_nfs4_sr'], indirect=True)
1818
def test_cold_crosspool_migration(self, host, hostB1, dispatch_nfs, local_sr_on_hostB1):

0 commit comments

Comments
 (0)