From 0d863c39acb03dcd0310a9ce483bb3b8a1f0c5a5 Mon Sep 17 00:00:00 2001 From: pavel-shirshov Date: Sat, 20 Jun 2020 21:01:24 -0700 Subject: [PATCH] [bgpcfgd]: make a package for bgpcfgd (#4813) --- dockers/docker-fpm-frr/Dockerfile.j2 | 12 ++++++++++-- dockers/docker-fpm-frr/base_image_files/monit_bgp | 2 +- .../frr/supervisord/supervisord.conf.j2 | 2 +- rules/docker-fpm-frr.mk | 1 + rules/sonic_bgpcfgd.dep | 10 ++++++++++ rules/sonic_bgpcfgd.mk | 7 +++++++ src/sonic-bgpcfgd/.gitignore | 6 ++++++ .../docker-fpm-frr => src/sonic-bgpcfgd}/bgpcfgd | 0 src/sonic-bgpcfgd/setup.cfg | 5 +++++ src/sonic-bgpcfgd/setup.py | 14 ++++++++++++++ src/sonic-bgpcfgd/tests/__init__.py | 0 src/sonic-bgpcfgd/tests/test_sample.py | 4 ++++ 12 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 rules/sonic_bgpcfgd.dep create mode 100644 rules/sonic_bgpcfgd.mk create mode 100644 src/sonic-bgpcfgd/.gitignore rename {dockers/docker-fpm-frr => src/sonic-bgpcfgd}/bgpcfgd (100%) create mode 100644 src/sonic-bgpcfgd/setup.cfg create mode 100755 src/sonic-bgpcfgd/setup.py create mode 100644 src/sonic-bgpcfgd/tests/__init__.py create mode 100644 src/sonic-bgpcfgd/tests/test_sample.py diff --git a/dockers/docker-fpm-frr/Dockerfile.j2 b/dockers/docker-fpm-frr/Dockerfile.j2 index 9499cc1ed5..38bef392e5 100644 --- a/dockers/docker-fpm-frr/Dockerfile.j2 +++ b/dockers/docker-fpm-frr/Dockerfile.j2 @@ -31,16 +31,24 @@ RUN useradd -u ${frr_user_uid} -g ${frr_user_gid} -M -s /bin/false frr {{ install_debian_packages(docker_fpm_frr_debs.split(' ')) }} {%- endif %} +{% if docker_fpm_frr_whls.strip() %} +# Copy locally-built Python wheel dependencies +{{ copy_files("python-wheels/", docker_fpm_frr_whls.split(' '), "/python-wheels/") }} + +# Install locally-built Python wheel dependencies +{{ install_python_wheels(docker_fpm_frr_whls.split(' ')) }} +{% endif %} + RUN chown -R ${frr_user_uid}:${frr_user_gid} /etc/frr/ # Clean up RUN apt-get clean -y && \ apt-get autoclean -y && \ apt-get autoremove -y && \ - rm -rf /debs ~/.cache + rm -rf /debs ~/.cache /python-wheels COPY ["frr", "/usr/share/sonic/templates"] -COPY ["bgpcfgd", "docker_init.sh", "/usr/bin/"] +COPY ["docker_init.sh", "/usr/bin/"] COPY ["snmp.conf", "/etc/snmp/frr.conf"] COPY ["TSA", "/usr/bin/TSA"] COPY ["TSB", "/usr/bin/TSB"] diff --git a/dockers/docker-fpm-frr/base_image_files/monit_bgp b/dockers/docker-fpm-frr/base_image_files/monit_bgp index 5b943ea7c0..5dbb794c34 100644 --- a/dockers/docker-fpm-frr/base_image_files/monit_bgp +++ b/dockers/docker-fpm-frr/base_image_files/monit_bgp @@ -19,5 +19,5 @@ check process bgpd matching "/usr/lib/frr/bgpd" check process staticd matching "/usr/lib/frr/staticd" if does not exist for 5 times within 5 cycles then alert -check process bgpcfgd matching "python /usr/bin/bgpcfgd" +check process bgpcfgd matching "python /usr/local/bin/bgpcfgd" if does not exist for 5 times within 5 cycles then alert diff --git a/dockers/docker-fpm-frr/frr/supervisord/supervisord.conf.j2 b/dockers/docker-fpm-frr/frr/supervisord/supervisord.conf.j2 index 31af4bad43..2a1930d839 100644 --- a/dockers/docker-fpm-frr/frr/supervisord/supervisord.conf.j2 +++ b/dockers/docker-fpm-frr/frr/supervisord/supervisord.conf.j2 @@ -73,7 +73,7 @@ dependent_startup=true dependent_startup_wait_for=bgpd:running [program:bgpcfgd] -command=/usr/bin/bgpcfgd +command=/usr/local/bin/bgpcfgd priority=6 autostart=false autorestart=false diff --git a/rules/docker-fpm-frr.mk b/rules/docker-fpm-frr.mk index 45a755a928..ad6613a685 100644 --- a/rules/docker-fpm-frr.mk +++ b/rules/docker-fpm-frr.mk @@ -5,6 +5,7 @@ DOCKER_FPM_FRR = $(DOCKER_FPM_FRR_STEM).gz DOCKER_FPM_FRR_DBG = $(DOCKER_FPM_FRR_STEM)-$(DBG_IMAGE_MARK).gz $(DOCKER_FPM_FRR)_PATH = $(DOCKERS_PATH)/$(DOCKER_FPM_FRR_STEM) +$(DOCKER_FPM_FRR)_PYTHON_WHEELS += $(SONIC_BGPCFGD) $(DOCKER_FPM_FRR)_DEPENDS += $(FRR) $(FRR_SNMP) $(SWSS) $(LIBYANG) $(DOCKER_FPM_FRR)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS) diff --git a/rules/sonic_bgpcfgd.dep b/rules/sonic_bgpcfgd.dep new file mode 100644 index 0000000000..abd51062b8 --- /dev/null +++ b/rules/sonic_bgpcfgd.dep @@ -0,0 +1,10 @@ + +SPATH := $($(SONIC_BGPCFGD)_SRC_PATH) +DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic_bgpcfgd.mk rules/sonic_bgpcfgd.dep +DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) +DEP_FILES += $(shell git ls-files $(SPATH)) + +$(SONIC_BGPCFGD)_CACHE_MODE := GIT_CONTENT_SHA +$(SONIC_BGPCFGD)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) +$(SONIC_BGPCFGD)_DEP_FILES := $(DEP_FILES) + diff --git a/rules/sonic_bgpcfgd.mk b/rules/sonic_bgpcfgd.mk new file mode 100644 index 0000000000..650874b619 --- /dev/null +++ b/rules/sonic_bgpcfgd.mk @@ -0,0 +1,7 @@ +# sonic-bgpcfgd package + +SONIC_BGPCFGD = sonic_bgpcfgd-1.0-py2-none-any.whl +$(SONIC_BGPCFGD)_SRC_PATH = $(SRC_PATH)/sonic-bgpcfgd +$(SONIC_BGPCFGD)_DEPENDS += $(SWSSSDK_PY2) +$(SONIC_BGPCFGD)_PYTHON_VERSION = 2 +SONIC_PYTHON_WHEELS += $(SONIC_BGPCFGD) diff --git a/src/sonic-bgpcfgd/.gitignore b/src/sonic-bgpcfgd/.gitignore new file mode 100644 index 0000000000..013f588165 --- /dev/null +++ b/src/sonic-bgpcfgd/.gitignore @@ -0,0 +1,6 @@ +.eggs/ +build/ +dist/ +*.egg-info/ +tests/*.pyc +tests/__pycache__/ diff --git a/dockers/docker-fpm-frr/bgpcfgd b/src/sonic-bgpcfgd/bgpcfgd similarity index 100% rename from dockers/docker-fpm-frr/bgpcfgd rename to src/sonic-bgpcfgd/bgpcfgd diff --git a/src/sonic-bgpcfgd/setup.cfg b/src/sonic-bgpcfgd/setup.cfg new file mode 100644 index 0000000000..00ed5efbcb --- /dev/null +++ b/src/sonic-bgpcfgd/setup.cfg @@ -0,0 +1,5 @@ +[aliases] +test=pytest +[tool:pytest] +addopts = --verbose +python_files = tests/*.py diff --git a/src/sonic-bgpcfgd/setup.py b/src/sonic-bgpcfgd/setup.py new file mode 100755 index 0000000000..2aea5cdb0c --- /dev/null +++ b/src/sonic-bgpcfgd/setup.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +from setuptools import setup + +setup(name='sonic-bgpcfgd', + version='1.0', + description='Utility to dynamically generate BGP configuration for FRR', + author='Pavel Shirshov', + author_email='pavelsh@microsoft.com', + url='https://github.com/Azure/sonic-buildimage', + scripts=['bgpcfgd'], + install_requires=['jinja2>=2.10', 'netaddr', 'pyyaml'], + setup_requires=['pytest-runner', 'pytest'], +) diff --git a/src/sonic-bgpcfgd/tests/__init__.py b/src/sonic-bgpcfgd/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/sonic-bgpcfgd/tests/test_sample.py b/src/sonic-bgpcfgd/tests/test_sample.py new file mode 100644 index 0000000000..3adfe439d2 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/test_sample.py @@ -0,0 +1,4 @@ +import pytest + +def test_sample(): + assert True