Commit f57f82bd authored by Simon Redman's avatar Simon Redman

Fix ospf sniffer stop not working if the PID file exists but the contained PID is not valid

parent f321162c
......@@ -72,7 +72,7 @@ def _generate_start_command(path:str=DEFAULT_CLONE_PATH,
)
def _generate_stop_command(pidfile: str=DEFAULT_PIDFILE) -> str:
return "kill $(cat {pidfile}) && rm {pidfile}".format(pidfile=pidfile)
return "kill $(cat {pidfile}); rm -f {pidfile}".format(pidfile=pidfile)
def clone_repo_on_network(graph: networkx.Graph,
......@@ -180,10 +180,15 @@ def stop_sniffer_on_network(graph: networkx.Graph,
try:
output = ssh_helper.run_commands_on_many_hosts(sessions, commands)
except ssh_helper.SSHCommandErrorError as e:
acceptable_error = r".*{command}\s+cat: {pidfile}: No such file or directory.*".format(command=re.escape(command), pidfile=re.escape(pidfile))
# If the PID file does not exist, cat will have an error trying to read it. This is not a problem, since it probably just
# means the sniffer is not running or has already been stopped
acceptable_error_cat = r".*{command}\s+cat: {pidfile}: No such file or directory.*".format(command=re.escape(command), pidfile=re.escape(pidfile))
# If the sniffer cannot be killed, it probably means that it has already died for some reason. Since our goal was to stop it, mission accomplished
acceptable_error_kill = r".*kill: \([0-9]+\) - No such process.*".format(command=re.escape(command), pidfile=re.escape(pidfile))
while e is not None:
output = str.join(' ', e.output.splitlines()) # Get rid of newlines
if re.match(acceptable_error, output):
if re.match(acceptable_error_cat, output) or re.match(acceptable_error_kill, output):
# Presumably this is a sign of the stop command being run more than once or before the sniffer was started: no problem
e = e.next
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment