Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into dev-reset-local-users-password
Browse files Browse the repository at this point in the history
  • Loading branch information
azmy98 authored Aug 12, 2024
2 parents 039db9d + 317e649 commit f0f87ad
Show file tree
Hide file tree
Showing 116 changed files with 6,997 additions and 990 deletions.
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
9 changes: 8 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ stages:
displayName: "Static Analysis"
timeoutInMinutes: 10
continueOnError: true
pool: ubuntu-20.04
pool: sonic-ubuntu-1c
steps:
- template: .azure-pipelines/pre-commit-check.yml

Expand All @@ -46,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
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 f0f87ad

Please sign in to comment.