diff --git a/rules/sonic_bgpcfgd.mk b/rules/sonic_bgpcfgd.mk index 2710beecc2..3e1395842b 100644 --- a/rules/sonic_bgpcfgd.mk +++ b/rules/sonic_bgpcfgd.mk @@ -7,7 +7,7 @@ $(SONIC_BGPCFGD)_SRC_PATH = $(SRC_PATH)/sonic-bgpcfgd # as part of its unit tests. # TODO: Refactor unit tests so that these dependencies are not needed -$(SONIC_BGPCFGD)_DEPENDS += $(SONIC_PY_COMMON_PY2) +$(SONIC_BGPCFGD)_DEPENDS += $(SONIC_CONFIG_ENGINE_PY3) $(SONIC_BGPCFGD)_DEBS_DEPENDS += $(PYTHON3_SWSSCOMMON) $(SONIC_BGPCFGD)_PYTHON_VERSION = 3 SONIC_PYTHON_WHEELS += $(SONIC_BGPCFGD) diff --git a/src/sonic-bgpcfgd/setup.py b/src/sonic-bgpcfgd/setup.py index 69110bbe79..91fcdd0ac2 100755 --- a/src/sonic-bgpcfgd/setup.py +++ b/src/sonic-bgpcfgd/setup.py @@ -26,6 +26,7 @@ setuptools.setup( ], tests_require = [ 'pytest', - 'pytest-cov' + 'pytest-cov', + 'sonic-config-engine' ] ) diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.conf.j2/all.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.conf.j2/all.conf index 7671d026ef..f1a1cc5408 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.conf.j2/all.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.conf.j2/all.conf @@ -1,12 +1,10 @@ ! ! template: bgpd/bgpd.conf.j2 ! -! ! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! generated by templates/quagga/bgpd.conf.j2 with config DB data ! file: bgpd.conf ! -! ! template: common/daemons.common.conf.j2 ! hostname new_hostname @@ -19,8 +17,6 @@ log facility local4 ! end of template: common/daemons.common.conf.j2! agentx ! -! -! ! template: bgpd/bgpd.main.conf.j2 ! ! bgp multiple-instance @@ -33,15 +29,13 @@ ip prefix-list PL_LoopbackV4 permit 55.55.55.55/32 ! ipv6 prefix-list PL_LoopbackV6 permit fc00::/64 ! -ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 10.10.10.0/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 5 permit fc01::/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.0/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::/64 ! route-map HIDE_INTERNAL permit 10 set community local-AS ! -! router bgp 55555 ! bgp log-neighbor-changes @@ -61,11 +55,10 @@ router bgp 55555 network fc00::1/64 exit-address-family ! + network 10.10.10.1/24 address-family ipv6 network fc01::1/64 exit-address-family - network 10.10.10.1/24 -! ! address-family ipv4 redistribute connected route-map HIDE_INTERNAL diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.conf index 249e70c91d..4fc1b7261e 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/all.conf @@ -11,15 +11,13 @@ ip prefix-list PL_LoopbackV4 permit 55.55.55.55/32 ! ipv6 prefix-list PL_LoopbackV6 permit fc00::/64 ! -ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 10.10.10.0/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 15 permit fc01::/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.0/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::/64 ! route-map HIDE_INTERNAL permit 10 set community local-AS ! -! router bgp 55555 ! bgp log-neighbor-changes @@ -43,7 +41,6 @@ router bgp 55555 address-family ipv6 network fc01::1/64 exit-address-family -! ! address-family ipv4 redistribute connected route-map HIDE_INTERNAL diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.conf index d79234ffdb..a1a4bd5a6a 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.main.conf.j2/defaults.conf @@ -11,15 +11,13 @@ ip prefix-list PL_LoopbackV4 permit 55.55.55.55/32 ! ipv6 prefix-list PL_LoopbackV6 permit fc00::/64 ! -ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 10.10.10.0/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 15 permit fc01::/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.0/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::/64 ! route-map HIDE_INTERNAL permit 10 set community local-AS ! -! router bgp 55555 ! bgp log-neighbor-changes @@ -43,7 +41,6 @@ router bgp 55555 address-family ipv6 network fc01::1/64 exit-address-family -! ! address-family ipv4 redistribute connected route-map HIDE_INTERNAL diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.spine_chassis_frontend_router.conf.j2/base.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.spine_chassis_frontend_router.conf.j2/base.conf index 2f54371529..581eb107ec 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.spine_chassis_frontend_router.conf.j2/base.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/bgpd.spine_chassis_frontend_router.conf.j2/base.conf @@ -1,23 +1,5 @@ ! ! Vnet BGP instance -router bgp 555 vrf Second - no bgp default ipv4-unicast - bgp log-neighbor-changes - bgp bestpath as-path multipath-relax - no bgp default ipv4-unicast - bgp graceful-restart restart-time 240 - bgp graceful-restart - bgp router-id 10.20.30.40 - neighbor 20.20.20.1 remote-as 20 - neighbor 20.20.20.1 description session2 - address-family ipv4 unicast - neighbor 20.20.20.1 activate - neighbor 20.20.20.1 soft-reconfiguration inbound - maximum-paths 64 - exit-address-family - address-family l2vpn evpn - advertise ipv4 unicast - exit-address-family router bgp 555 vrf First no bgp default ipv4-unicast bgp log-neighbor-changes @@ -36,4 +18,22 @@ router bgp 555 vrf First address-family l2vpn evpn advertise ipv4 unicast exit-address-family +router bgp 555 vrf Second + no bgp default ipv4-unicast + bgp log-neighbor-changes + bgp bestpath as-path multipath-relax + no bgp default ipv4-unicast + bgp graceful-restart restart-time 240 + bgp graceful-restart + bgp router-id 10.20.30.40 + neighbor 20.20.20.1 remote-as 20 + neighbor 20.20.20.1 description session2 + address-family ipv4 unicast + neighbor 20.20.20.1 activate + neighbor 20.20.20.1 soft-reconfiguration inbound + maximum-paths 64 + exit-address-family + address-family l2vpn evpn + advertise ipv4 unicast + exit-address-family ! diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf index 4b88beb665..da63c01adc 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf @@ -3,7 +3,6 @@ ! generated by templates/frr.conf.j2 with config DB data ! file: frr.conf ! -! ! template: common/daemons.common.conf.j2 ! hostname test_hostname @@ -16,15 +15,13 @@ log facility local4 ! end of template: common/daemons.common.conf.j2! agentx ! -! -! ! Enable nht through default route ip nht resolve-via-default ! Enable link-detect (default disabled) -interface Ethernet4 +interface Ethernet0 link-detect ! -interface Ethernet0 +interface Ethernet4 link-detect ! interface PortChannel10 @@ -51,15 +48,13 @@ ip prefix-list PL_LoopbackV4 permit 55.55.55.55/32 ! ipv6 prefix-list PL_LoopbackV6 permit fc00::/64 ! -ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 10.10.10.0/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 5 permit fc01::/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.0/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::/64 ! route-map HIDE_INTERNAL permit 10 set community local-AS ! -! router bgp 55555 ! bgp log-neighbor-changes @@ -79,11 +74,10 @@ router bgp 55555 network fc00::1/64 exit-address-family ! + network 10.10.10.1/24 address-family ipv6 network fc01::1/64 exit-address-family - network 10.10.10.1/24 -! ! address-family ipv4 redistribute connected route-map HIDE_INTERNAL diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/interfaces.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/interfaces.conf index 1a49042fad..ddd129bcd1 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/interfaces.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/interfaces.conf @@ -1,12 +1,11 @@ ! -! ! Enable nht through default route ip nht resolve-via-default ! Enable link-detect (default disabled) -interface Ethernet4 +interface Ethernet0 link-detect ! -interface Ethernet0 +interface Ethernet4 link-detect ! interface PortChannel10 @@ -15,4 +14,3 @@ link-detect interface PortChannel20 link-detect ! -! diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/zebra.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/zebra.conf index 5bff88c711..ac2d8dac88 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/zebra.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/zebra/zebra.conf @@ -3,7 +3,6 @@ ! generated by templates/zebra/zebra.conf.j2 using config DB data ! file: zebra.conf ! -! ! template: common/daemons.common.conf.j2 ! hostname new_hostname @@ -15,20 +14,19 @@ log facility local4 ! ! end of template: common/daemons.common.conf.j2! ! -vrf Second -vni 20 -! vrf First vni 10 ! +vrf Second +vni 20 ! ! Enable nht through default route ip nht resolve-via-default ! Enable link-detect (default disabled) -interface Ethernet4 +interface Ethernet0 link-detect ! -interface Ethernet0 +interface Ethernet4 link-detect ! interface PortChannel10 diff --git a/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py b/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py index 92f6dec249..f49f0a0a42 100644 --- a/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py +++ b/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py @@ -12,9 +12,8 @@ CONSTANTS_PATH = os.path.abspath('../../files/image_config/constants/constants.y def run_test(name, template_path, json_path, match_path): template_path = os.path.join(TEMPLATE_PATH, template_path) json_path = os.path.join(DATA_PATH, json_path) - cfggen = os.path.abspath("../sonic-config-engine/sonic-cfggen") - command = ['/usr/bin/python2.7', cfggen, "-T", TEMPLATE_PATH, "-t", template_path, "-y", json_path] - p = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={"PYTHONPATH": "."}) + command = ['sonic-cfggen', "-T", TEMPLATE_PATH, "-t", template_path, "-y", json_path] + p = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() assert p.returncode == 0, "sonic-cfggen for %s test returned %d code. stderr='%s'" % (name, p.returncode, stderr) raw_generated_result = stdout.decode("ascii")