Skip to content

Commit dd2ec2c

Browse files
Fix bmpcfgd daemon integration bug (sonic-net#20922)
Why I did it Fix bmpcfgd daemon integration bug Work item tracking Microsoft ADO (number only):27511095 How I did it updated corresponding script code. How to verify it Verified on DUT, bmpcfgd observes config db and behave as expected, with syslog output.
1 parent 24fb3e1 commit dd2ec2c

File tree

5 files changed

+34
-53
lines changed

5 files changed

+34
-53
lines changed

rules/docker-bmp.mk

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ $(DOCKER_BMP)_PATH = $(DOCKERS_PATH)/$(DOCKER_BMP_STEM)
99
$(DOCKER_BMP)_DEPENDS += $(LIBSWSSCOMMON) \
1010
$(SONIC_BMPD)
1111

12-
$(DOCKER_BMP)_INSTALL_PYTHON_WHEELS = $(SONIC_BMPCFGD) \
13-
$(SONIC_UTILITIES_PY3)
12+
$(DOCKER_BMP)_PYTHON_WHEELS = $(SONIC_BMPCFGD)
1413
$(DOCKER_BMP)_INSTALL_DEBS = $(LIBSWSSCOMMON) \
1514
$(SONIC_BMPD) \
1615
$(PYTHON3_SWSSCOMMON) \
File renamed without changes.

src/sonic-bmpcfgd/scripts/bmpcfgd src/sonic-bmpcfgd/bmpcfgd/bmpcfgd.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import signal
1212
from shutil import copy2
1313
from datetime import datetime
14-
from sonic_py_common import device_info
14+
from sonic_py_common import logger
1515
from sonic_py_common.general import check_output_pipe
1616
from swsscommon.swsscommon import ConfigDBConnector, DBConnector, Table
1717
from swsscommon import swsscommon
@@ -22,6 +22,7 @@
2222
REDIS_HOSTIP = "127.0.0.1"
2323
BMP_TABLE = "BMP"
2424
SYSLOG_IDENTIFIER = "bmpcfgd"
25+
logger = logger.Logger(SYSLOG_IDENTIFIER)
2526

2627
def is_true(val):
2728
return str(val).lower() == 'true'
@@ -40,7 +41,7 @@ def load(self, data={}):
4041
self.bgp_neighbor_table = is_true(common_config.get('bgp_neighbor_table', 'false'))
4142
self.bgp_rib_in_table = is_true(common_config.get('bgp_rib_in_table', 'false'))
4243
self.bgp_rib_out_table = is_true(common_config.get('bgp_rib_out_table', 'false'))
43-
self.log_info(f'BMPCfg: update : {self.bgp_neighbor_table}, {self.bgp_rib_in_table}, {self.bgp_rib_out_table}')
44+
logger.log_notice(f'bmpcfgd: config update : {self.bgp_neighbor_table}, {self.bgp_rib_in_table}, {self.bgp_rib_out_table}')
4445

4546
# reset bmp table state once config is changed.
4647
self.stop_bmp()
@@ -53,20 +54,20 @@ def cfg_handler(self, data):
5354

5455

5556
def stop_bmp(self):
56-
self.log_info('BMPCfg: stop bmp daemon')
57-
subprocess.call(["supervisorctl", "stop", "openbmpd"])
57+
logger.log_notice('bmpcfgd: stop bmp daemon')
58+
subprocess.call(["supervisorctl", "stop", "sonic-bmp:openbmpd"])
5859

5960

6061
def reset_bmp_table(self):
61-
self.log_info('BMPCfg: Reset bmp table from state_db')
62+
logger.log_notice('bmpcfgd: Reset bmp table from state_db')
6263
self.state_db_conn.delete_all_by_pattern(BMP_STATE_DB, 'BGP_NEIGHBOR*')
6364
self.state_db_conn.delete_all_by_pattern(BMP_STATE_DB, 'BGP_RIB_IN_TABLE*')
6465
self.state_db_conn.delete_all_by_pattern(BMP_STATE_DB, 'BGP_RIB_OUT_TABLE*')
6566

6667

6768
def start_bmp(self):
68-
self.log_info('BMPCfg: start bmp daemon')
69-
subprocess.call(["supervisorctl", "start", "openbmpd"])
69+
logger.log_notice('bmpcfgd: start bmp daemon')
70+
subprocess.call(["supervisorctl", "start", "sonic-bmp:openbmpd"])
7071

7172

7273
class BMPCfgDaemon:
@@ -77,14 +78,15 @@ def __init__(self):
7778
self.config_db.connect(wait_for_init=True, retry_on=True)
7879
self.bmpcfg = BMPCfg(self.state_db_conn)
7980

80-
def bmp_handler(self, key, op, data):
81+
def bmp_handler(self, key, data):
8182
data = self.config_db.get_table(BMP_TABLE)
8283
self.bmpcfg.cfg_handler(data)
8384

8485
def register_callbacks(self):
8586
self.config_db.subscribe(BMP_TABLE,
8687
lambda table, key, data:
87-
self.bmp_handler(key, op, data))
88+
self.bmp_handler(key, data))
89+
self.config_db.listen(init_data_handler=self.bmpcfg.load)
8890

8991
def main():
9092
daemon = BMPCfgDaemon()

src/sonic-bmpcfgd/setup.py

+11-31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from __future__ import print_function
2-
import sys
3-
from setuptools import setup
4-
import pkg_resources
5-
from packaging import version
1+
import setuptools
62

