Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
anilkpandey committed Dec 9, 2020
2 parents 65b1b18 + d414970 commit 38fd881
Show file tree
Hide file tree
Showing 20 changed files with 915 additions and 127 deletions.
32 changes: 32 additions & 0 deletions config/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@ def console():
"""Console-related configuration tasks"""
pass

#
# 'console enable' group ('config console enable')
#
@console.command('enable')
@clicommon.pass_db
def enable_console_switch(db):
"""Enable console switch"""
config_db = db.cfgdb

table = "CONSOLE_SWITCH"
dataKey1 = 'console_mgmt'
dataKey2 = 'enabled'

data = { dataKey2 : "yes" }
config_db.mod_entry(table, dataKey1, data)

#
# 'console disable' group ('config console disable')
#
@console.command('disable')
@clicommon.pass_db
def disable_console_switch(db):
"""Disable console switch"""
config_db = db.cfgdb

table = "CONSOLE_SWITCH"
dataKey1 = 'console_mgmt'
dataKey2 = 'enabled'

data = { dataKey2 : "no" }
config_db.mod_entry(table, dataKey1, data)

#
# 'console add' group ('config console add ...')
#
Expand Down
44 changes: 44 additions & 0 deletions config/kdump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import click
import utilities_common.cli as clicommon
from swsssdk import ConfigDBConnector

@click.group(cls=clicommon.AbbreviationGroup, name="kdump")
def kdump():
""" Configure kdump """
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

@kdump.command()
def disable():
"""Disable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "false"})

@kdump.command()
def enable():
"""Enable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "true"})

@kdump.command()
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
def memory(kdump_memory):
"""Set memory allocated for kdump capture kernel"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory})

@kdump.command('num-dumps')
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)
def num_dumps(kdump_num_dumps):
"""Set max number of dump files for kdump"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})
46 changes: 2 additions & 44 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from . import chassis_modules
from . import console
from . import feature
from . import kdump
from . import kube
from . import mlnx
from . import muxcable
Expand Down Expand Up @@ -892,6 +893,7 @@ def config(ctx):
config.add_command(chassis_modules.chassis_modules)
config.add_command(console.console)
config.add_command(feature.feature)
config.add_command(kdump.kdump)
config.add_command(kube.kubernetes)
config.add_command(muxcable.muxcable)
config.add_command(nat.nat)
Expand Down Expand Up @@ -2026,50 +2028,6 @@ def shutdown():
"""Shut down BGP session(s)"""
pass

@config.group(cls=clicommon.AbbreviationGroup)
def kdump():
""" Configure kdump """
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

@kdump.command()
def disable():
"""Disable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "false"})
clicommon.run_command("sonic-kdump-config --disable")

@kdump.command()
def enable():
"""Enable kdump operation"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"enabled": "true"})
clicommon.run_command("sonic-kdump-config --enable")

