-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sonic-net:master' into master
- Loading branch information
Showing
180 changed files
with
14,260 additions
and
2,462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Oops, something went wrong.