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

Enabling/fixing debug/undebug feature for quagga/frr #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
100 changes: 100 additions & 0 deletions debug/debug_quagga.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import click
from debug.main import *


###############################################################################
#
# 'debug bgp' cli stanza
#
###############################################################################


@cli.group(cls=AliasedGroup, default_if_no_args=False)
def bgp():
"""debug bgp events """
pass

@bgp.command()
def as4():
"""debug bgp AS4 actions """
command = 'sudo vtysh -c "debug bgp as4"'
run_command(command)

@bgp.command()
def events():
"""debug bgp events """
command = 'sudo vtysh -c "debug bgp events"'
run_command(command)

@bgp.command()
def filters():
"""debug bgp filters """
command = 'sudo vtysh -c "debug bgp filters"'
run_command(command)

@bgp.command()
def fsm():
"""debug bgp fsm """
command = 'sudo vtysh -c "debug bgp fsm"'
run_command(command)

@bgp.command()
def keepalives():
"""debug bgp keepalives """
command = 'sudo vtysh -c "debug bgp keepalives"'
run_command(command)

@bgp.command()
def updates():
"""debug bgp updates """
command = 'sudo vtysh -c "debug bgp updates"'
run_command(command)

@bgp.command()
def zebra():
"""debug bgp zebra messages """
command = 'sudo vtysh -c "debug bgp zebra"'
run_command(command)


###############################################################################
#
# 'debug zebra' cli stanza
#
###############################################################################


@cli.group(cls=AliasedGroup, default_if_no_args=False)
def zebra():
"""debug zebra events """
pass

@zebra.command()
def events():
"""debug zebra events """
command = 'sudo vtysh -c "debug zebra events"'
run_command(command)

@zebra.command()
def fpm():
"""debug zebra fpm events """
command = 'sudo vtysh -c "debug zebra fpm"'
run_command(command)

@zebra.command()
def kernel():
"""debug zebra's kernel-interface events """
command = 'sudo vtysh -c "debug zebra kernel"'
run_command(command)

@zebra.command()
def packet():
"""debug zebra packets """
command = 'sudo vtysh -c "debug zebra packet"'
run_command(command)

@zebra.command()
def rib():
"""debug zebra RIB events """
command = 'sudo vtysh -c "debug zebra rib"'
run_command(command)
68 changes: 46 additions & 22 deletions debug/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import subprocess
from click_default_group import DefaultGroup
from sonic_platform import get_system_routing_stack

try:
import ConfigParser as configparser
Expand Down Expand Up @@ -99,34 +100,57 @@ def run_command(command, pager=False):

@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS)
def cli():
"""SONiC command line - 'debug' command"""
"""SONiC debugging commands for routing events"""
pass

#
# 'bgp' group ###
#

@cli.group(cls=AliasedGroup, default_if_no_args=True)
def bgp():
"""debug bgp on """
pass

@bgp.command(default=True)
def default():
command = 'sudo vtysh -c "debug bgp"'
@cli.command()
def enable():
"""Enable debugging for routing events """
command = 'sudo vtysh -c "configure terminal" -c "log syslog debugging"'
run_command(command)

@bgp.command()
def events():
"""debug bgp events on """
command = 'sudo vtysh -c "debug bgp events"'
@cli.command()
def disable():
"""Disable debugging for routing events """
command = 'sudo vtysh -c "configure terminal" -c "no log syslog debugging"'
run_command(command)

@bgp.command()
def updates():
"""debug bgp events on """
command = 'sudo vtysh -c "debug bgp updates"'
run_command(command)

#
# Inserting 'debug' functionality into cli's parse-chain. Debugging commands are
# determined by the routing-stack being elected.
#
routing_stack = get_system_routing_stack()

if routing_stack == "quagga":

from .debug_quagga import bgp
cli.add_command(bgp)
from .debug_quagga import zebra
cli.add_command(zebra)

elif routing_stack == "frr":

@cli.command()
@click.argument('debug_args', nargs = -1, required = False)
def bgp(debug_args):
"""Debug BGP information"""
debug_cmd = "debug bgp"
for arg in debug_args:
debug_cmd += " " + str(arg)
command = 'sudo vtysh -c "{}"'.format(debug_cmd)
run_command(command)

@cli.command()
@click.argument('debug_args', nargs = -1, required = False)
def zebra(debug_args):
"""Debug Zebra information"""
debug_cmd = "debug zebra"
for arg in debug_args:
debug_cmd += " " + str(arg)
command = 'sudo vtysh -c "{}"'.format(debug_cmd)
run_command(command)


