Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rameshraghupathy authored Sep 1, 2024
2 parents 433bc50 + c4ce5ae commit 3ddcc9c
Show file tree
Hide file tree
Showing 180 changed files with 14,260 additions and 2,462 deletions.
35 changes: 35 additions & 0 deletions .azure-pipelines/pre-commit-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
steps:
- checkout: self
clean: true
displayName: 'checkout sonic-utilities repo'

- script: |
set -x
sudo pip install pre-commit
pre-commit install-hooks
displayName: 'Prepare pre-commit check'

- script: |
# Run pre-commit check and capture the output
out=`pre-commit run --color never --from-ref HEAD^ --to-ref HEAD 2>&1`
RC=$?
if [[ $RC -ne 0 ]]; then
echo -e "The [pre-commit](http://pre-commit.com/) check detected issues in the files touched by this pull request.\n\
The pre-commit check is a mandatory check, please fix detected issues.\n\
\n\
To run the pre-commit checks locally, you can follow below steps:\n\
1. Ensure that default python is python3.\n\
2. Ensure that the 'pre-commit' package is installed:\n\
sudo pip install pre-commit\n\
3. Go to repository root folder\n\
4. Install the pre-commit hooks:\n\
pre-commit install\n\
5. Use pre-commit to check staged file:\n\
pre-commit\n\
6. Alternatively, you can check committed files using:\n\
pre-commit run --from-ref <commit_id> --to-ref <commit_id>\n"
fi
echo "Pre-commit check results:"
echo "$out"
exit $RC
displayName: 'Run pre-commit check'
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
entry: bash -c 'git diff HEAD^ HEAD -U0 -- "$@" | flake8 --diff "$@"' --
args: ["--max-line-length=120"]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ A convenient alternative is to let the SONiC build system configure a build envi

2. Build the sonic-utilities Python wheel package inside the Bullseye slave container, and tell the build system to keep the container alive when finished
```
make NOSTRETCH=1 NOBUSTER=1 KEEP_SLAVE_ON=yes target/python-wheels/bullseye/sonic_utilities-1.2-py3-none-any.whl
make -f Makefile.work BLDENV=bookworm KEEP_SLAVE_ON=yes target/python-wheels/bookworm/sonic_utilities-1.2-py3-none-any.whl
```

3. When the build finishes, your prompt will change to indicate you are inside the slave container. Change into the `src/sonic-utilities/` directory
Expand All @@ -66,13 +66,20 @@ A convenient alternative is to let the SONiC build system configure a build envi
```
python3 setup.py bdist_wheel
```
Note: This command by default will not update the wheel package in target/. To specify the destination location of wheel package, use "-d" option.

#### To run unit tests

```
python3 setup.py test
```

#### To install the package on a SONiC machine
```
sudo pip uninstall sonic-utilities
sudo pip install YOUR_WHEEL_PACKAGE
```
Note: Don't use "--force-reinstall".

### sonic-utilities-data

Expand Down
17 changes: 17 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ variables:
value: $(Build.SourceBranchName)

stages:
- stage: Pretest
jobs:
- job: static_analysis
displayName: "Static Analysis"
timeoutInMinutes: 10
continueOnError: true
pool: sonic-ubuntu-1c
steps:
- template: .azure-pipelines/pre-commit-check.yml

- stage: Build

jobs:
Expand All @@ -36,6 +46,13 @@ stages:
image: sonicdev-microsoft.azurecr.io:443/sonic-slave-bullseye:$(BUILD_BRANCH)

steps:
- script: |
set -ex
sudo apt-get update
sudo apt-get install -y python3-pip
sudo pip3 install requests==2.31.0
displayName: "Install dependencies"
- script: |
sourceBranch=$(Build.SourceBranchName)
if [[ "$(Build.Reason)" == "PullRequest" ]];then
Expand Down
24 changes: 23 additions & 1 deletion clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import click
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util
from sonic_py_common import multi_asic
from sonic_py_common.general import getstatusoutput_noshell_pipe
from flow_counter_util.route import exit_if_route_flow_counter_not_support
from utilities_common import util_base
from show.plugins.pbh import read_pbh_counters
from config.plugins.pbh import serialize_pbh_counters
from . import plugins


