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 7 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
166 changes: 166 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3916,6 +3916,172 @@ 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()
@click.pass_context
def bmp(ctx):
"""BMP-related configuration"""

#
# 'enable' subgroup ('config bmp enable ...')
#
@bmp.group()
@click.pass_context
def enable(ctx):
"""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')
@click.pass_context
def enable_bgp_neighbor_table(ctx):
"""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...")
config_db = ConfigDBConnector()
config_db.connect()
try:
bmp_table = config_db.get_table('BMP')
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
if not bmp_table:
bmp_table = {'table': {'bgp_neighbor_table': 'true'}}
else:
bmp_table['table']['bgp_neighbor_table'] = 'true'
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved

config_db.mod_entry('BMP', 'table', bmp_table['table'])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved



#
# 'bgp-rib-out-table' command ('config bmp enable bgp-rib-out-table')
#
@enable.command('bgp-rib-out-table')
@click.pass_context
def enable_bgp_rib_out_table(ctx):
"""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...")
config_db = ConfigDBConnector()
config_db.connect()
try:
bmp_table = config_db.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_out_table': 'true'}}
else:
bmp_table['table']['bgp_rib_out_table'] = 'true'

config_db.mod_entry('BMP', 'table', bmp_table['table'])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))

#
# 'bgp-rib-in-table' command ('config bmp enable bgp-rib-in-table')
#
@enable.command('bgp-rib-in-table')
@click.pass_context
def enable_bgp_rib_in_table(ctx):
"""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...")
config_db = ConfigDBConnector()
config_db.connect()
try:
bmp_table = config_db.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_in_table': 'true'}}
else:
bmp_table['table']['bgp_rib_in_table'] = 'true'

config_db.mod_entry('BMP', 'table', bmp_table['table'])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))

#
# 'disable' subgroup ('config bmp disable ...')
#
@bmp.group()
@click.pass_context
def disable(ctx):
"""Disable BMP table dump """

#
# 'bgp-neighbor-table' command ('config bmp disable bgp-neighbor-table')
#
@disable.command('bgp-neighbor-table')
@click.pass_context
def disable_bgp_neighbor_table(ctx):
"""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...")
config_db = ConfigDBConnector()
config_db.connect()
try:
bmp_table = config_db.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_neighbor_table': 'false'}}
else:
bmp_table['table']['bgp_neighbor_table'] = 'false'

config_db.mod_entry('BMP', 'table', bmp_table['table'])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))

#
# 'bgp-rib-out-table' command ('config bmp disable bgp-rib-out-table')
#
@disable.command('bgp-rib-out-table')
@click.pass_context
def diable_bgp_rib_out_table(ctx):
"""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...")
config_db = ConfigDBConnector()
config_db.connect()
try:
bmp_table = config_db.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_out_table': 'false'}}
else:
bmp_table['table']['bgp_rib_out_table'] = 'false'

config_db.mod_entry('BMP', 'table', bmp_table['table'])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))


#
# 'bgp-rib-in-table' command ('config bmp disable bgp-rib-in-table')
#
@disable.command('bgp-rib-in-table')
@click.pass_context
def disable_bgp_rib_in_table(ctx):
"""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...")
config_db = ConfigDBConnector()
config_db.connect()
try:
bmp_table = config_db.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_rib_in_table': 'false'}}
else:
bmp_table['table']['bgp_rib_in_table'] = 'false'

config_db.mod_entry('BMP', 'table', bmp_table['table'])
except ValueError as e:
ctx.fail("Invalid ConfigDB. Error: {}".format(e))

#
# 'bgp' group ('config bgp ...')
#
Expand Down
144 changes: 144 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 @@ -392,6 +395,147 @@ def teardown_class(cls):
dbconnector.load_namespace_config()


class TestBMPConfig(object):
@classmethod
def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "1"
print("SETUP")
import config.main
importlib.reload(config.main)

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, "config_db.json")
from .mock_tables import dbconnector
FengPan-Frank marked this conversation as resolved.
Show resolved Hide resolved
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

runner = CliRunner()
db = Db()
obj = {'config_db': db.cfgdb}

# bmp enable bgp-neighbor-table
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
result = runner.invoke(config.config.commands["bmp"],
["enable", "bgp-neighbor-table"], obj=obj)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_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, "config_db.json")
from .mock_tables import dbconnector
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

runner = CliRunner()
db = Db()
obj = {'config_db': db.cfgdb}

# bmp disable bgp-neighbor-table
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
result = runner.invoke(config.config.commands["bmp"],
["disable", "bgp-neighbor-table"], obj=obj)
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, "config_db.json")
from .mock_tables import dbconnector
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

runner = CliRunner()
db = Db()
obj = {'config_db': db.cfgdb}

# bmp enable bgp-rib-in-table
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
result = runner.invoke(config.config.commands["bmp"],
["enable", "bgp-rib-in-table"], obj=obj)
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, "config_db.json")
from .mock_tables import dbconnector
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

runner = CliRunner()
db = Db()
obj = {'config_db': db.cfgdb}

# bmp disable bgp-rib-in-table
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
result = runner.invoke(config.config.commands["bmp"],
["disable", "bgp-rib-in-table"], obj=obj)
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, "config_db.json")
from .mock_tables import dbconnector
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

runner = CliRunner()
db = Db()
obj = {'config_db': db.cfgdb}

# bmp enable bgp-rib-out-table
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
result = runner.invoke(config.config.commands["bmp"],
["enable", "bgp-rib-out-table"], obj=obj)
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, "config_db.json")
from .mock_tables import dbconnector
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

runner = CliRunner()
db = Db()
obj = {'config_db': db.cfgdb}

# bmp disable bgp-rib-out-table
with mock.patch('utilities_common.cli.run_command') as mock_run_command:
result = runner.invoke(config.config.commands["bmp"],
["disable", "bgp-rib-out-table"], obj=obj)
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
from .mock_tables import dbconnector
dbconnector.dedicated_dbs = {}
print("TEARDOWN")

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