Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI for bmp configdb entity Enable/Disable #3286

Merged
merged 46 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a6f8234
Add CLI for bmp configdb entity Enable/Disable.
FengPan-Frank Apr 23, 2024
7e2e40a
Add CLI for bmp configdb entity Enable/Disable.
FengPan-Frank Apr 23, 2024
18a1b04
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Apr 23, 2024
5b33d4e
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Apr 23, 2024
25e7a7c
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Apr 24, 2024
c6217eb
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Apr 24, 2024
50efcde
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Apr 24, 2024
5130d7e
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-utili…
FengPan-Frank May 16, 2024
00c522e
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-utili…
FengPan-Frank May 16, 2024
949a1e4
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
53daa5d
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
77cd856
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
4d94ba7
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
a4051e0
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
5564051
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
6522777
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
6a8d5bb
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
a7f90d0
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
121bcb8
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
9491efd
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
3884cb4
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 16, 2024
f2e4139
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 21, 2024
4000679
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 21, 2024
672a4b2
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 21, 2024
083c39d
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-utili…
FengPan-Frank May 22, 2024
2840a53
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-utili…
FengPan-Frank May 23, 2024
4a541d0
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-utili…
FengPan-Frank May 23, 2024
318be3b
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 23, 2024
a75d05e
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 23, 2024
1ff4925
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 23, 2024
b9e7b6d
Merge branch 'sonic-net:master' into bmpcli_cfg
FengPan-Frank May 24, 2024
7de7e79
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-utili…
FengPan-Frank May 24, 2024
b902345
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 24, 2024
a049e8e
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 24, 2024
56ec7a7
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 28, 2024
95dcffe
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 28, 2024
b9542e4
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 29, 2024
e4cd104
Merge branch 'sonic-net:master' into bmpcli_cfg
FengPan-Frank Jun 6, 2024
6f9e926
Merge branch 'master' into bmpcli_cfg
FengPan-Frank Aug 29, 2024
61f1780
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank May 29, 2024
2d3497f
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Aug 29, 2024
5dec52d
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Aug 29, 2024
c915444
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Sep 5, 2024
aad6646
Use pytest.mark.parametrize to reduce duplicated code
FengPan-Frank Oct 25, 2024
1469779
Use pytest.mark.parametrize to reduce duplicated code
FengPan-Frank Oct 25, 2024
d8f4538
Merge branch 'bmpcli_cfg' of https://github.com/FengPan-Frank/sonic-u…
FengPan-Frank Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4191,6 +4191,105 @@ def del_user(db, user):
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()


#
# 'bmp' group ('config bmp ...')
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
#
@config.group()
@clicommon.pass_db
def bmp(db):
"""BMP-related configuration"""
pass


#
# common function to update bmp config table
#
@clicommon.pass_db
def update_bmp_table(db, table_name, value):
log.log_info(f"'bmp {value} {table_name}' executing...")
bmp_table = db.cfgdb.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {table_name: value}}
else:
bmp_table['table'][table_name] = value
db.cfgdb.mod_entry('BMP', 'table', bmp_table['table'])


#
# 'enable' subgroup ('config bmp enable ...')
#
@bmp.group()
@clicommon.pass_db
def enable(db):
"""Enable BMP table dump """
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
pass


#
# 'bgp-neighbor-table' command ('config bmp enable bgp-neighbor-table')
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
#
@enable.command('bgp-neighbor-table')
@clicommon.pass_db
def enable_bgp_neighbor_table(db):
update_bmp_table('bgp_neighbor_table', 'true')


#
# 'bgp-rib-out-table' command ('config bmp enable bgp-rib-out-table')
#
@enable.command('bgp-rib-out-table')
@clicommon.pass_db
def enable_bgp_rib_out_table(db):
update_bmp_table('bgp_rib_out_table', 'true')


#
# 'bgp-rib-in-table' command ('config bmp enable bgp-rib-in-table')
#
@enable.command('bgp-rib-in-table')
@clicommon.pass_db
def enable_bgp_rib_in_table(db):
update_bmp_table('bgp_rib_in_table', 'true')


#
# 'disable' subgroup ('config bmp disable ...')
#
@bmp.group()
@clicommon.pass_db
def disable(db):
"""Disable BMP table dump """
pass


#
# 'bgp-neighbor-table' command ('config bmp disable bgp-neighbor-table')
#
@disable.command('bgp-neighbor-table')
@clicommon.pass_db
def disable_bgp_neighbor_table(db):
update_bmp_table('bgp_neighbor_table', 'false')


#
# 'bgp-rib-out-table' command ('config bmp disable bgp-rib-out-table')
#
@disable.command('bgp-rib-out-table')
@clicommon.pass_db
def diable_bgp_rib_out_table(db):
update_bmp_table('bgp_rib_out_table', 'false')


#
# 'bgp-rib-in-table' command ('config bmp disable bgp-rib-in-table')
#
@disable.command('bgp-rib-in-table')
@clicommon.pass_db
def disable_bgp_rib_in_table(db):
update_bmp_table('bgp_rib_in_table', 'false')


#
# 'bgp' group ('config bgp ...')
#
Expand Down
9 changes: 9 additions & 0 deletions tests/bmp_input/bmp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"BMP": {
"table": {
"bgp_neighbor_table": "false",
"bgp_rib_in_table": "false",
"bgp_rib_out_table": "false"
}
}
}
6 changes: 6 additions & 0 deletions tests/bmp_input/bmp_invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"BMP": {
"table": {
}
}
}
48 changes: 48 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
# Config Reload input Path
mock_db_path = os.path.join(test_path, "config_reload_input")

mock_bmp_db_path = os.path.join(test_path, "bmp_input")


# Load minigraph input Path
load_minigraph_input_path = os.path.join(test_path, "load_minigraph_input")
load_minigraph_platform_path = os.path.join(load_minigraph_input_path, "platform")
Expand Down Expand Up @@ -702,6 +705,51 @@ def teardown_class(cls):
dbconnector.load_namespace_config()


class TestBMPConfig(object):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ['UTILITIES_UNIT_TESTING'] = "1"
yield
print("TEARDOWN")
os.environ["UTILITIES_UNIT_TESTING"] = "0"

@pytest.mark.parametrize("table_name", [
"bgp-neighbor-table",
"bgp-rib-in-table",
"bgp-rib-out-table"
])
@pytest.mark.parametrize("enabled", ["true", "false"])
@pytest.mark.parametrize("filename", ["bmp_invalid.json", "bmp.json"])
def test_enable_disable_table(
self,
get_cmd_module,
setup_single_broadcom_asic,
table_name,
enabled,
filename):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, filename)
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# Enable table
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
[table_name], obj=db)
assert result.exit_code == 0

# Disable table
result = runner.invoke(config.config.commands["bmp"].commands["disable"],
[table_name], obj=db)
assert result.exit_code == 0

# Enable table again
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
[table_name], obj=db)
assert result.exit_code == 0


class TestConfigReloadMasic(object):
@classmethod
def setup_class(cls):
Expand Down
Loading