# This is from the aliases example:
# https://github.com/pallets/click/blob/57c6f09611fc47ca80db0bd010f05998b3c0aa95/examples/aliases/aliases.py
class Config(object):
Expand Down Expand Up @@ -550,6 +550,28 @@ def route(prefix, vrf, namespace):
helper = util_base.UtilHelper()
helper.load_and_register_plugins(plugins, cli)

# ("sonic-clear asic-sdk-health-event")
@cli.command()
@click.option('--namespace', '-n', 'namespace', required=False, default=None, show_default=False,
help='Option needed for multi-asic only: provide namespace name',
type=click.Choice(multi_asic_util.multi_asic_ns_choices()))
@clicommon.pass_db
def asic_sdk_health_event(db, namespace):
"""Clear received ASIC/SDK health events"""
if multi_asic.get_num_asics() > 1:
namespace_list = multi_asic.get_namespaces_from_linux()
else:
namespace_list = [multi_asic.DEFAULT_NAMESPACE]

for ns in namespace_list:
if namespace and namespace != ns:
continue

state_db = db.db_clients[ns]
keys = state_db.keys(db.db.STATE_DB, "ASIC_SDK_HEALTH_EVENT_TABLE*")
for key in keys:
state_db.delete(state_db.STATE_DB, key);


if __name__ == '__main__':
cli()
8 changes: 4 additions & 4 deletions config/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def trace(option):


@click.command()
@click.argument('auth_protocol', nargs=-1, type=click.Choice(["radius", "tacacs+", "local", "default"]))
@click.argument('auth_protocol', nargs=-1, type=click.Choice(["ldap", "radius", "tacacs+", "local", "default"]))
def login(auth_protocol):
"""Switch login authentication [ {radius, tacacs+, local} | default ]"""
"""Switch login authentication [ {ldap, radius, tacacs+, local} | default ]"""
if len(auth_protocol) is 0:
click.echo('Argument "auth_protocol" is required')
return
Expand All @@ -135,9 +135,9 @@ def login(auth_protocol):
val2 = auth_protocol[1]
good_ap = False
if val == 'local':
if val2 == 'radius' or val2 == 'tacacs+':
if val2 == 'radius' or val2 == 'tacacs+' or val2 == 'ldap':
good_ap = True
elif val == 'radius' or val == 'tacacs+':
elif val == 'radius' or val == 'tacacs+' or val == 'ldap':
if val2 == 'local':
good_ap = True
if good_ap == True:
Expand Down
192 changes: 192 additions & 0 deletions config/bgp_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import click
import utilities_common.cli as clicommon

from sonic_py_common import logger
from utilities_common.bgp import (
CFG_BGP_DEVICE_GLOBAL,
BGP_DEVICE_GLOBAL_KEY,
SYSLOG_IDENTIFIER,
to_str,
)


log = logger.Logger(SYSLOG_IDENTIFIER)
log.set_min_log_priority_info()


#
# BGP DB interface ----------------------------------------------------------------------------------------------------
#


def update_entry_validated(db, table, key, data, create_if_not_exists=False):
""" Update entry in table and validate configuration.
If attribute value in data is None, the attribute is deleted.
Args:
db (swsscommon.ConfigDBConnector): Config DB connector object.
table (str): Table name to add new entry to.
key (Union[str, Tuple]): Key name in the table.
data (Dict): Entry data.
create_if_not_exists (bool):
In case entry does not exists already a new entry
is not created if this flag is set to False and
creates a new entry if flag is set to True.
Raises:
Exception: when cfg does not satisfy YANG schema.
"""

cfg = db.get_config()
cfg.setdefault(table, {})