@kdump.command()
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
def memory(kdump_memory):
"""Set memory allocated for kdump capture kernel"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory})
clicommon.run_command("sonic-kdump-config --memory %s" % kdump_memory)

@kdump.command('num-dumps')
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)
def num_dumps(kdump_num_dumps):
"""Set max number of dump files for kdump"""
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
config_db.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})
clicommon.run_command("sonic-kdump-config --num_dumps %d" % kdump_num_dumps)

# 'all' subcommand
@shutdown.command()
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
Expand Down
4 changes: 4 additions & 0 deletions consutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
ERR_BUSY = 5

CONSOLE_PORT_TABLE = "CONSOLE_PORT"
CONSOLE_SWITCH_TABLE = "CONSOLE_SWITCH"

LINE_KEY = "LINE"
CUR_STATE_KEY = "CUR_STATE"

# CONFIG_DB Keys
BAUD_KEY = "baud_rate"
DEVICE_KEY = "remote_device"
FLOW_KEY = "flow_control"
FEATURE_KEY = "console_mgmt"
FEATURE_ENABLED_KEY = "enabled"

# STATE_DB Keys
STATE_KEY = "state"
Expand Down
9 changes: 8 additions & 1 deletion consutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
raise ImportError("%s - required module not found" % str(e))

@click.group()
def consutil():
@clicommon.pass_db
def consutil(db):
"""consutil - Command-line utility for interacting with switches via console device"""
config_db = db.cfgdb
data = config_db.get_entry(CONSOLE_SWITCH_TABLE, FEATURE_KEY)
if FEATURE_ENABLED_KEY not in data or data[FEATURE_ENABLED_KEY] == "no":
click.echo("Console switch feature is disabled")
sys.exit(ERR_DISABLE)

SysInfoProvider.init_device_prefix()

# 'show' subcommand
Expand Down
2 changes: 1 addition & 1 deletion fdbutil/filter_fdb_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_arp_entries_map(arp_filename, config_db_filename):
for key, config in arp.items():
if "NEIGH_TABLE" not in key:
continue
table, vlan, ip = tuple(key.split(':'))
table, vlan, ip = tuple(key.split(':', 2)) # split with max of 2 is used here because IPv6 addresses contain ':' causing a creation of a non tuple object
if "NEIGH_TABLE" in table and vlan in vlan_cidr \
and ip_address(ip) in ip_network(vlan_cidr[vlan][ip_interface(ip).version]) \
and "neigh" in config:
Expand Down
53 changes: 35 additions & 18 deletions pfcwd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import click

import utilities_common.cli as clicommon

from natsort import natsorted
from sonic_py_common.multi_asic import get_external_ports
from tabulate import tabulate
Expand Down Expand Up @@ -98,10 +100,14 @@ def get_server_facing_ports(db):


class PfcwdCli(object):
def __init__(self, namespace=None, display=constants.DISPLAY_ALL):
def __init__(
self, db=None, namespace=None, display=constants.DISPLAY_ALL
):
self.db = None
self.config_db = None
self.multi_asic = multi_asic_util.MultiAsic(display, namespace)
self.multi_asic = multi_asic_util.MultiAsic(
display, namespace, db
)
self.table = []
self.all_ports = []

Expand Down Expand Up @@ -397,6 +403,7 @@ def big_red_switch(self, big_red_switch):
pfcwd_info
)


# Show stats
class Show(object):
# Show commands
Expand All @@ -408,19 +415,21 @@ def show():
@multi_asic_util.multi_asic_click_options
@click.option('-e', '--empty', is_flag=True)
@click.argument('queues', nargs=-1)
def stats(namespace, display, empty, queues):
@clicommon.pass_db
def stats(db, namespace, display, empty, queues):
""" Show PFC Watchdog stats per queue """
if (len(queues)):
display = constants.DISPLAY_ALL
PfcwdCli(namespace, display).show_stats(empty, queues)
PfcwdCli(db, namespace, display).show_stats(empty, queues)

# Show config
@show.command()
@multi_asic_util.multi_asic_click_options
@click.argument('ports', nargs=-1)
def config(namespace, display, ports):
@clicommon.pass_db
def config(db, namespace, display, ports):
""" Show PFC Watchdog configuration """
PfcwdCli(namespace, display).config(ports)
PfcwdCli(db, namespace, display).config(ports)


# Start WD
Expand All @@ -432,7 +441,8 @@ class Start(object):
@click.option('--restoration-time', '-r', type=click.IntRange(100, 60000))
@click.argument('ports', nargs=-1)
@click.argument('detection-time', type=click.IntRange(100, 5000))
def start(action, restoration_time, ports, detection_time):
@clicommon.pass_db
def start(db, action, restoration_time, ports, detection_time):
"""
Start PFC watchdog on port(s). To config all ports, use all as input.
Expand All @@ -441,51 +451,58 @@ def start(action, restoration_time, ports, detection_time):
sudo pfcwd start --action drop ports all detection-time 400 --restoration-time 400
"""
PfcwdCli().start(action, restoration_time, ports, detection_time)
PfcwdCli(db).start(
action, restoration_time, ports, detection_time
)


# Set WD poll interval
class Interval(object):
@cli.command()
@click.argument('poll_interval', type=click.IntRange(100, 3000))
def interval(poll_interval):
@clicommon.pass_db
def interval(db, poll_interval):
""" Set PFC watchdog counter polling interval """
PfcwdCli().interval(poll_interval)
PfcwdCli(db).interval(poll_interval)


# Stop WD
class Stop(object):
@cli.command()
@click.argument('ports', nargs=-1)
def stop(ports):
@clicommon.pass_db
def stop(db, ports):
""" Stop PFC watchdog on port(s) """
PfcwdCli().stop(ports)
PfcwdCli(db).stop(ports)


# Set WD default configuration on server facing ports when enable flag is on
class StartDefault(object):
@cli.command("start_default")
def start_default():
@clicommon.pass_db
def start_default(db):
""" Start PFC WD by default configurations """
PfcwdCli().start_default()
PfcwdCli(db).start_default()


# Enable/disable PFC WD counter polling
class CounterPoll(object):
@cli.command('counter_poll')
@click.argument('counter_poll', type=click.Choice(['enable', 'disable']))
def counter_poll(counter_poll):
@clicommon.pass_db
def counter_poll(db, counter_poll):
""" Enable/disable counter polling """
PfcwdCli().counter_poll(counter_poll)
PfcwdCli(db).counter_poll(counter_poll)


# Enable/disable PFC WD BIG_RED_SWITCH mode
class BigRedSwitch(object):
@cli.command('big_red_switch')
@click.argument('big_red_switch', type=click.Choice(['enable', 'disable']))
def big_red_switch(big_red_switch):
@clicommon.pass_db
def big_red_switch(db, big_red_switch):
""" Enable/disable BIG_RED_SWITCH mode """
PfcwdCli().big_red_switch(big_red_switch)
PfcwdCli(db).big_red_switch(big_red_switch)


def get_pfcwd_clis():
Expand Down
9 changes: 7 additions & 2 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ REBOOT_SCRIPT_NAME=$(basename $0)
REBOOT_TYPE="${REBOOT_SCRIPT_NAME}"
VERBOSE=no
FORCE=no
IGNORE_ASIC=no
STRICT=no
REBOOT_METHOD="/sbin/kexec -e"
ASSISTANT_IP_LIST=""
Expand Down Expand Up @@ -55,6 +56,7 @@ function showHelpAndExit()
echo " -h,-? : get this help"
echo " -v : turn on verbose"
echo " -f : force execution"
echo " -i : ignore MD5-checksum-verification of ASIC configuration files"
echo " -r : reboot with /sbin/reboot"
echo " -k : reboot with /sbin/kexec -e [default]"
echo " -x : execute script with -x flag"
Expand All @@ -67,7 +69,7 @@ function showHelpAndExit()

function parseOptions()
{
while getopts "vfh?rkxc:s" opt; do
while getopts "vfih?rkxc:s" opt; do
case ${opt} in
h|\? )
showHelpAndExit
Expand All @@ -78,6 +80,9 @@ function parseOptions()
f )
FORCE=yes
;;
i )
IGNORE_ASIC=yes
;;
r )
REBOOT_METHOD="/sbin/reboot"
;;
Expand Down Expand Up @@ -335,7 +340,7 @@ function reboot_pre_check()
${ASIC_CONFIG_CHECK_SCRIPT} || ASIC_CONFIG_CHECK_EXIT_CODE=$?
if [[ "${ASIC_CONFIG_CHECK_EXIT_CODE}" != "${ASIC_CONFIG_CHECK_SUCCESS}" ]]; then
if [[ x"${FORCE}" == x"yes" ]]; then
if [[ x"${IGNORE_ASIC}" == x"yes" ]]; then
debug "Ignoring ASIC config checksum failure..."
else
error "ASIC config may have changed: errno=${ASIC_CONFIG_CHECK_EXIT_CODE}"
Expand Down
Loading

0 comments on commit 38fd881

Please sign in to comment.