Commit 79a20659 authored by Simon Redman's avatar Simon Redman

Handle errors in ospf_sniffer_configurator

parent fd74ec55
...@@ -33,7 +33,7 @@ DEFAULT_REPO_URL="https://gitlab.flux.utah.edu/safeedge/ospfv3_monitor.git" ...@@ -33,7 +33,7 @@ DEFAULT_REPO_URL="https://gitlab.flux.utah.edu/safeedge/ospfv3_monitor.git"
def generate_repo_clone_command(repo: str, branch: str, path: str) -> str: def generate_repo_clone_command(repo: str, branch: str, path: str) -> str:
return "git clone {repo} -b {branch} --single-branch {path}".format(repo=repo, branch=branch, path=path) return "git clone -b {branch} --single-branch -- {repo} {path}".format(repo=repo, branch=branch, path=path)
def generate_start_command(path:str=DEFAULT_CLONE_PATH, def generate_start_command(path:str=DEFAULT_CLONE_PATH,
...@@ -65,7 +65,7 @@ def clone_repo_on_network(graph: networkx.Graph, ...@@ -65,7 +65,7 @@ def clone_repo_on_network(graph: networkx.Graph,
branch: str=DEFAULT_REPO_BRANCH, branch: str=DEFAULT_REPO_BRANCH,
path: str=DEFAULT_CLONE_PATH, path: str=DEFAULT_CLONE_PATH,
ignore_nodes: List[str]=None, ignore_nodes: List[str]=None,
) -> Optional[List[str]]: ):
""" """
Clone the specified repository and branch on each non-ignored node in the network Clone the specified repository and branch on each non-ignored node in the network
...@@ -82,19 +82,19 @@ def clone_repo_on_network(graph: networkx.Graph, ...@@ -82,19 +82,19 @@ def clone_repo_on_network(graph: networkx.Graph,
commands = [command for host in hosts] commands = [command for host in hosts]
sessions = [graph._node[host]['session'] for host in hosts] sessions = [graph._node[host]['session'] for host in hosts]
outputs = ssh_helper.run_commands_on_many_hosts(sessions, commands) # If we try to clone into an existing directory, git will return an error
codes = ssh_helper.get_exit_codes(sessions) # (Obviously this will get messed up on a non-English system. Sorry.)
allowed_exception = ".*fatal: destination path \S+ already exists and is not an empty directory"
errors = [] try:
for index in range(0, len(codes)): outputs = ssh_helper.run_commands_on_many_hosts(sessions, commands)
code = codes[index] except ssh_helper.SSHCommandErrorError as e:
if code != 0: while e is not None:
errors.append(outputs[index]) output = str.join('', e.output.splitlines()) # Get rid of linebreaks (otherwise we get one every 80 characters)
if re.match(allowed_exception, output):
if len(errors) == 0: # No problem: Hopefully we tried to re-clone the repository
return None e = e.next
else: else:
return errors raise
def start_sniffer_on_network(graph: networkx.Graph, def start_sniffer_on_network(graph: networkx.Graph,
...@@ -102,7 +102,7 @@ def start_sniffer_on_network(graph: networkx.Graph, ...@@ -102,7 +102,7 @@ def start_sniffer_on_network(graph: networkx.Graph,
executable: str=DEFAULT_EXECUTABLE, executable: str=DEFAULT_EXECUTABLE,
controller: str=DEFAULT_CONTROLLER, controller: str=DEFAULT_CONTROLLER,
pidfile: str=DEFAULT_PIDFILE, pidfile: str=DEFAULT_PIDFILE,
ignore_nodes: List[str]=None) -> Optional[str]: ignore_nodes: List[str]=None):
""" """
Start the sniffer daemon on all non-ignored nodes in the network Start the sniffer daemon on all non-ignored nodes in the network
...@@ -121,18 +121,6 @@ def start_sniffer_on_network(graph: networkx.Graph, ...@@ -121,18 +121,6 @@ def start_sniffer_on_network(graph: networkx.Graph,
sessions = [graph._node[host]['session'] for host in hosts] sessions = [graph._node[host]['session'] for host in hosts]
outputs = ssh_helper.run_commands_on_many_hosts(sessions, commands) outputs = ssh_helper.run_commands_on_many_hosts(sessions, commands)
codes = ssh_helper.get_exit_codes(sessions)
errors = []
for index in range(0, len(codes)):
code = codes[index]
if code != 0:
errors.append(outputs[index])
if len(errors) == 0:
return None
else:
return errors
def stop_sniffer_on_network(graph: networkx.Graph, pidfile: str=DEFAULT_PIDFILE) -> Optional[str]: def stop_sniffer_on_network(graph: networkx.Graph, pidfile: str=DEFAULT_PIDFILE) -> Optional[str]:
...@@ -177,7 +165,7 @@ if __name__ == "__main__": ...@@ -177,7 +165,7 @@ if __name__ == "__main__":
path=args.clone_path, path=args.clone_path,
ignore_nodes=ignore_nodes) ignore_nodes=ignore_nodes)
start_sniffer_on_network(netgraph.graph, start_sniffer_on_network(netgraph.graph,
path=args.repo_path, path=args.clone_path,
controller=args.controller_name, controller=args.controller_name,
pidfile=args.pid_file, pidfile=args.pid_file,
ignore_nodes=ignore_nodes) ignore_nodes=ignore_nodes)
......
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