if not data:
raise click.ClickException(f"No field/values to update {key}")

if create_if_not_exists:
cfg[table].setdefault(key, {})

if key not in cfg[table]:
raise click.ClickException(f"{key} does not exist")

entry_changed = False
for attr, value in data.items():
if value == cfg[table][key].get(attr):
continue
entry_changed = True
if value is None:
cfg[table][key].pop(attr, None)
else:
cfg[table][key][attr] = value

if not entry_changed:
return

db.set_entry(table, key, cfg[table][key])


#
# BGP handlers --------------------------------------------------------------------------------------------------------
#


def tsa_handler(ctx, db, state):
""" Handle config updates for Traffic-Shift-Away (TSA) feature """

table = CFG_BGP_DEVICE_GLOBAL
key = BGP_DEVICE_GLOBAL_KEY
data = {
"tsa_enabled": state,
}

try:
update_entry_validated(db.cfgdb, table, key, data, create_if_not_exists=True)
log.log_notice("Configured TSA state: {}".format(to_str(state)))
except Exception as e:
log.log_error("Failed to configure TSA state: {}".format(str(e)))
ctx.fail(str(e))


def wcmp_handler(ctx, db, state):
""" Handle config updates for Weighted-Cost Multi-Path (W-ECMP) feature """

table = CFG_BGP_DEVICE_GLOBAL
key = BGP_DEVICE_GLOBAL_KEY
data = {
"wcmp_enabled": state,
}

try:
update_entry_validated(db.cfgdb, table, key, data, create_if_not_exists=True)
log.log_notice("Configured W-ECMP state: {}".format(to_str(state)))
except Exception as e:
log.log_error("Failed to configure W-ECMP state: {}".format(str(e)))
ctx.fail(str(e))


#
# BGP device-global ---------------------------------------------------------------------------------------------------
#


@click.group(
name="device-global",
cls=clicommon.AliasedGroup
)
def DEVICE_GLOBAL():
""" Configure BGP device global state """

pass


#
# BGP device-global tsa -----------------------------------------------------------------------------------------------
#


@DEVICE_GLOBAL.group(
name="tsa",
cls=clicommon.AliasedGroup
)
def DEVICE_GLOBAL_TSA():
""" Configure Traffic-Shift-Away (TSA) feature """

pass


@DEVICE_GLOBAL_TSA.command(
name="enabled"
)
@clicommon.pass_db
@click.pass_context
def DEVICE_GLOBAL_TSA_ENABLED(ctx, db):
""" Enable Traffic-Shift-Away (TSA) feature """

tsa_handler(ctx, db, "true")


@DEVICE_GLOBAL_TSA.command(
name="disabled"
)
@clicommon.pass_db
@click.pass_context
def DEVICE_GLOBAL_TSA_DISABLED(ctx, db):
""" Disable Traffic-Shift-Away (TSA) feature """

tsa_handler(ctx, db, "false")


#
# BGP device-global w-ecmp --------------------------------------------------------------------------------------------
#


@DEVICE_GLOBAL.group(
name="w-ecmp",
cls=clicommon.AliasedGroup
)
def DEVICE_GLOBAL_WCMP():
""" Configure Weighted-Cost Multi-Path (W-ECMP) feature """

pass


@DEVICE_GLOBAL_WCMP.command(
name="enabled"
)
@clicommon.pass_db
@click.pass_context
def DEVICE_GLOBAL_WCMP_ENABLED(ctx, db):
""" Enable Weighted-Cost Multi-Path (W-ECMP) feature """

wcmp_handler(ctx, db, "true")


@DEVICE_GLOBAL_WCMP.command(
name="disabled"
)
@clicommon.pass_db
@click.pass_context
def DEVICE_GLOBAL_WCMP_DISABLED(ctx, db):
""" Disable Weighted-Cost Multi-Path (W-ECMP) feature """

wcmp_handler(ctx, db, "false")
Loading

0 comments on commit 3ddcc9c

Please sign in to comment.