Skip to content

Commit f0c6352

Browse files
committed
c-foreach-restart: make inner function a class method
1 parent 5b03f2f commit f0c6352

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

cassandra/tools/instances.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def get_instances():
2121
for descr in __get_descriptor_files():
2222
yield Instance(descr)
2323

24-
2524
class Instance(object):
2625
def __init__(self, descr):
2726
with open(descr) as fobj:
@@ -52,28 +51,14 @@ def restart(self, retries=10, delay=6, post_shutdown=None):
5251
self.__log_info("Draining...")
5352
self.nodetool.run("drain")
5453

55-
def exec_command(*args):
56-
(retcode, stdout, stderr) = call(*args)
57-
stdout = stdout.rstrip()
58-
stderr = stderr.rstrip()
59-
if stdout:
60-
for line in stdout.splitlines():
61-
self.__log_info(line)
62-
if stderr:
63-
for line in stderr.splitlines():
64-
self.__log_error(line)
65-
if retcode != 0:
66-
self.__log_error("%s returned exit code %s", args[0], retcode)
67-
raise RuntimeError("{} returned exit code {}".format(args[0], retcode))
68-
6954
# Restart Cassandra
7055
self.__log_info("Stopping service %s", self.service_name)
71-
exec_command("systemctl", "stop", self.service_name)
56+
self.__exec_command("systemctl", "stop", self.service_name)
7257
if post_shutdown:
7358
self.__log_info("Executing post-shutdown command: %s", post_shutdown)
74-
exec_command(*(post_shutdown.strip().split()))
59+
self.__exec_command(*(post_shutdown.strip().split()))
7560
self.__log_info("Starting service %s", self.service_name)
76-
exec_command("systemctl", "start", self.service_name)
61+
self.__exec_command("systemctl", "start", self.service_name)
7762

7863
# Wait for Cassandra to come back up before continuing
7964
listening = False
@@ -94,6 +79,20 @@ def exec_command(*args):
9479
self.__log_error("CQL (%s:%s) DOWN", self.rpc_address, self.native_transport_port)
9580
raise Exception("{} restart FAILED".format(self.service_name))
9681

82+
def __exec_command(self, *args):
83+
(retcode, stdout, stderr) = call(*args)
84+
stdout = stdout.rstrip()
85+
stderr = stderr.rstrip()
86+
if stdout:
87+
for line in stdout.splitlines():
88+
self.__log_info(line)
89+
if stderr:
90+
for line in stderr.splitlines():
91+
self.__log_error(line)
92+
if retcode != 0:
93+
self.__log_error("%s returned exit code %s", args[0], retcode)
94+
raise RuntimeError("{} returned exit code {}".format(args[0], retcode))
95+
9796
def __log_debug(self, msg, *args, **kwargs):
9897
self.__log(logging.DEBUG, msg, *args, **kwargs)
9998

0 commit comments

Comments
 (0)