Skip to content

Commit 81db57d

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 025f588 commit 81db57d

File tree

3 files changed

+134
-23
lines changed

3 files changed

+134
-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: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,66 @@
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:
19+
default_users = test_info.get("users")
20+
if default_users is None:
21+
default_users = {}
22+
users = test_info.get("test_users")
23+
if users is not None:
24+
for user in users:
25+
default_users[user["username"]] = user["password"]
26+
return default_users
27+
28+
29+
def read_yaml(test_info_file):
830
"""Returns a dict containing the contents of the yaml file.
931
1032
Parameters:
11-
test_info: filename of yaml file.
33+
test_info_file: filename of yaml file.
1234
1335
Returns:
1436
dict: The parsed test information yml as a dictionary.
1537
"""
16-
with open(test_info) as f:
38+
with open(test_info_file) as f:
1739
test_info = yaml.load(f, Loader=yaml.FullLoader)
40+
41+
shares = test_info.get("shares", {})
42+
43+
# Copy exported_sharenames to shares
44+
# Todo - remove once sit-environment is updated
45+
for sharename in test_info.get("exported_sharenames", []):
46+
assert sharename not in shares, "Duplicate share name present"
47+
shares[sharename] = {}
48+
49+
# Add missing fields with defaults
50+
# Todo : Remove old field names once sit-environment is updated
51+
default_backend = _get_default_backend(test_info)
52+
default_server = _get_default_server(test_info)
53+
default_users = _get_default_users(test_info)
54+
55+
for sharename in shares:
56+
if shares[sharename] is None:
57+
shares[sharename] = {"name": sharename}
58+
share = shares[sharename]
59+
share.setdefault("name", share)
60+
share.setdefault("backend", {})
61+
share.setdefault("server", default_server)
62+
share.setdefault("users", default_users)
63+
share["backend"].setdefault("name", default_backend)
64+
65+
test_info["shares"] = shares
66+
1867
return test_info
1968

2069

@@ -48,11 +97,14 @@ def get_mount_parameters(test_info: dict, share: str) -> typing.Dict[str, str]:
4897
test_info: Dict containing the parsed yaml file.
4998
share: The share for which to get the mount_params
5099
"""
100+
s = get_share(test_info, share)
101+
server = s["server"]
102+
users = list(s["users"].keys())
51103
return gen_mount_params(
52-
test_info["public_interfaces"][0],
104+
server,
53105
share,
54-
test_info["test_users"][0]["username"],
55-
test_info["test_users"][0]["password"],
106+
users[0],
107+
s["users"][users[0]],
56108
)
57109

58110

@@ -76,6 +128,46 @@ def generate_random_bytes(size: int) -> bytes:
76128
return rba[:size]
77129

78130

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

91183

92184
def get_exported_shares(test_info: dict) -> typing.List[str]:
@@ -97,4 +189,8 @@ def get_exported_shares(test_info: dict) -> typing.List[str]:
97189
Returns:
98190
list of exported shares
99191
"""
100-
return test_info.get("exported_sharenames", [])
192+
arr = []
193+
for share in get_shares(test_info).values():
194+
if not is_premounted_share(share):
195+
arr.append(share["name"])
196+
return arr

0 commit comments

Comments
 (0)