Skip to content

Commit

Permalink
Merge branch 'master' into pcie_aer
Browse files Browse the repository at this point in the history
  • Loading branch information
ArunSaravananBalachandran authored Dec 10, 2020
2 parents 310d79f + 57a0b41 commit 35183f9
Show file tree
Hide file tree
Showing 104 changed files with 16,502 additions and 1,501 deletions.
12 changes: 4 additions & 8 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,14 @@ def convert_ip(self, table_name, rule_idx, rule):
rule_props["IP_PROTOCOL"] = rule.ip.config.protocol

if rule.ip.config.source_ip_address:
source_ip_address = rule.ip.config.source_ip_address.encode("ascii")
source_ip_address = rule.ip.config.source_ip_address
if ipaddress.ip_network(source_ip_address).version == 4:
rule_props["SRC_IP"] = source_ip_address
else:
rule_props["SRC_IPV6"] = source_ip_address

if rule.ip.config.destination_ip_address:
destination_ip_address = rule.ip.config.destination_ip_address.encode("ascii")
destination_ip_address = rule.ip.config.destination_ip_address
if ipaddress.ip_network(destination_ip_address).version == 4:
rule_props["DST_IP"] = destination_ip_address
else:
Expand Down Expand Up @@ -550,7 +550,7 @@ def convert_rules(self):
:return:
"""
for acl_set_name in self.yang_acl.acl.acl_sets.acl_set:
table_name = acl_set_name.replace(" ", "_").replace("-", "_").upper().encode('ascii')
table_name = acl_set_name.replace(" ", "_").replace("-", "_").upper()
acl_set = self.yang_acl.acl.acl_sets.acl_set[acl_set_name]

if not self.is_table_valid(table_name):
Expand Down Expand Up @@ -826,11 +826,7 @@ def pop_matches(val):

raw_data.append([priority, rule_data])

def cmp_rules(a, b):
return cmp(a[0], b[0])

raw_data.sort(cmp_rules)
raw_data.reverse()
raw_data.sort(key=lambda x: x[0], reverse=True)

data = []
for _, d in raw_data:
Expand Down
34 changes: 31 additions & 3 deletions clear/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import configparser
import os
import subprocess
import sys

import click

Expand Down Expand Up @@ -93,11 +94,12 @@ def get_routing_stack():
routing_stack = get_routing_stack()


def run_command(command, pager=False, return_output=False):
def run_command(command, pager=False, return_output=False, return_exitstatus=False):
# Provide option for caller function to Process the output.
proc = subprocess.Popen(command, shell=True, text=True, stdout=subprocess.PIPE)
if return_output:
return proc.communicate()
output = proc.communicate()
return output if not return_exitstatus else output + (proc.returncode,)
elif pager:
#click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green'))
click.echo_via_pager(proc.stdout.read())
Expand Down Expand Up @@ -275,6 +277,30 @@ def clear_pwm_q_multi():
command = 'watermarkstat -c -p -t q_shared_multi'
run_command(command)


@cli.group(name='headroom-pool')
def headroom_pool():
"""Clear headroom pool WM"""
pass

@headroom_pool.command('watermark')
def watermark():
"""Clear headroom pool user WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

command = 'watermarkstat -c -t headroom_pool'
run_command(command)

@headroom_pool.command('persistent-watermark')
def persistent_watermark():
"""Clear headroom pool persistent WM. One does not simply clear WM, root is required"""
if os.geteuid() != 0:
exit("Root privileges are required for this operation")

command = 'watermarkstat -c -p -t headroom_pool'
run_command(command)

#
# 'arp' command ####
#
Expand Down Expand Up @@ -367,7 +393,9 @@ def clear_vlan_fdb(vlanid):
def line(target, devicename):
"""Clear preexisting connection to line"""
cmd = "consutil clear {}".format("--devicename " if devicename else "") + str(target)
run_command(cmd)
(output, _, exitstatus) = run_command(cmd, return_output=True, return_exitstatus=True)
click.echo(output)
sys.exit(exitstatus)

#
# 'nat' group ("clear nat ...")
Expand Down
3 changes: 1 addition & 2 deletions config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Using load_source to 'import /usr/local/bin/sonic-cfggen as sonic_cfggen'
# since /usr/local/bin/sonic-cfggen does not have .py extension.
load_source('sonic_cfggen', '/usr/local/bin/sonic-cfggen')
from sonic_cfggen import deep_update, FormatConverter, sort_data
from sonic_cfggen import deep_update, FormatConverter

except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
Expand Down Expand Up @@ -213,7 +213,6 @@ def writeConfigDB(self, jDiff):
configdb = ConfigDBConnector(**db_kwargs)
configdb.connect(False)
deep_update(data, FormatConverter.to_deserialized(jDiff))
data = sort_data(data)
self.sysLog(msg="Write in DB: {}".format(data))
configdb.mod_config(FormatConverter.output_to_db(data))

Expand Down
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
21 changes: 13 additions & 8 deletions config/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ def feature():
@pass_db
def feature_state(db, name, state):
"""Enable/disable a feature"""
state_data = db.cfgdb.get_entry('FEATURE', name)
entry_data = db.cfgdb.get_entry('FEATURE', name)

if not state_data:
if not entry_data:
click.echo("Feature '{}' doesn't exist".format(name))
sys.exit(1)

if entry_data['state'] == "always_enabled":
click.echo("Feature '{}' state is always enabled and can not be modified".format(name))
return

db.cfgdb.mod_entry('FEATURE', name, {'state': state})

#
Expand All @@ -37,13 +41,14 @@ def feature_state(db, name, state):
@pass_db
def feature_autorestart(db, name, autorestart):
"""Enable/disable autorestart of a feature"""
feature_table = db.cfgdb.get_table('FEATURE')
if not feature_table:
click.echo("Unable to retrieve feature table from Config DB.")
sys.exit(1)
entry_data = db.cfgdb.get_entry('FEATURE', name)

if name not in feature_table:
click.echo("Unable to retrieve feature '{}'".format(name))
if not entry_data:
click.echo("Feature '{}' doesn't exist".format(name))
sys.exit(1)

if entry_data['auto_restart'] == "always_enabled":
click.echo("Feature '{}' auto-restart is always enabled and can not be modified".format(name))
return

db.cfgdb.mod_entry('FEATURE', name, {'auto_restart': autorestart})
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})
49 changes: 4 additions & 45 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
from . import chassis_modules
from . import console
from . import feature
from . import kdump
from . import kube
from . import mlnx
from . import muxcable
from . import nat
from . import vlan
from .config_mgmt import ConfigMgmtDPB
Expand Down Expand Up @@ -877,7 +879,9 @@ 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)
config.add_command(vlan.vlan)

Expand Down Expand Up @@ -1899,50 +1903,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 Expand Up @@ -3186,7 +3146,6 @@ def naming_mode_alias():
"""Set CLI interface naming mode to ALIAS (Vendor port alias)"""
set_interface_naming_mode('alias')

@config.group()
def is_loopback_name_valid(loopback_name):
"""Loopback name validation
"""
Expand Down
Loading

0 comments on commit 35183f9

Please sign in to comment.