Commit 5a163ac6 authored by Simon Redman's avatar Simon Redman

Upgrade ospf_sniffer_orchestrator to handle multiple stops

parent 7ff543ff
......@@ -68,7 +68,7 @@ def _generate_start_command(path:str=DEFAULT_CLONE_PATH,
)
def _generate_stop_command(pidfile: str=DEFAULT_PIDFILE) -> str:
return "kill $(cat {pidfile})".format(pidfile=pidfile)
return "kill $(cat {pidfile}) && rm {pidfile}".format(pidfile=pidfile)
def clone_repo_on_network(graph: networkx.Graph,
......@@ -170,9 +170,20 @@ def stop_sniffer_on_network(graph: networkx.Graph,
hosts = [host for host in graph.nodes if host not in ignore_nodes]
sessions = [graph._node[host]['session'] for host in hosts]
commands = [_generate_stop_command(pidfile=pidfile)] * len(hosts)
command = _generate_stop_command(pidfile=pidfile)
commands = [command] * len(hosts)
output = ssh_helper.run_commands_on_many_hosts(sessions, commands)
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))
while e is not None:
output = str.join(' ', e.output.splitlines()) # Get rid of newlines
if re.match(acceptable_error, 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
raise
pass
......
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