if __name__ == '__main__':
cli()
42 changes: 16 additions & 26 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from natsort import natsorted
from tabulate import tabulate
from swsssdk import ConfigDBConnector
from sonic_platform import get_system_routing_stack

try:
# noinspection PyPep8Naming
Expand Down Expand Up @@ -87,31 +88,6 @@ def get_command(self, ctx, cmd_name):
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))


# To be enhanced. Routing-stack information should be collected from a global
# location (configdb?), so that we prevent the continous execution of this
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.
def get_routing_stack():
command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1"

try:
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')

except OSError, e:
raise OSError("Cannot detect routing-stack")

return (result)


# Global Routing-Stack variable
routing_stack = get_routing_stack()


def run_command(command, display_cmd=False):
if display_cmd:
click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green'))
Expand Down Expand Up @@ -489,12 +465,17 @@ def protocol(verbose):
# Inserting BGP functionality into cli's show parse-chain.
# BGP commands are determined by the routing-stack being elected.
#
routing_stack = get_system_routing_stack()

if routing_stack == "quagga":

from .bgp_quagga_v4 import bgp
ip.add_command(bgp)
from .bgp_quagga_v6 import bgp
ipv6.add_command(bgp)

elif routing_stack == "frr":

@cli.command()
@click.argument('bgp_args', nargs = -1, required = False)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
Expand All @@ -506,6 +487,15 @@ def bgp(bgp_args, verbose):
cmd = 'sudo vtysh -c "{}"'.format(bgp_cmd)
run_command(cmd, display_cmd=verbose)

@cli.command()
@click.argument('debug_args', nargs = -1, required = False)
def debug(debug_args):
"""Show debuggging configuration state"""
debug_cmd = "show debugging"
for arg in debug_args:
debug_cmd += " " + str(arg)
command = 'sudo vtysh -c "{}"'.format(debug_cmd)
run_command(command)

#
# 'lldp' group ("show lldp ...")
Expand Down Expand Up @@ -692,7 +682,7 @@ def cpu(verbose):
# Run top in batch mode to prevent unexpected newline after each newline
cmd = "top -bn 1 -o %CPU"
run_command(cmd, display_cmd=verbose)

# 'memory' subcommand
@processes.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
Expand Down
59 changes: 34 additions & 25 deletions undebug/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
from click_default_group import DefaultGroup
from sonic_platform import get_system_routing_stack

try:
import ConfigParser as configparser
Expand Down Expand Up @@ -96,36 +97,44 @@ def run_command(command, pager=False):

@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS)
def cli():
"""SONiC command line - 'undebug' command"""
"""SONiC undebugging commands for routing events"""
pass


#
# 'bgp' group ###
# Inserting 'undebug' functionality into cli's parse-chain. Undebugging commands
# are determined by the routing-stack being elected.
#
routing_stack = get_system_routing_stack()

if routing_stack == "quagga":

from .undebug_quagga import bgp
cli.add_command(bgp)
from .undebug_quagga import zebra
cli.add_command(zebra)

elif routing_stack == "frr":

@cli.command()
@click.argument('debug_args', nargs = -1, required = False)
def bgp(debug_args):
"""Debug BGP information"""
debug_cmd = "no debug bgp"
for arg in debug_args:
debug_cmd += " " + str(arg)
command = 'sudo vtysh -c "{}"'.format(debug_cmd)
run_command(command)

@cli.command()
@click.argument('debug_args', nargs = -1, required = False)
def zebra(debug_args):
"""Debug Zebra information"""
debug_cmd = "no debug zebra"
for arg in debug_args:
debug_cmd += " " + str(arg)
command = 'sudo vtysh -c "{}"'.format(debug_cmd)
run_command(command)

# This allows us to add commands to both cli and ip groups, allowing for
@cli.group(cls=AliasedGroup, default_if_no_args=True)
def bgp():
"""undebug bgp on """
pass

@bgp.command(default=True)
def default():
command = 'sudo vtysh -c "undebug bgp"'
run_command(command)

@bgp.command()
def events():
"""undebug bgp events on """
command = 'sudo vtysh -c "undebug bgp events"'
run_command(command)

@bgp.command()
def updates():
"""undebug bgp events on """
command = 'sudo vtysh -c "undebug bgp updates"'
run_command(command)

if __name__ == '__main__':
cli()
Loading