7-
setup(
3+
4+
dependencies = [
5+
'sonic_py_common',
6+
]
7+
8+
setuptools.setup(
89
name = 'sonic-bmpcfgd-services',
910
version = '1.0',
1011
description = 'Python services which run in the bmp container',
@@ -14,8 +15,9 @@
1415
url = 'https://github.com/Azure/sonic-buildimage',
1516
maintainer = 'Feng Pan',
1617
maintainer_email = 'fenpan@microsoft.com',
17-
scripts = [
18-
'scripts/bmpcfgd'
18+
packages=[
19+
'bmpcfgd',
20+
'tests'
1921
],
2022
install_requires = [
2123
'jinja2>=2.10',
@@ -25,7 +27,7 @@
2527
],
2628
entry_points={
2729
'console_scripts': [
28-
'bmpcfgd = scripts.bmpcfgd:main',
30+
'bmpcfgd = bmpcfgd.bmpcfgd:main',
2931
]
3032
},
3133
setup_requires = [
@@ -39,26 +41,4 @@
3941
'sonic-py-common',
4042
'pytest-cov'
4143
],
42-
extras_require = {
43-
"testing": [
44-
'parameterized',
45-
'pytest',
46-
'pyfakefs',
47-
'sonic-py-common'
48-
]
49-
},
50-
classifiers = [
51-
'Development Status :: 3 - Alpha',
52-
'Environment :: Console',
53-
'Intended Audience :: Developers',
54-
'Intended Audience :: Information Technology',
55-
'Intended Audience :: System Administrators',
56-
'License :: OSI Approved :: Apache Software License',
57-
'Natural Language :: English',
58-
'Operating System :: POSIX :: Linux',
59-
'Programming Language :: Python :: 3.7',
60-
'Topic :: System',
61-
],
62-
keywords = 'SONiC bmp config daemon',
63-
test_suite = 'setup.get_test_suite'
6444
)

src/sonic-bmpcfgd/tests/bmpcfgd_test.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
test_path = os.path.dirname(os.path.abspath(__file__))
2121
modules_path = os.path.dirname(test_path)
22-
scripts_path = os.path.join(modules_path, "scripts")
22+
scripts_path = os.path.join(modules_path, "bmpcfgd")
2323
sys.path.insert(0, modules_path)
2424

2525
# Load the file under test
26-
bmpcfgd_path = os.path.join(scripts_path, 'bmpcfgd')
26+
bmpcfgd_path = os.path.join(scripts_path, 'bmpcfgd.py')
2727
bmpcfgd = load_module_from_source('bmpcfgd', bmpcfgd_path)
2828

2929

@@ -51,10 +51,10 @@ def test_bmpcfgd_neighbor_enable(self, mock_call, mock_log_info):
5151
MockConfigDb.set_config_db(self.test_data)
5252
bmp_config_daemon = bmpcfgd.BMPCfgDaemon()
5353
bmp_config_daemon.register_callbacks()
54-
bmp_config_daemon.bmp_handler("BMP", '', self.test_data)
54+
bmp_config_daemon.bmp_handler("BMP", self.test_data)
5555
expected_calls = [
56-
mock.call(["supervisorctl", "stop", "openbmpd"]),
57-
mock.call(["supervisorctl", "start", "openbmpd"])
56+
mock.call(["supervisorctl", "stop", "sonic-bmp:openbmpd"]),
57+
mock.call(["supervisorctl", "start", "sonic-bmp:openbmpd"])
5858
]
5959
mock_log_info.assert_has_calls(expected_calls)
6060

@@ -64,10 +64,10 @@ def test_bmpcfgd_bgp_rib_in_enable(self, mock_call, mock_log_info):
6464
self.test_data['BMP']['table']['bgp_rib_in_table'] = 'true'
6565
MockConfigDb.set_config_db(self.test_data)
6666
bmp_config_daemon = bmpcfgd.BMPCfgDaemon()
67-
bmp_config_daemon.bmp_handler("BMP", '', self.test_data)
67+
bmp_config_daemon.bmp_handler("BMP", self.test_data)
6868
expected_calls = [
69-
mock.call(["supervisorctl", "stop", "openbmpd"]),
70-
mock.call(["supervisorctl", "start", "openbmpd"])
69+
mock.call(["supervisorctl", "stop", "sonic-bmp:openbmpd"]),
70+
mock.call(["supervisorctl", "start", "sonic-bmp:openbmpd"])
7171
]
7272
mock_log_info.assert_has_calls(expected_calls)
7373

@@ -77,9 +77,9 @@ def test_bmpcfgd_bgp_rib_out_enable(self, mock_call, mock_log_info):
7777
self.test_data['BMP']['table']['bgp_rib_out_table'] = 'true'
7878
MockConfigDb.set_config_db(self.test_data)
7979
bmp_config_daemon = bmpcfgd.BMPCfgDaemon()
80-
bmp_config_daemon.bmp_handler("BMP", '', self.test_data)
80+
bmp_config_daemon.bmp_handler("BMP", self.test_data)
8181
expected_calls = [
82-
mock.call(["supervisorctl", "stop", "openbmpd"]),
83-
mock.call(["supervisorctl", "start", "openbmpd"])
82+
mock.call(["supervisorctl", "stop", "sonic-bmp:openbmpd"]),
83+
mock.call(["supervisorctl", "start", "sonic-bmp:openbmpd"])
8484
]
8585
mock_log_info.assert_has_calls(expected_calls)

0 commit comments

Comments
 (0)