Skip to content

Commit ad9ff38

Browse files
mgr/vol: better to call base class __init__() at beginning
It is a good practice and a common convention to call base class's __init__() method at the beginning of derived class's __init__(). It ensures proper initialization of base class's attributes and methods. Signed-off-by: Rishabh Dave <[email protected]>
1 parent a1cd410 commit ad9ff38

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/pybind/mgr/volumes/fs/async_cloner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ class Cloner(AsyncJobs):
313313
the driver. file types supported are directories, symbolic links and regular files.
314314
"""
315315
def __init__(self, volume_client, tp_size, snapshot_clone_delay, clone_no_wait):
316+
super(Cloner, self).__init__(volume_client, "cloner", tp_size)
317+
316318
self.vc = volume_client
317319
self.snapshot_clone_delay = snapshot_clone_delay
318320
self.snapshot_clone_no_wait = clone_no_wait
@@ -323,7 +325,6 @@ def __init__(self, volume_client, tp_size, snapshot_clone_delay, clone_no_wait):
323325
SubvolumeStates.STATE_FAILED : handle_clone_failed,
324326
SubvolumeStates.STATE_CANCELED : handle_clone_failed,
325327
}
326-
super(Cloner, self).__init__(volume_client, "cloner", tp_size)
327328

328329
def reconfigure_max_concurrent_clones(self, tp_size):
329330
return super(Cloner, self).reconfigure_max_async_threads(tp_size)

src/pybind/mgr/volumes/fs/async_job.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class JobThread(threading.Thread):
1919
MAX_RETRIES_ON_EXCEPTION = 10
2020

2121
def __init__(self, async_job, volume_client, name):
22+
threading.Thread.__init__(self, name=name)
23+
2224
self.vc = volume_client
2325
self.async_job = async_job
2426
# event object to cancel jobs
2527
self.cancel_event = threading.Event()
26-
threading.Thread.__init__(self, name=name)
2728

2829
def run(self):
2930
retries = 0
@@ -117,6 +118,7 @@ class AsyncJobs(threading.Thread):
117118

118119
def __init__(self, volume_client, name_pfx, nr_concurrent_jobs):
119120
threading.Thread.__init__(self, name="{0}.tick".format(name_pfx))
121+
120122
self.vc = volume_client
121123
# queue of volumes for starting async jobs
122124
self.q = deque() # type: deque

src/pybind/mgr/volumes/fs/purge_queue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ class ThreadPoolPurgeQueueMixin(AsyncJobs):
103103
_all_ threads purging entries for one volume (starving other volumes).
104104
"""
105105
def __init__(self, volume_client, tp_size):
106-
self.vc = volume_client
107106
super(ThreadPoolPurgeQueueMixin, self).__init__(volume_client, "purgejob", tp_size)
108107

108+
self.vc = volume_client
109+
109110
def get_next_job(self, volname, running_jobs):
110111
return get_trash_entry_for_volume(self.fs_client, self.vc.volspec, volname, running_jobs)
111112

0 commit comments

Comments
 (0)