Skip to content

Commit 29a4f47

Browse files
committed
testhelper: introduce exported_shares
Change the way we list shares in test-info.yml This will be used to add additional functionality to tests. Signed-off-by: Sachin Prabhu <[email protected]>
1 parent 0b5fa58 commit 29a4f47

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

test-info.yml.example

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ public_interfaces:
99
exported_sharenames:
1010
- "gluster-vol"
1111

12+
# List of dict of exported shares
13+
# name: share_name
14+
# mntdir: If this is a premounted share, the mount directory
15+
# fs: exported filesystem
16+
exported_shares:
17+
- {"name": "export2"}
18+
- {"name": "export3", "mntdir": "/mnt-cephfs", "fs": "cephfs"}
19+
1220
test_users:
1321
- {"username": "test1", "password": "x"}
1422
- {"username": "test2", "password": "x"}
1523

1624
test_backend: glusterfs
17-
18-
premounted_shares:
19-
- "/testdir1"
20-
- "/testdir2"

testhelper/testhelper.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,47 @@ def generate_random_bytes(size: int) -> bytes:
7676
return rba[:size]
7777

7878

79+
def get_shares(test_info: dict) -> typing.List[dict]:
80+
"""
81+
Get list of shares
82+
83+
Parameters:
84+
test_info: Dict containing the parsed yaml file.
85+
Returns:
86+
list of shares
87+
"""
88+
if "shares" in test_info:
89+
return test_info["shares"]
90+
91+
default_fs = test_info.get("test_backend", "")
92+
arr = []
93+
for sharename in test_info.get("exported_sharenames", []):
94+
arr.append({"name": sharename, "mntdir": "", "fs": default_fs})
95+
for share in test_info.get("exported_shares", []):
96+
arr.append(
97+
{
98+
"name": share.get("name", ""),
99+
"mntdir": share.get("mntdir", ""),
100+
"fs": share.get("fs", default_fs),
101+
}
102+
)
103+
test_info["shares"] = arr
104+
return arr
105+
106+
107+
def is_premounted_share(share: dict) -> bool:
108+
"""
109+
Is the share dict a premounted share
110+
111+
Paramters:
112+
share: dict of the share
113+
Returns:
114+
bool
115+
"""
116+
mntdir = share.get("mntdir", "")
117+
return mntdir != ""
118+
119+
79120
def get_premounted_shares(test_info: dict) -> typing.List[Path]:
80121
"""
81122
Get list of premounted shares
@@ -85,8 +126,11 @@ def get_premounted_shares(test_info: dict) -> typing.List[Path]:
85126
Returns:
86127
list of paths with shares
87128
"""
88-
premounted_shares = test_info.get("premounted_shares", [])
89-
return [Path(mnt) for mnt in premounted_shares]
129+
arr = []
130+
for share in get_shares(test_info):
131+
if is_premounted_share(share):
132+
arr.append(Path(share["mntdir"]))
133+
return arr
90134

91135

92136
def get_exported_shares(test_info: dict) -> typing.List[str]:
@@ -97,4 +141,8 @@ def get_exported_shares(test_info: dict) -> typing.List[str]:
97141
Returns:
98142
list of exported shares
99143
"""
100-
return test_info.get("exported_sharenames", [])
144+
arr = []
145+
for share in get_shares(test_info):
146+
if not is_premounted_share(share):
147+
arr.append(share["name"])
148+
return arr

0 commit comments

Comments
 (0)