Skip to content

Commit d45636b

Browse files
committed
testhelper: introduce shares in test-info.yml
Change the way we list shares in test-info.yml This will be used to add additional functionality to tests. eg: shares: # share name export1 export1: # If present, it means the share is pre-mounted path: /mnt/share/export1-cephfs-vfs backend: # If present backend filesystem name: cephfs.vfs # If present, username to perform the tests with on this share users: test2: x # If present, the hostname to use to connect to the test server server: hostname1 export2: This commit still supports the old format of test-info.yml. The new changes deprecates the old test-info.yml format which can be removed once the sit-environment has been updated. Signed-off-by: Sachin Prabhu <[email protected]>
1 parent 2d9d7f3 commit d45636b

File tree

3 files changed

+131
-23
lines changed

3 files changed

+131
-23
lines changed

test-info.yml.example

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
public_interfaces:
2-
- "192.168.123.10"
3-
- "192.168.123.11"
1+
# Server hostname to be tested
2+
server: server_name
43

5-
exported_sharenames:
6-
- "gluster-vol"
4+
# Users to use for authentication
5+
users:
6+
user1: user1password
7+
user2: user2password
78

8-
test_users:
9-
- {"username": "test1", "password": "x"}
10-
- {"username": "test2", "password": "x"}
9+
# Backend filesystem of the exported shares
10+
backend: glusterfs
1111

12-
test_backend: glusterfs
13-
14-
premounted_shares:
15-
- "/testdir1"
16-
- "/testdir2"
12+
# shares: List of dict of exported shares
13+
shares:
14+
# share export1
15+
export1:
16+
# If present, it means the share is pre-mounted
17+
# at the location given
18+
path: /mnt/share/export1-cephfs-vfs
19+
backend:
20+
# If present override default backend filesystem
21+
name: cephfs.vfs
22+
# If present, use these credentials to perform the
23+
# tests for this share
24+
users:
25+
test2: x
26+
# If present, override the server to test for this share
27+
server: hostname1
28+
# share name export2
29+
export2:
30+
# Use default values set for this share

