4
4
from pathlib import Path
5
5
6
6
7
- def read_yaml (test_info ):
7
+ def read_yaml (test_info_file ):
8
8
"""Returns a dict containing the contents of the yaml file.
9
9
10
10
Parameters:
11
- test_info : filename of yaml file.
11
+ test_info_file : filename of yaml file.
12
12
13
13
Returns:
14
14
dict: The parsed test information yml as a dictionary.
15
15
"""
16
- with open (test_info ) as f :
16
+ with open (test_info_file ) as f :
17
17
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
+
18
60
return test_info
19
61
20
62
@@ -48,11 +90,14 @@ def get_mount_parameters(test_info: dict, share: str) -> typing.Dict[str, str]:
48
90
test_info: Dict containing the parsed yaml file.
49
91
share: The share for which to get the mount_params
50
92
"""
93
+ s = get_share (test_info , share )
94
+ server = s ["server" ]
95
+ users = list (s ["users" ].keys ())
51
96
return gen_mount_params (
52
- test_info [ "public_interfaces" ][ 0 ] ,
97
+ server ,
53
98
share ,
54
- test_info [ "test_users" ][ 0 ][ "username" ],
55
- test_info [ "test_users " ][0 ][ "password" ],
99
+ users [ 0 ],
100
+ s [ "users " ][users [ 0 ] ],
56
101
)
57
102
58
103
@@ -76,6 +121,46 @@ def generate_random_bytes(size: int) -> bytes:
76
121
return rba [:size ]
77
122
78
123
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
+
79
164
def get_premounted_shares (test_info : dict ) -> typing .List [Path ]:
80
165
"""
81
166
Get list of premounted shares
@@ -85,8 +170,11 @@ def get_premounted_shares(test_info: dict) -> typing.List[Path]:
85
170
Returns:
86
171
list of paths with shares
87
172
"""
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
90
178
91
179
92
180
def get_exported_shares (test_info : dict ) -> typing .List [str ]:
@@ -97,4 +185,8 @@ def get_exported_shares(test_info: dict) -> typing.List[str]:
97
185
Returns:
98
186
list of exported shares
99
187
"""
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