Skip to content

Commit 076eea4

Browse files
author
vshepard
committed
Fix node.py: try_shutdown and cleanup
1 parent 98b0286 commit 076eea4

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

testgres/node.py

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -334,37 +334,38 @@ def _try_shutdown(self, max_attempts, with_force=False):
334334
attempts = 0
335335
node_pid = self.pid
336336

337-
# try stopping server N times
338-
while attempts < max_attempts:
339-
try:
340-
self.stop()
341-
break # OK
342-
except ExecUtilException:
343-
pass # one more time
344-
except Exception:
345-
eprint('cannot stop node {}'.format(self.name))
346-
break
347-
348-
attempts += 1
349-
350-
# If force stopping is enabled and PID is valid
351-
if with_force and node_pid != 0:
352-
# If we couldn't stop the node
353-
p_status_output = self.os_ops.exec_command(cmd=f'ps -p {node_pid}', shell=True).decode('utf-8')
354-
if self.status() != NodeStatus.Stopped and p_status_output and str(node_pid) in p_status_output:
337+
if node_pid > 0:
338+
# try stopping server N times
339+
while attempts < max_attempts:
355340
try:
356-
eprint(f'Force stopping node {self.name} with PID {node_pid}')
357-
self.os_ops.kill(node_pid, signal.SIGKILL, expect_error=False)
341+
self.stop()
342+
break # OK
343+
except ExecUtilException:
344+
pass # one more time
358345
except Exception:
359-
# The node has already stopped
360-
pass
361-
362-
# Check that node stopped - print only column pid without headers
363-
p_status_output = self.os_ops.exec_command(f'ps -o pid= -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8')
364-
if p_status_output and str(node_pid) in p_status_output:
365-
eprint(f'Failed to stop node {self.name}.')
366-
else:
367-
eprint(f'Node {self.name} has been stopped successfully.')
346+
eprint('cannot stop node {}'.format(self.name))
347+
break
348+
349+
attempts += 1
350+
351+
# If force stopping is enabled and PID is valid
352+
if with_force and node_pid != 0:
353+
# If we couldn't stop the node
354+
p_status_output = self.os_ops.exec_command(cmd=f'ps -p {node_pid}', shell=True).decode('utf-8')
355+
if self.status() != NodeStatus.Stopped and p_status_output and str(node_pid) in p_status_output:
356+
try:
357+
eprint(f'Force stopping node {self.name} with PID {node_pid}')
358+
self.os_ops.kill(node_pid, signal.SIGKILL, expect_error=False)
359+
except Exception:
360+
# The node has already stopped
361+
pass
362+
363+
# Check that node stopped - print only column pid without headers
364+
p_status_output = self.os_ops.exec_command(f'ps -o pid= -p {node_pid}', shell=True, ignore_errors=True).decode('utf-8')
365+
if p_status_output and str(node_pid) in p_status_output:
366+
eprint(f'Failed to stop node {self.name}.')
367+
else:
368+
eprint(f'Node {self.name} has been stopped successfully.')
368369

369370
def _assign_master(self, master):
370371
"""NOTE: this is a private method!"""
@@ -945,6 +946,7 @@ def cleanup(self, max_attempts=3, full=False):
945946
This instance of :class:`.PostgresNode`.
946947
"""
947948

949+
self.stop()
948950
self._try_shutdown(max_attempts)
949951

950952
# choose directory to be removed

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy