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 39 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
136 changes: 136 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4191,6 +4191,142 @@ 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"""


#
# '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


#
# '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):
"""enable bgp-neighbor-table sessions
In the case of Multi-Asic platform, corresponding database instance of neighbor will be operated.
"""
log.log_info("'bmp enable bgp-neighbor-table' executing...")
bmp_table = db.cfgdb.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_neighbor_table': 'true'}}
else:
bmp_table['table']['bgp_neighbor_table'] = 'true'
db.cfgdb.mod_entry('BMP', 'table', bmp_table['table'])


#
# '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):
"""enable bgp-rib-out-table sessions
In the case of Multi-Asic platform, corresponding database instance of neighbor will be operated.
"""
log.log_info("'bmp enable bgp-rib-out-table' executing...")
bmp_table = db.cfgdb.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_out_table': 'true'}}
else:
bmp_table['table']['bgp_rib_out_table'] = 'true'
db.cfgdb.mod_entry('BMP', 'table', bmp_table['table'])


#
# '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):
"""enable bgp-rib-in-table sessions
In the case of Multi-Asic platform, corresponding database instance of neighbor will be operated.
"""
log.log_info("'bmp enable bgp-rib-in-table' executing...")
bmp_table = db.cfgdb.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_in_table': 'true'}}
else:
bmp_table['table']['bgp_rib_in_table'] = 'true'
db.cfgdb.mod_entry('BMP', 'table', bmp_table['table'])


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


#
# 'bgp-neighbor-table' command ('config bmp disable bgp-neighbor-table')
#
@disable.command('bgp-neighbor-table')
@clicommon.pass_db
def disable_bgp_neighbor_table(db):
"""disable bgp-neighbor-table sessions
In the case of Multi-Asic platform, corresponding database instance of neighbor will be operated.
"""
log.log_info("'bmp disable bgp-neighbor-table' executing...")
bmp_table = db.cfgdb.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_neighbor_table': 'false'}}
else:
bmp_table['table']['bgp_neighbor_table'] = 'false'
db.cfgdb.mod_entry('BMP', 'table', bmp_table['table'])


#
# '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):
"""disable bgp-rib-out-table sessions
In the case of Multi-Asic platform, corresponding database instance of neighbor will be operated.
"""
log.log_info("'bmp disable bgp-rib-out-table' executing...")
bmp_table = db.cfgdb.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_out_table': 'false'}}
else:
bmp_table['table']['bgp_rib_out_table'] = 'false'
db.cfgdb.mod_entry('BMP', 'table', bmp_table['table'])


#
# '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):
"""disable bgp-rib-in-table sessions
In the case of Multi-Asic platform, corresponding database instance of neighbor will be operated.
"""
log.log_info("'bmp disable bgp-rib-in-table' executing...")
bmp_table = db.cfgdb.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_in_table': 'false'}}
else:
bmp_table['table']['bgp_rib_in_table'] = 'false'
db.cfgdb.mod_entry('BMP', 'table', bmp_table['table'])


#
# '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": {
}
}
}
197 changes: 197 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,200 @@ 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"

def test_disable_bgp_neighbor_table(
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp_invalid.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp disable bgp-neighbor-table
result = runner.invoke(config.config.commands["bmp"].commands["disable"],
["bgp-neighbor-table"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_disable_bgp_rib_in_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp_invalid.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp disable bgp-rib-in-table
result = runner.invoke(config.config.commands["bmp"].commands["disable"],
["bgp-rib-in-table"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_disable_bgp_rib_out_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp_invalid.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp disable bgp-rib-out-table
result = runner.invoke(config.config.commands["bmp"].commands["disable"],
["bgp-rib-out-table"], obj=db)

print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_enable_bgp_neighbor_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp_invalid.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp enable bgp-neighbor-table
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-neighbor-table"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_enable_bgp_rib_in_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp_invalid.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp enable bgp-rib-in-table
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-rib-in-table"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_enable_bgp_rib_out_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp_invalid.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp enable bgp-rib-out-table
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-rib-out-table"], obj=db)

print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_enable_disable_bgp_neighbor_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp enable bgp-neighbor-table first
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-neighbor-table"], obj=db)
assert result.exit_code == 0

# bmp disable bgp-neighbor-table
result = runner.invoke(config.config.commands["bmp"].commands["disable"],
["bgp-neighbor-table"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

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

def test_enable_disable_bgp_rib_in_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp enable bgp-rib-in-table first
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-rib-in-table"], obj=db)
assert result.exit_code == 0

# bmp disable bgp-rib-in-table
result = runner.invoke(config.config.commands["bmp"].commands["disable"],
["bgp-rib-in-table"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

# bmp enable bgp-rib-in-table first
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-rib-in-table"], obj=db)
assert result.exit_code == 0

def test_enable_disable_bgp_rib_out_table(
self,
get_cmd_module,
setup_single_broadcom_asic):
(config, show) = get_cmd_module
jsonfile_config = os.path.join(mock_bmp_db_path, "bmp.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config
runner = CliRunner()
db = Db()

# bmp enable bgp-rib-out-table first
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-rib-out-table"], obj=db)
assert result.exit_code == 0

# bmp disable bgp-rib-out-table
result = runner.invoke(config.config.commands["bmp"].commands["disable"],
["bgp-rib-out-table"], obj=db)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

# bmp enable bgp-rib-out-table first
result = runner.invoke(config.config.commands["bmp"].commands["enable"],
["bgp-rib-out-table"], obj=db)
assert result.exit_code == 0

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