testcases/smbtorture/test_smbtorture.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def smbtorture(share_name: str, test: str, tmp_output: Path) -> bool:
4848
"--expected-failures=" + script_root + "/selftest/" + filter
4949
)
5050
flapping_list = ["flapping", "flapping.d"]
51-
test_backend = test_info.get("test_backend")
51+
share = testhelper.get_share(test_info, share_name)
52+
test_backend = share["backend"].get("name")
5253
if test_backend is not None:
5354
flapping_file = "flapping." + test_backend
5455
flapping_file_path = os.path.join(

testhelper/testhelper.py

Lines changed: 102 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,63 @@
44
from pathlib import Path
55

66

7-
def read_yaml(test_info):
7+
def _get_default_backend(test_info: dict) -> str:
8+
return test_info.get("backend") or test_info.get("test_backend", "xfs")
9+
10+
11+
def _get_default_server(test_info: dict) -> str:
12+
return (
13+
test_info.get("server")
14+
or test_info.get("public_interfaces", ["localhost"])[0]
15+
)
16+
17+
18+
def _get_default_users(test_info: dict) -> typing.Dict[str, str]:
19+
default_users = test_info.get("users", {})
20+
if not default_users:
21+
for user in test_info.get("test_users", []):
22+
default_users[user["username"]] = user["password"]
23+
return default_users
24+
25+
26+
def read_yaml(test_info_file):
827
"""Returns a dict containing the contents of the yaml file.
928
1029
Parameters:
11-
test_info: filename of yaml file.
30+
test_info_file: filename of yaml file.
1231
1332
Returns:
1433
dict: The parsed test information yml as a dictionary.
1534
"""
16-
with open(test_info) as f:
35+
with open(test_info_file) as f:
1736
test_info = yaml.load(f, Loader=yaml.FullLoader)
37+
38+
shares = test_info.get("shares", {})
39+
40+
# Copy exported_sharenames to shares
41+
# Todo - remove once sit-environment is updated
42+
for sharename in test_info.get("exported_sharenames", []):
43+
assert sharename not in shares, "Duplicate share name present"
44+
shares[sharename] = {}
45+
46+
# Add missing fields with defaults
47+
# Todo : Remove old field names once sit-environment is updated
48+
default_backend = _get_default_backend(test_info)
49+
default_server = _get_default_server(test_info)
50+
default_users = _get_default_users(test_info)
51+
52+
for sharename in shares:
53+
if shares[sharename] is None:
54+
shares[sharename] = {"name": sharename}
55+
share = shares[sharename]
56+
share.setdefault("name", sharename)
57+
share.setdefault("backend", {})
58+
share.setdefault("server", default_server)
59+
share.setdefault("users", default_users)
60+
share["backend"].setdefault("name", default_backend)
61+
62+
test_info["shares"] = shares
63+
1864
return test_info
1965

2066

@@ -48,11 +94,14 @@ def get_mount_parameters(test_info: dict, share: str) -> typing.Dict[str, str]:
4894
test_info: Dict containing the parsed yaml file.
4995
share: The share for which to get the mount_params
5096
"""
97+
s = get_share(test_info, share)
98+
server = s["server"]
99+
users = list(s["users"].keys())
51100
return gen_mount_params(
52-
test_info["public_interfaces"][0],
101+
server,
53102
share,
54-
test_info["test_users"][0]["username"],
55-
test_info["test_users"][0]["password"],
103+
users[0],
104+
s["users"][users[0]],
56105
)
57106

58107

@@ -76,6 +125,46 @@ def generate_random_bytes(size: int) -> bytes:
76125
return rba[:size]
77126

78127

128+
def get_shares(test_info: dict) -> dict:
129+
"""
130+
Get list of shares
131+
132+
Parameters:
133+
test_info: Dict containing the parsed yaml file.
134+
Returns:
135+
list of dict of shares
136+
"""
137+
return test_info["shares"]
138+
139+
140+
def get_share(test_info: dict, sharename: str) -> dict:
141+
"""
142+
Get share dict for a given sharename
143+
144+
Parameters:
145+
test_info: Dict containing the parsed yaml file.
146+
sharename: name of the share
147+
Returns:
148+
dict of the share
149+
"""
150+
shares = get_shares(test_info)
151+
assert sharename in shares.keys(), "Share not found"
152+
return shares[sharename]
153+
154+
155+
def is_premounted_share(share: dict) -> bool:
156+
"""
157+
Check if the share is a premounted share
158+
159+
Parameters:
160+
share: dict of the share
161+
Returns:
162+
bool
163+
"""
164+
mntdir = share.get("path")
165+
return mntdir is not None
166+
167+
79168
def get_premounted_shares(test_info: dict) -> typing.List[Path]:
80169
"""
81170
Get list of premounted shares
@@ -85,8 +174,8 @@ def get_premounted_shares(test_info: dict) -> typing.List[Path]:
85174
Returns:
86175
list of paths with shares
87176
"""
88-
premounted_shares = test_info.get("premounted_shares", [])
89-
return [Path(mnt) for mnt in premounted_shares]
177+
share_values = get_shares(test_info).values()
178+
return [Path(s["path"]) for s in share_values if is_premounted_share(s)]
90179

91180

92181
def get_exported_shares(test_info: dict) -> typing.List[str]:
@@ -97,4 +186,8 @@ def get_exported_shares(test_info: dict) -> typing.List[str]:
97186
Returns:
98187
list of exported shares
99188
"""
100-
return test_info.get("exported_sharenames", [])
189+
arr = []
190+
for share in get_shares(test_info).values():
191+
if not is_premounted_share(share):
192+
arr.append(share["name"])
193+
return arr

0 commit comments

Comments
 (0)