forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[show] Break some groups out into their own modules (sonic-net#1259)
In order to organize code better, reduce the size of large files and help granularize unit test coverage reports, break out the following groups from show/main.py into their own files: - acl - dropcounters - gearbox - kdump - nat - platform - processes - sflow - vnet - vxlan - warm_restart Also remove the following check from utilities_common/cli.py:run_command() and fix all tests which relied upon it: ``` if os.getenv("UTILITIES_UNIT_TESTING") == "1": return ```
- Loading branch information
Showing
19 changed files
with
1,228 additions
and
1,074 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import click | ||
import utilities_common.cli as clicommon | ||
|
||
|
||
# | ||
# 'acl' group ### | ||
# | ||
|
||
@click.group(cls=clicommon.AliasedGroup) | ||
def acl(): | ||
"""Show ACL related information""" | ||
pass | ||
|
||
|
||
# 'rule' subcommand ("show acl rule") | ||
@acl.command() | ||
@click.argument('table_name', required=False) | ||
@click.argument('rule_id', required=False) | ||
@click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
def rule(table_name, rule_id, verbose): | ||
"""Show existing ACL rules""" | ||
cmd = "acl-loader show rule" | ||
|
||
if table_name is not None: | ||
cmd += " {}".format(table_name) | ||
|
||
if rule_id is not None: | ||
cmd += " {}".format(rule_id) | ||
|
||
clicommon.run_command(cmd, display_cmd=verbose) | ||
|
||
|
||
# 'table' subcommand ("show acl table") | ||
@acl.command() | ||
@click.argument('table_name', required=False) | ||
@click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
def table(table_name, verbose): | ||
"""Show existing ACL tables""" | ||
cmd = "acl-loader show table" | ||
|
||
if table_name is not None: | ||
cmd += " {}".format(table_name) | ||
|
||
clicommon.run_command(cmd, display_cmd=verbose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import click | ||
import utilities_common.cli as clicommon | ||
|
||
|
||
# | ||
# 'dropcounters' group ### | ||
# | ||
|
||
@click.group(cls=clicommon.AliasedGroup) | ||
def dropcounters(): | ||
"""Show drop counter related information""" | ||
pass | ||
|
||
|
||
# 'configuration' subcommand ("show dropcounters configuration") | ||
@dropcounters.command() | ||
@click.option('-g', '--group', required=False) | ||
@click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
def configuration(group, verbose): | ||
"""Show current drop counter configuration""" | ||
cmd = "dropconfig -c show_config" | ||
|
||
if group: | ||
cmd += " -g '{}'".format(group) | ||
|
||
clicommon.run_command(cmd, display_cmd=verbose) | ||
|
||
|
||
# 'capabilities' subcommand ("show dropcounters capabilities") | ||
@dropcounters.command() | ||
@click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
def capabilities(verbose): | ||
"""Show device drop counter capabilities""" | ||
cmd = "dropconfig -c show_capabilities" | ||
|
||
clicommon.run_command(cmd, display_cmd=verbose) | ||
|
||
|
||
# 'counts' subcommand ("show dropcounters counts") | ||
@dropcounters.command() | ||
@click.option('-g', '--group', required=False) | ||
@click.option('-t', '--counter_type', required=False) | ||
@click.option('--verbose', is_flag=True, help="Enable verbose output") | ||
def counts(group, counter_type, verbose): | ||
"""Show drop counts""" | ||
cmd = "dropstat -c show" | ||
|
||
if group: | ||
cmd += " -g '{}'".format(group) | ||
|
||
if counter_type: | ||
cmd += " -t '{}'".format(counter_type) | ||
|
||
clicommon.run_command(cmd, display_cmd=verbose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import click | ||
import utilities_common.cli as clicommon | ||
|
||
|
||
@click.group(cls=clicommon.AliasedGroup) | ||
def gearbox(): | ||
"""Show gearbox info""" | ||
pass | ||
|
||
# 'phys' subcommand ("show gearbox phys") | ||
@gearbox.group(cls=clicommon.AliasedGroup) | ||
def phys(): | ||
"""Show external PHY information""" | ||
pass | ||
|
||
# 'status' subcommand ("show gearbox phys status") | ||
@phys.command() | ||
@click.pass_context | ||
def status(ctx): | ||
"""Show gearbox phys status""" | ||
clicommon.run_command("gearboxutil phys status") | ||
|
||
# 'interfaces' subcommand ("show gearbox interfaces") | ||
@gearbox.group(cls=clicommon.AliasedGroup) | ||
def interfaces(): | ||
"""Show gearbox interfaces information""" | ||
pass | ||
|
||
# 'status' subcommand ("show gearbox interfaces status") | ||
@interfaces.command() | ||
@click.pass_context | ||
def status(ctx): | ||
"""Show gearbox interfaces status""" | ||
clicommon.run_command("gearboxutil interfaces status") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import click | ||
import utilities_common.cli as clicommon | ||
from swsssdk import ConfigDBConnector | ||
|
||
|
||
# | ||
# 'kdump command ("show kdump ...") | ||
# | ||
@click.group(cls=clicommon.AliasedGroup) | ||
def kdump(): | ||
"""Show kdump configuration, status and information """ | ||
pass | ||
|
||
|
||
@kdump.command('enabled') | ||
def enabled(): | ||
"""Show if kdump is enabled or disabled""" | ||
kdump_is_enabled = False | ||
config_db = ConfigDBConnector() | ||
if config_db is not None: | ||
config_db.connect() | ||
table_data = config_db.get_table('KDUMP') | ||
if table_data is not None: | ||
config_data = table_data.get('config') | ||
if config_data is not None: | ||
if config_data.get('enabled').lower() == 'true': | ||
kdump_is_enabled = True | ||
if kdump_is_enabled: | ||
click.echo("kdump is enabled") | ||
else: | ||
click.echo("kdump is disabled") | ||
|
||
|
||
@kdump.command('status') | ||
def status(): | ||
"""Show kdump status""" | ||
clicommon.run_command("sonic-kdump-config --status") | ||
clicommon.run_command("sonic-kdump-config --memory") | ||
clicommon.run_command("sonic-kdump-config --num_dumps") | ||
clicommon.run_command("sonic-kdump-config --files") | ||
|
||
|
||
@kdump.command('memory') | ||
def memory(): | ||
"""Show kdump memory information""" | ||
kdump_memory = "0M-2G:256M,2G-4G:320M,4G-8G:384M,8G-:448M" | ||
config_db = ConfigDBConnector() | ||
if config_db is not None: | ||
config_db.connect() | ||
table_data = config_db.get_table('KDUMP') | ||
if table_data is not None: | ||
config_data = table_data.get('config') | ||
if config_data is not None: | ||
kdump_memory_from_db = config_data.get('memory') | ||
if kdump_memory_from_db is not None: | ||
kdump_memory = kdump_memory_from_db | ||
click.echo("Memory Reserved: {}".format(kdump_memory)) | ||
|
||
|
||
@kdump.command('num_dumps') | ||
def num_dumps(): | ||
"""Show kdump max number of dump files""" | ||
kdump_num_dumps = "3" | ||
config_db = ConfigDBConnector() | ||
if config_db is not None: | ||
config_db.connect() | ||
table_data = config_db.get_table('KDUMP') | ||
if table_data is not None: | ||
config_data = table_data.get('config') | ||
if config_data is not None: | ||
kdump_num_dumps_from_db = config_data.get('num_dumps') | ||
if kdump_num_dumps_from_db is not None: | ||
kdump_num_dumps = kdump_num_dumps_from_db | ||
click.echo("Maximum number of Kernel Core files Stored: {}".format(kdump_num_dumps)) | ||
|
||
|
||
@kdump.command('files') | ||
def files(): | ||
"""Show kdump kernel core dump files""" | ||
clicommon.run_command("sonic-kdump-config --files") | ||
|
||
|
||
@kdump.command() | ||
@click.argument('record', required=True) | ||
@click.argument('lines', metavar='<lines>', required=False) | ||
def log(record, lines): | ||
"""Show kdump kernel core dump file kernel log""" | ||
cmd = "sonic-kdump-config --file {}".format(record) | ||
|
||
if lines is not None: | ||
cmd += " --lines {}".format(lines) | ||
|
||
clicommon.run_command(cmd) |
Oops, something went wrong.