diff --git a/rules/sonic_bgpcfgd.mk b/rules/sonic_bgpcfgd.mk index 2710beecc26..3e1395842b5 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 5b18bb2ba25..40c24d2222b 100755 --- a/src/sonic-bgpcfgd/setup.py +++ b/src/sonic-bgpcfgd/setup.py @@ -28,6 +28,7 @@ ], 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 6d79e4c2264..53efd1ea723 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.1/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 5 permit fc01::1/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.1/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::1/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 d771ff49c92..a7c8a69d924 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.1/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 15 permit fc01::1/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.1/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::1/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 e9296f8627d..e4080af9e42 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.1/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 15 permit fc01::1/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.1/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::1/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 2f543715299..581eb107ec2 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,6 +1,6 @@ ! ! Vnet BGP instance -router bgp 555 vrf Second +router bgp 555 vrf First no bgp default ipv4-unicast bgp log-neighbor-changes bgp bestpath as-path multipath-relax @@ -8,17 +8,17 @@ router bgp 555 vrf Second 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 + neighbor 10.10.10.1 remote-as 10 + neighbor 10.10.10.1 description session1 address-family ipv4 unicast - neighbor 20.20.20.1 activate - neighbor 20.20.20.1 soft-reconfiguration inbound + neighbor 10.10.10.1 activate + neighbor 10.10.10.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 +router bgp 555 vrf Second no bgp default ipv4-unicast bgp log-neighbor-changes bgp bestpath as-path multipath-relax @@ -26,11 +26,11 @@ router bgp 555 vrf First bgp graceful-restart restart-time 240 bgp graceful-restart bgp router-id 10.20.30.40 - neighbor 10.10.10.1 remote-as 10 - neighbor 10.10.10.1 description session1 + neighbor 20.20.20.1 remote-as 20 + neighbor 20.20.20.1 description session2 address-family ipv4 unicast - neighbor 10.10.10.1 activate - neighbor 10.10.10.1 soft-reconfiguration inbound + neighbor 20.20.20.1 activate + neighbor 20.20.20.1 soft-reconfiguration inbound maximum-paths 64 exit-address-family address-family l2vpn evpn 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 775861ef47c..6728343124f 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.1/24 -! -ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 5 permit fc01::1/64 +ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 10.10.10.1/24 ! +ipv6 prefix-list LOCAL_VLAN_IPV6_PREFIX seq 10 permit fc01::1/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 1a49042fad3..ddd129bcd18 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 5bff88c711e..ac2d8dac88f 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 92f6dec249b..f49f0a0a42d 100644 --- a/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py +++ b/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py @@ -12,9 +12,8 @@ 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")