def test__get_available_peer_groups(): cfg_mgr = MagicMock() common_objs = { 'directory': Directory(), 'cfg_mgr': cfg_mgr, 'tf': TemplateFabric(), 'constants': global_constants, } m = BBRMgr(common_objs, "CONFIG_DB", "BGP_BBR") m.cfg_mgr.get_text = MagicMock(return_value=[ ' neighbor PEER_V4 peer-group', ' neighbor PEER_V6 peer-group', ' address-family ipv4', ' neighbor PEER_V4 allowas-in 1', ' neighbor PEER_V4 soft-reconfiguration inbound', ' neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in', ' neighbor PEER_V4 route-map TO_BGP_PEER_V4 out', ' exit-address-family', ' address-family ipv6', ' neighbor PEER_V6 allowas-in 1', ' neighbor PEER_V6 soft-reconfiguration inbound', ' neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in', ' neighbor PEER_V6 route-map TO_BGP_PEER_V6 out', ' exit-address-family', ' ', ]) res = m._BBRMgr__get_available_peer_groups() assert res == {"PEER_V4", "PEER_V6"}
def __set_prepare_config_common(status, bbr_enabled_pgs, available_pgs, mapping_pgs, expected_cmds, bbr_applied_pgs=None): cfg_mgr = MagicMock() common_objs = { 'directory': Directory(), 'cfg_mgr': cfg_mgr, 'tf': TemplateFabric(), 'constants': global_constants, } m = BBRMgr(common_objs, "CONFIG_DB", "BGP_BBR") m.directory.data = { "CONFIG_DB__DEVICE_METADATA": { "localhost": { "bgp_asn": "65500" } } } m.bbr_enabled_pgs = bbr_enabled_pgs m._BBRMgr__get_available_peer_groups = MagicMock( return_value=available_pgs) m._BBRMgr__get_available_peers_per_peer_group = MagicMock( return_value=mapping_pgs) cmds, peer_groups = m._BBRMgr__set_prepare_config(status) assert cmds == expected_cmds assert set(peer_groups) == (available_pgs if not bbr_applied_pgs else bbr_applied_pgs)