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

Not4Review #3325

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
150 changes: 150 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4038,6 +4038,156 @@ def del_user(db, user):
click.echo("Restart service snmp failed with error {}".format(e))
raise click.Abort()


#
# 'bmp' group ('config bmp ...')
#
@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 """


#
# 'bgp-neighbor-table' command ('config bmp enable bgp-neighbor-table')
#
@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()
bmp_table = config_db.get_table('BMP')
if not bmp_table:
bmp_table = {'table': {'bgp_neighbor_table': 'true'}}
else:
bmp_table['table']['bgp_neighbor_table'] = 'true'
config_db.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')
@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()
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'])


#
# '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()
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'])


#
# '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()
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'])


#
# '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()
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'])


#
# '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()
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'])


#
# '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": {
}
}
}
163 changes: 163 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import shutil
from unittest import mock
from jsonpatch import JsonPatchConflict
from importlib import reload

import click
from click.testing import CliRunner
Expand All @@ -38,6 +39,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 @@ -635,6 +639,165 @@ def teardown_class(cls):
dbconnector.load_namespace_config()


class TestBMPConfig(object):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ['UTILITIES_UNIT_TESTING'] = "1"
import config.main as config
reload(config)
yield
print("TEARDOWN")
os.environ["UTILITIES_UNIT_TESTING"] = "0"
from .mock_tables import dbconnector
dbconnector.dedicated_dbs = {}

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")
from .mock_tables import dbconnector
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'):
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_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")
from .mock_tables import dbconnector
dbconnector.dedicated_dbs['CONFIG_DB'] = jsonfile_config

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

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

# bmp disable bgp-neighbor-table
with mock.patch('utilities_common.cli.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, "bmp_invalid.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'):
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_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")
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 first
with mock.patch('utilities_common.cli.run_command'):
result = runner.invoke(config.config.commands["bmp"],
["enable", "bgp-rib-in-table"], obj=obj)
assert result.exit_code == 0

# bmp disable bgp-rib-in-table
with mock.patch('utilities_common.cli.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, "bmp_invalid.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'):
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_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")
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 first
with mock.patch('utilities_common.cli.run_command'):
result = runner.invoke(config.config.commands["bmp"],
["enable", "bgp-rib-out-table"], obj=obj)
assert result.exit_code == 0

# bmp disable bgp-rib-out-table
with mock.patch('utilities_common.cli.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


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