Skip to content

Commit 61160d8

Browse files
committed
test-info: allow extra configuration to be set
Some tests may require additional information to run their tests, we can provide this information in the extra section. Signed-off-by: Sachin Prabhu <[email protected]>
1 parent 5a031fc commit 61160d8

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

selftest/test-info1.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ users:
99
# Backend filesystem of the exported shares
1010
backend: glusterfs
1111

12+
# Additional information which may be used by tests here
13+
# some tests may be skipped if the required config option is not set
14+
extra:
15+
# The supplementary group to be used by test_permissions
16+
supplementary_group: test_sg
17+
18+
1219
# shares: List of dict of exported shares
1320
shares:
1421
# share export1

selftest/test_testhelper.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,16 @@ def test_generate_exported_shares():
6262
arr.append((share["server"], share["name"]))
6363
assert len(arr) == 1
6464
assert ("server_name", "export2") in arr
65+
66+
67+
def test_get_extra_configuration():
68+
testinfo = testhelper.read_yaml("test-info1.yml")
69+
sg = testhelper.get_extra_configuration(testinfo, "supplementary_group")
70+
assert sg == "test_sg", "Could not read extra configuration"
71+
other = testhelper.get_extra_configuration(testinfo, "other")
72+
assert other is None, "Incorrectly read other from extra configuration"
73+
74+
# test-info2.yml does not have extra section
75+
testinfo = testhelper.read_yaml("test-info2.yml")
76+
sg = testhelper.get_extra_configuration(testinfo, "supplementary_group")
77+
assert sg is None, "Could not read extra configuration"

test-info.yml.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ users:
99
# Backend filesystem of the exported shares
1010
backend: glusterfs
1111

12+
# Additional information which may be used by tests here
13+
# some tests may be skipped if the required config option is not set
14+
extra:
15+
# The supplementary group to be used by test_supplementary_group
16+
supplementary_group: sg
17+
1218
# shares: List of dict of exported shares
1319
shares:
1420
# share export1

testhelper/testhelper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,18 @@ def get_exported_shares(test_info: dict) -> typing.List[str]:
192192
if not is_premounted_share(share):
193193
arr.append(share["name"])
194194
return arr
195+
196+
197+
def get_extra_configuration(test_info: dict, extra_var: str) -> typing.Any:
198+
""" Return value of config set in extra section
199+
200+
Parameters:
201+
test_info: Dict containing the parsed yaml file
202+
extra_var: string containing extra config value required
203+
Returns:
204+
value set for the extra_var in the extra section
205+
"""
206+
extra = test_info.get("extra")
207+
if extra is None:
208+
return None
209+
return extra.get(extra_var)

0 commit comments

Comments
 (0)