Skip to content

Commit 745b340

Browse files
authored
[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 ```
1 parent 04dd841 commit 745b340

19 files changed

+1228
-1074
lines changed

show/acl.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
4+
5+
#
6+
# 'acl' group ###
7+
#
8+
9+
@click.group(cls=clicommon.AliasedGroup)
10+
def acl():
11+
"""Show ACL related information"""
12+
pass
13+
14+
15+
# 'rule' subcommand ("show acl rule")
16+
@acl.command()
17+
@click.argument('table_name', required=False)
18+
@click.argument('rule_id', required=False)
19+
@click.option('--verbose', is_flag=True, help="Enable verbose output")
20+
def rule(table_name, rule_id, verbose):
21+
"""Show existing ACL rules"""
22+
cmd = "acl-loader show rule"
23+
24+
if table_name is not None:
25+
cmd += " {}".format(table_name)
26+
27+
if rule_id is not None:
28+
cmd += " {}".format(rule_id)
29+
30+
clicommon.run_command(cmd, display_cmd=verbose)
31+
32+
33+
# 'table' subcommand ("show acl table")
34+
@acl.command()
35+
@click.argument('table_name', required=False)
36+
@click.option('--verbose', is_flag=True, help="Enable verbose output")
37+
def table(table_name, verbose):
38+
"""Show existing ACL tables"""
39+
cmd = "acl-loader show table"
40+
41+
if table_name is not None:
42+
cmd += " {}".format(table_name)
43+
44+
clicommon.run_command(cmd, display_cmd=verbose)

show/dropcounters.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
4+
5+
#
6+
# 'dropcounters' group ###
7+
#
8+
9+
@click.group(cls=clicommon.AliasedGroup)
10+
def dropcounters():
11+
"""Show drop counter related information"""
12+
pass
13+
14+
15+
# 'configuration' subcommand ("show dropcounters configuration")
16+
@dropcounters.command()
17+
@click.option('-g', '--group', required=False)
18+
@click.option('--verbose', is_flag=True, help="Enable verbose output")
19+
def configuration(group, verbose):
20+
"""Show current drop counter configuration"""
21+
cmd = "dropconfig -c show_config"
22+
23+
if group:
24+
cmd += " -g '{}'".format(group)
25+
26+
clicommon.run_command(cmd, display_cmd=verbose)
27+
28+
29+
# 'capabilities' subcommand ("show dropcounters capabilities")
30+
@dropcounters.command()
31+
@click.option('--verbose', is_flag=True, help="Enable verbose output")
32+
def capabilities(verbose):
33+
"""Show device drop counter capabilities"""
34+
cmd = "dropconfig -c show_capabilities"
35+
36+
clicommon.run_command(cmd, display_cmd=verbose)
37+
38+
39+
# 'counts' subcommand ("show dropcounters counts")
40+
@dropcounters.command()
41+
@click.option('-g', '--group', required=False)
42+
@click.option('-t', '--counter_type', required=False)
43+
@click.option('--verbose', is_flag=True, help="Enable verbose output")
44+
def counts(group, counter_type, verbose):
45+
"""Show drop counts"""
46+
cmd = "dropstat -c show"
47+
48+
if group:
49+
cmd += " -g '{}'".format(group)
50+
51+
if counter_type:
52+
cmd += " -t '{}'".format(counter_type)
53+
54+
clicommon.run_command(cmd, display_cmd=verbose)

show/gearbox.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
4+
5+
@click.group(cls=clicommon.AliasedGroup)
6+
def gearbox():
7+
"""Show gearbox info"""
8+
pass
9+
10+
# 'phys' subcommand ("show gearbox phys")
11+
@gearbox.group(cls=clicommon.AliasedGroup)
12+
def phys():
13+
"""Show external PHY information"""
14+
pass
15+
16+
# 'status' subcommand ("show gearbox phys status")
17+
@phys.command()
18+
@click.pass_context
19+
def status(ctx):
20+
"""Show gearbox phys status"""
21+
clicommon.run_command("gearboxutil phys status")
22+
23+
# 'interfaces' subcommand ("show gearbox interfaces")
24+
@gearbox.group(cls=clicommon.AliasedGroup)
25+
def interfaces():
26+
"""Show gearbox interfaces information"""
27+
pass
28+
29+
# 'status' subcommand ("show gearbox interfaces status")
30+
@interfaces.command()
31+
@click.pass_context
32+
def status(ctx):
33+
"""Show gearbox interfaces status"""
34+
clicommon.run_command("gearboxutil interfaces status")

show/kdump.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
from swsssdk import ConfigDBConnector
4+
5+
6+
#
7+
# 'kdump command ("show kdump ...")
8+
#
9+
@click.group(cls=clicommon.AliasedGroup)
10+
def kdump():
11+
"""Show kdump configuration, status and information """
12+
pass
13+
14+
15+
@kdump.command('enabled')
16+
def enabled():
17+
"""Show if kdump is enabled or disabled"""
18+
kdump_is_enabled = False
19+
config_db = ConfigDBConnector()
20+
if config_db is not None:
21+
config_db.connect()
22+
table_data = config_db.get_table('KDUMP')
23+
if table_data is not None:
24+
config_data = table_data.get('config')
25+
if config_data is not None:
26+
if config_data.get('enabled').lower() == 'true':
27+
kdump_is_enabled = True
28+
if kdump_is_enabled:
29+
click.echo("kdump is enabled")
30+
else:
31+
click.echo("kdump is disabled")
32+
33+
34+
@kdump.command('status')
35+
def status():
36+
"""Show kdump status"""
37+
clicommon.run_command("sonic-kdump-config --status")
38+
clicommon.run_command("sonic-kdump-config --memory")
39+
clicommon.run_command("sonic-kdump-config --num_dumps")
40+
clicommon.run_command("sonic-kdump-config --files")
41+
42+
43+
@kdump.command('memory')
44+
def memory():
45+
"""Show kdump memory information"""
46+
kdump_memory = "0M-2G:256M,2G-4G:320M,4G-8G:384M,8G-:448M"
47+
config_db = ConfigDBConnector()
48+
if config_db is not None:
49+
config_db.connect()
50+
table_data = config_db.get_table('KDUMP')
51+
if table_data is not None:
52+
config_data = table_data.get('config')
53+
if config_data is not None:
54+
kdump_memory_from_db = config_data.get('memory')
55+
if kdump_memory_from_db is not None:
56+
kdump_memory = kdump_memory_from_db
57+
click.echo("Memory Reserved: {}".format(kdump_memory))
58+
59+
60+
@kdump.command('num_dumps')
61+
def num_dumps():
62+
"""Show kdump max number of dump files"""
63+
kdump_num_dumps = "3"
64+
config_db = ConfigDBConnector()
65+
if config_db is not None:
66+
config_db.connect()
67+
table_data = config_db.get_table('KDUMP')
68+
if table_data is not None:
69+
config_data = table_data.get('config')
70+
if config_data is not None:
71+
kdump_num_dumps_from_db = config_data.get('num_dumps')
72+
if kdump_num_dumps_from_db is not None:
73+
kdump_num_dumps = kdump_num_dumps_from_db
74+
click.echo("Maximum number of Kernel Core files Stored: {}".format(kdump_num_dumps))
75+
76+
77+
@kdump.command('files')
78+
def files():
79+
"""Show kdump kernel core dump files"""
80+
clicommon.run_command("sonic-kdump-config --files")
81+
82+
83+
@kdump.command()
84+
@click.argument('record', required=True)
85+
@click.argument('lines', metavar='<lines>', required=False)
86+
def log(record, lines):
87+
"""Show kdump kernel core dump file kernel log"""
88+
cmd = "sonic-kdump-config --file {}".format(record)
89+
90+
if lines is not None:
91+
cmd += " --lines {}".format(lines)
92+
93+
clicommon.run_command(cmd)

0 commit comments

Comments
 (0)