Skip to content

Commit e8961cd

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 205468d commit e8961cd

File tree

3 files changed

+127
-23
lines changed

3 files changed

+127
-23
lines changed

test-info.yml.example

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
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
77

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

12-
test_backend: glusterfs
13-
14-
premounted_shares:
15-
- "/testdir1"
16-
- "/testdir2"
11+
# shares: List of dict of exported shares
12+
shares:
13+
# share name export1
14+
export1:
15+
# If present, it means the share is pre-mounted
16+
path: /mnt/share/export1-cephfs-vfs
17+
backend:
18+
# If present backend filesystem
19+
name: cephfs.vfs
20+
# If present, username to perform the tests with on this share
21+
users:
22+
test2: x
23+
# If present, the hostname to use to connect to the test server
24+
server: hostname1
25+
# share name export2
26+
export2:
27+
# 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: 101 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,59 @@
44
from pathlib import Path
55

66

7-
def read_yaml(test_info):
7+
def read_yaml(test_info_file):
88
"""Returns a dict containing the contents of the yaml file.
99
1010
Parameters:
11-
test_info: filename of yaml file.
11+
test_info_file: filename of yaml file.
1212
1313
Returns:
1414
dict: The parsed test information yml as a dictionary.
1515
"""
16-
with open(test_info) as f:
16+
with open(test_info_file) as f:
1717
test_info = yaml.load(f, Loader=yaml.FullLoader)
18+
19+
shares = test_info.get("shares", {})
20+
21+
# Copy exported_sharenames to shares
22+
for sharename in test_info.get("exported_sharenames", []):
23+
assert sharename not in shares, "Duplicate share name present"
24+
shares[sharename] = {}
25+
26+
# Add missing fields with defaults
27+
# Todo : Remove old field names once sit-environment is updated
28+
default_backend = test_info.get("backend") or test_info.get(
29+
"test_backend", "xfs"
30+
)
31+
default_server = (
32+
test_info.get("server")
33+
or test_info.get("public_interfaces", ["localhost"])[0]
34+
)
35+
default_users = test_info.get("users")
36+
if default_users is None:
37+
users = test_info.get("test_users", None)
38+
if users is None:
39+
default_users = {}
40+
else:
41+
for user in users:
42+
default_users = {user["username"]: user["password"]}
43+
44+
for share in shares:
45+
if shares[share] is None:
46+
shares[share] = {"name": share}
47+
else:
48+
shares[share]["name"] = share
49+
if "backend" not in shares[share]:
50+
shares[share]["backend"] = {}
51+
if "name" not in shares[share]["backend"]:
52+
shares[share]["backend"]["name"] = default_backend
53+
if "server" not in share:
54+
shares[share]["server"] = default_server
55+
if "users" not in share:
56+
shares[share]["users"] = default_users
57+
58+
test_info["shares"] = shares
59+
1860
return test_info
1961

2062

@@ -48,11 +90,14 @@ def get_mount_parameters(test_info: dict, share: str) -> typing.Dict[str, str]:
4890
test_info: Dict containing the parsed yaml file.
4991
share: The share for which to get the mount_params
5092
"""
93+
s = get_share(test_info, share)
94+
server = s["server"]
95+
users = list(s["users"].keys())
5196
return gen_mount_params(
52-
test_info["public_interfaces"][0],
97+
server,
5398
share,
54-
test_info["test_users"][0]["username"],
55-
test_info["test_users"][0]["password"],
99+
users[0],
100+
s["users"][users[0]],
56101
)
57102

58103

@@ -76,6 +121,46 @@ def generate_random_bytes(size: int) -> bytes:
76121
return rba[:size]
77122

78123

124+
def get_shares(test_info: dict) -> dict:
125+
"""
126+
Get list of shares
127+
128+
Parameters:
129+
test_info: Dict containing the parsed yaml file.
130+
Returns:
131+
list of dict of shares
132+
"""
133+
return test_info["shares"]
134+
135+
136+
def get_share(test_info: dict, sharename: str) -> dict:
137+
"""
138+
Get share dict for a given sharename
139+
140+
Parameters:
141+
test_info: Dict containing the parsed yaml file.
142+
sharename: name of the share
143+
Returns:
144+
dict of the share
145+
"""
146+
shares = get_shares(test_info)
147+
assert sharename in shares.keys(), "Share not found"
148+
return shares[sharename]
149+
150+
151+
def is_premounted_share(share: dict) -> bool:
152+
"""
153+
Check if the share is a premounted share
154+
155+
Parameters:
156+
share: dict of the share
157+
Returns:
158+
bool
159+
"""
160+
mntdir = share.get("path")
161+
return mntdir is not None
162+
163+
79164
def get_premounted_shares(test_info: dict) -> typing.List[Path]:
80165
"""
81166
Get list of premounted shares
@@ -85,8 +170,11 @@ def get_premounted_shares(test_info: dict) -> typing.List[Path]:
85170
Returns:
86171
list of paths with shares
87172
"""
88-
premounted_shares = test_info.get("premounted_shares", [])
89-
return [Path(mnt) for mnt in premounted_shares]
173+
arr = []
174+
for share in get_shares(test_info).values():
175+
if is_premounted_share(share):
176+
arr.append(Path(share["path"]))
177+
return arr
90178

91179

92180
def get_exported_shares(test_info: dict) -> typing.List[str]:
@@ -97,4 +185,8 @@ def get_exported_shares(test_info: dict) -> typing.List[str]:
97185
Returns:
98186
list of exported shares
99187
"""
100-
return test_info.get("exported_sharenames", [])
188+
arr = []
189+
for share in get_shares(test_info).values():
190+
if not is_premounted_share(share):
191+
arr.append(share["name"])
192+
return arr

0 commit comments

Comments
 (0)