Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fast-reboot-filter-routes.py] Remove click and improve error reporting #77

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions scripts/fast-reboot-filter-routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@
import utilities_common.cli as clicommon
import syslog
import traceback
import click
from swsscommon.swsscommon import ConfigDBConnector

ROUTE_IDX = 1

def get_connected_routes():
cmd = ['sudo', 'vtysh', '-c', "show ip route connected json"]
connected_routes = []
try:
output, ret = clicommon.run_command(cmd, return_cmd=True)
if ret != 0:
click.echo(output.rstrip('\n'))
sys.exit(ret)
if output is not None:
route_info = json.loads(output)
for route in route_info.keys():
connected_routes.append(route)
except Exception:
ctx = click.get_current_context()
ctx.fail("Unable to get connected routes from bgp")

output, ret = clicommon.run_command(cmd, return_cmd=True)
if ret != 0:
raise Exception("Failed to execute {}: {}".format(" ".join(cmd), output.rstrip('\n')))
if output is not None:
route_info = json.loads(output)
for route in route_info.keys():
connected_routes.append(route)

return connected_routes

def get_route(db, route):
Expand Down Expand Up @@ -81,7 +75,8 @@ def main():
syslog.syslog(syslog.LOG_NOTICE, "SIGINT received. Quitting")
res = 1
except Exception as e:
syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc()))
print(e)
syslog.syslog(syslog.LOG_ERR, "Got an exception: {}: Traceback: {}".format(e, traceback.format_exc()))
res = 2
finally:
syslog.closelog()
Expand Down
Loading