Skip to content

Commit 19cc12a

Browse files
Standardized the code (#200)
* Standardized the code 1. Added return statements in ops 2. Added docstrings for the same 3. Modified the docstrings that did not match the operation. 4. Changed class names for ops from snake_case to CamelCase. Fixes: #172 Signed-off-by: aujjwal-redhat <[email protected]> * added space Signed-off-by: aujjwal-redhat <[email protected]>
1 parent 31acea1 commit 19cc12a

File tree

10 files changed

+199
-18
lines changed

10 files changed

+199
-18
lines changed

support/mixin.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
"""
55
from support.rexe import Rexe
66
from support.relog import Logger
7-
from support.ops.support_ops.io_ops import io_ops
8-
from support.ops.gluster_ops.peer_ops import peer_ops
7+
from support.ops.support_ops.io_ops import IoOps
8+
from support.ops.gluster_ops.peer_ops import PeerOps
99
from support.ops.gluster_ops.volume_ops import VolumeOps
1010
from support.ops.gluster_ops.gluster_ops import GlusterOps
1111

1212

13-
# pylint: disable=W0107
14-
class RedantMixin(GlusterOps, VolumeOps, peer_ops, io_ops, Rexe, Logger):
13+
class RedantMixin(GlusterOps, VolumeOps, PeerOps, IoOps, Rexe, Logger):
1514
"""
1615
A mixin class for redant project to encompass all ops and support
1716
modules.

support/ops/gluster_ops/gluster_ops.py

+43-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ def start_glusterd(self, node, enable_retry: bool=True):
1616
Args:
1717
node (str|list): The node(s) on which the glusterd service
1818
is to be started.
19+
Returns:
20+
ret: A dictionary consisting
21+
- Flag : Flag to check if connection failed
22+
- msg : message
23+
- error_msg: error message
24+
- error_code: error code returned
25+
- cmd : command that got executed
26+
- node : node on which the command got executed
27+
1928
"""
2029
cmd_fail = False
2130
error_msg = ""
@@ -43,12 +52,23 @@ def start_glusterd(self, node, enable_retry: bool=True):
4352

4453
self.logger.info(f"Successfully ran {cmd} on {node}")
4554

55+
return ret
56+
4657
def restart_glusterd(self, node: str, enable_retry: bool=True):
4758
"""
4859
Restarts the glusterd service on the specified node or nodes.
4960
Args:
5061
node (str|list): The node(s) on which the glusterd service
5162
is to be restarted.
63+
Returns:
64+
ret: A dictionary consisting
65+
- Flag : Flag to check if connection failed
66+
- msg : message
67+
- error_msg: error message
68+
- error_code: error code returned
69+
- cmd : command that got executed
70+
- node : node on which the command got executed
71+
5272
"""
5373
cmd_fail = False
5474
error_msg = ""
@@ -76,12 +96,23 @@ def restart_glusterd(self, node: str, enable_retry: bool=True):
7696

7797
self.logger.info(f"Successfully ran {cmd} on {node}")
7898

99+
return ret
100+
79101
def stop_glusterd(self, node):
80102
"""
81103
Stops the glusterd service on the specified node(s).
82104
Args:
83105
node (str|list): The node on which the glusterd service
84106
is to be stopped.
107+
Returns:
108+
ret: A dictionary consisting
109+
- Flag : Flag to check if connection failed
110+
- msg : message
111+
- error_msg: error message
112+
- error_code: error code returned
113+
- cmd : command that got executed
114+
- node : node on which the command got executed
115+
85116
"""
86117
cmd = "systemctl stop glusterd"
87118

@@ -99,6 +130,8 @@ def stop_glusterd(self, node):
99130

100131
self.logger.info(f"Successfully ran {cmd} on {node}")
101132

133+
return ret
134+
102135
def reset_failed_glusterd(self, node) -> bool:
103136
"""
104137
Glusterd has a burst limit of 5 times, hence TCs will
@@ -111,7 +144,14 @@ def reset_failed_glusterd(self, node) -> bool:
111144
reset-failed has to be run.
112145
113146
Returns:
114-
bool: True if successful on all servers or false.
147+
ret: A dictionary consisting
148+
- Flag : Flag to check if connection failed
149+
- msg : message
150+
- error_msg: error message
151+
- error_code: error code returned
152+
- cmd : command that got executed
153+
- node : node on which the command got executed
154+
115155
"""
116156
if not isinstance(node, list):
117157
node = [node]
@@ -128,6 +168,8 @@ def reset_failed_glusterd(self, node) -> bool:
128168

129169
self.logger.info(f"Successfully ran {cmd} on {node}")
130170

171+
return ret
172+
131173
def is_glusterd_running(self, node: str) -> bool:
132174
"""
133175
Checks the status of the glusterd service on the

support/ops/gluster_ops/peer_ops.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
2-
This file contains one class - peer_ops which
2+
This file contains one class - PeerOps which
33
holds APIS related to peers which will be called
44
from the test case.
55
"""
66

77

8-
class peer_ops:
8+
class PeerOps:
99
"""
10-
peer_ops class provides APIs to perform operations
10+
PeerOps class provides APIs to perform operations
1111
like adding and deleting the peers,checking the status
1212
and list of peers in the pool.
1313
"""

support/ops/gluster_ops/volume_ops.py

+115-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ def volume_mount(self, server: str, volname: str,
2222
server (str): Hostname or IP address
2323
volname (str): Name of volume to be mounted
2424
path (str): The path of the mount directory(mount point)
25+
26+
Returns:
27+
ret: A dictionary consisting
28+
- Flag : Flag to check if connection failed
29+
- msg : message
30+
- error_msg: error message
31+
- error_code: error code returned
32+
- cmd : command that got executed
33+
- node : node on which the command got executed
34+
2535
"""
2636

2737
cmd = f"mount -t glusterfs {server}:/{volname} {path}"
@@ -35,6 +45,8 @@ def volume_mount(self, server: str, volname: str,
3545
raise Exception(ret["error_msg"])
3646

3747
self.logger.info(f"Successfully ran {cmd} on {node}")
48+
49+
return ret
3850

3951
def volume_unmount(self, path: str, node: str=None):
4052
"""
@@ -45,6 +57,16 @@ def volume_unmount(self, path: str, node: str=None):
4557
server (str): Hostname or IP address
4658
volname (str): Name of volume to be mounted
4759
path (str): The path of the mount directory(mount point)
60+
61+
Returns:
62+
ret: A dictionary consisting
63+
- Flag : Flag to check if connection failed
64+
- msg : message
65+
- error_msg: error message
66+
- error_code: error code returned
67+
- cmd : command that got executed
68+
- node : node on which the command got executed
69+
4870
"""
4971

5072
cmd = f"umount {path}"
@@ -59,6 +81,7 @@ def volume_unmount(self, path: str, node: str=None):
5981

6082
self.logger.info(f"Successfully ran {cmd} on {node}")
6183

84+
return ret
6285

6386
def volume_create(self, volname: str, bricks_list: list,
6487
node : str=None, force: bool = False,
@@ -84,6 +107,15 @@ def volume_create(self, volname: str, bricks_list: list,
84107
- redundancy_count : (int)|None
85108
- transport_type : tcp|rdma|tcp,rdma|None
86109
- ...
110+
Returns:
111+
ret: A dictionary consisting
112+
- Flag : Flag to check if connection failed
113+
- msg : message
114+
- error_msg: error message
115+
- error_code: error code returned
116+
- cmd : command that got executed
117+
- node : node on which the command got executed
118+
87119
"""
88120

89121
replica = arbiter = stripe = disperse = disperse_data = redundancy = ''
@@ -128,16 +160,28 @@ def volume_create(self, volname: str, bricks_list: list,
128160

129161
self.logger.info(f"Successfully ran {cmd} on {node}")
130162

163+
return ret
164+
131165
def volume_start(self, volname: str, node : str=None, force: bool = False):
132166
"""
133167
Starts the gluster volume
134168
Args:
135169
node (str): Node on which cmd has to be executed.
136170
volname (str): volume name
171+
137172
Kwargs:
138173
force (bool): If this option is set to True, then start volume
139174
will get executed with force option. If it is set to False,
140175
then start volume will get executed without force option
176+
Returns:
177+
ret: A dictionary consisting
178+
- Flag : Flag to check if connection failed
179+
- msg : message
180+
- error_msg: error message
181+
- error_code: error code returned
182+
- cmd : command that got executed
183+
- node : node on which the command got executed
184+
141185
"""
142186

143187
if force:
@@ -155,6 +199,8 @@ def volume_start(self, volname: str, node : str=None, force: bool = False):
155199

156200
self.logger.info(f"Successfully ran {cmd} on {node}")
157201

202+
return ret
203+
158204
def volume_stop(self, volname: str, node : str=None, force: bool = False):
159205
"""
160206
Stops the gluster volume
@@ -165,6 +211,15 @@ def volume_stop(self, volname: str, node : str=None, force: bool = False):
165211
force (bool): If this option is set to True, then start volume
166212
will get executed with force option. If it is set to False,
167213
then start volume will get executed without force option
214+
Returns:
215+
ret: A dictionary consisting
216+
- Flag : Flag to check if connection failed
217+
- msg : message
218+
- error_msg: error message
219+
- error_code: error code returned
220+
- cmd : command that got executed
221+
- node : node on which the command got executed
222+
168223
"""
169224

170225
if force:
@@ -181,6 +236,7 @@ def volume_stop(self, volname: str, node : str=None, force: bool = False):
181236
raise Exception(ret['msg']['opErrstr'])
182237

183238
self.logger.info(f"Successfully ran {cmd} on {node}")
239+
return ret
184240

185241
def volume_delete(self, volname: str,node : str=None):
186242
"""
@@ -189,6 +245,15 @@ def volume_delete(self, volname: str,node : str=None):
189245
Args:
190246
node (str): Node on which cmd has to be executed.
191247
volname (str): volume name
248+
Returns:
249+
ret: A dictionary consisting
250+
- Flag : Flag to check if connection failed
251+
- msg : message
252+
- error_msg: error message
253+
- error_code: error code returned
254+
- cmd : command that got executed
255+
- node : node on which the command got executed
256+
192257
"""
193258

194259
cmd = f"gluster volume delete {volname} --mode=script --xml"
@@ -203,6 +268,8 @@ def volume_delete(self, volname: str,node : str=None):
203268

204269
self.logger.info(f"Successfully ran {cmd} on {node}")
205270

271+
return ret
272+
206273
def get_volume_info(self, node : str=None, volname: str = 'all') -> dict:
207274
"""
208275
Gives volume information
@@ -347,6 +414,15 @@ def volume_reset(self, volname: str, node : str=None, force : bool=False):
347414
then reset volume will get executed without force option
348415
Example:
349416
volume_reset("testvol",server)
417+
418+
Returns:
419+
ret: A dictionary consisting
420+
- Flag : Flag to check if connection failed
421+
- msg : message
422+
- error_msg: error message
423+
- error_code: error code returned
424+
- cmd : command that got executed
425+
- node : node on which the command got executed
350426
351427
"""
352428
if force:
@@ -363,6 +439,8 @@ def volume_reset(self, volname: str, node : str=None, force : bool=False):
363439
raise Exception(ret['msg']['opErrstr'])
364440

365441
self.logger.info(f"Successfully ran {cmd} on {node}")
442+
443+
return ret
366444

367445
def get_volume_status(self,node : str=None,volname : str='all',
368446
service : str='',options : str='') -> dict:
@@ -520,6 +598,16 @@ def set_volume_options(self, volname : str, options : str, node : str=None):
520598
Example:
521599
options = {"user.cifs":"enable","user.smb":"enable"}
522600
set_volume_options("test-vol1", options, server)
601+
602+
Returns:
603+
ret: A dictionary consisting
604+
- Flag : Flag to check if connection failed
605+
- msg : message
606+
- error_msg: error message
607+
- error_code: error code returned
608+
- cmd : command that got executed
609+
- node : node on which the command got executed
610+
523611
"""
524612

525613
volume_options = options
@@ -552,6 +640,8 @@ def set_volume_options(self, volname : str, options : str, node : str=None):
552640
raise Exception(ret['msg']['opErrstr'])
553641

554642
self.logger.info(f"Successfully ran {cmd} on {node}")
643+
644+
return ret
555645

556646
def reset_volume_option(self, volname : str, option : str,
557647
node : str=None, force : bool=False):
@@ -567,6 +657,16 @@ def reset_volume_option(self, volname : str, option : str,
567657
then reset volume will get executed without force option
568658
Example:
569659
reset_volume_option("test-vol1", "option", server)
660+
661+
Returns:
662+
ret: A dictionary consisting
663+
- Flag : Flag to check if connection failed
664+
- msg : message
665+
- error_msg: error message
666+
- error_code: error code returned
667+
- cmd : command that got executed
668+
- node : node on which the command got executed
669+
570670
"""
571671

572672
if force:
@@ -582,7 +682,9 @@ def reset_volume_option(self, volname : str, option : str,
582682
raise Exception(ret['msg']['opErrstr'])
583683

584684
self.logger.info(f"Successfully ran {cmd} on {node}")
585-
685+
686+
return ret
687+
586688
def volume_sync(self, hostname : str, node: str, volname : str='all'):
587689
"""
588690
Sync the volume to the specified host
@@ -593,6 +695,16 @@ def volume_sync(self, hostname : str, node: str, volname : str='all'):
593695
volname (str): volume name. Defaults to 'all'.
594696
Example:
595697
volume_sync(volname="testvol",server)
698+
699+
Returns:
700+
ret: A dictionary consisting
701+
- Flag : Flag to check if connection failed
702+
- msg : message
703+
- error_msg: error message
704+
- error_code: error code returned
705+
- cmd : command that got executed
706+
- node : node on which the command got executed
707+
596708
"""
597709

598710
cmd = f"gluster volume sync {hostname} {volname} --mode=script --xml"
@@ -605,3 +717,5 @@ def volume_sync(self, hostname : str, node: str, volname : str='all'):
605717
raise Exception(ret['msg']['opErrstr'])
606718

607719
self.logger.info(f"Successfully ran {cmd} on {node}")
720+
721+
return ret

0 commit comments

Comments
 (0)